From patchwork Fri Dec 16 13:46:01 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 88305 Delivered-To: patch@linaro.org Received: by 10.182.112.6 with SMTP id im6csp267960obb; Fri, 16 Dec 2016 05:46:33 -0800 (PST) X-Received: by 10.84.174.67 with SMTP id q61mr6938268plb.93.1481895993748; Fri, 16 Dec 2016 05:46:33 -0800 (PST) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id b1si362530pgn.86.2016.12.16.05.46.33 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 16 Dec 2016 05:46:33 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-return-444609-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org; spf=pass (google.com: domain of gcc-patches-return-444609-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-444609-patch=linaro.org@gcc.gnu.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; q=dns; s=default; b=fe9Q4nSZkI7/bHkNv VNX6cS6A6/8hlQe7/dilv1H9gQu0Ylio5bcIM8xDdf26TpfC8S8Ju0VN6cnWkPgp 9X3DJYX5JHfG2TM9Qjbwwvim38DW6VTNoNWYSuOeGkb4X+tKodX7VbrLomMufe2h rfbDFDl8DvviMXiRhi+Zbk82PA= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=default; bh=iFAZYR5UBUWAH1WCDtGqti1 CXXw=; b=F8DEsiM2o/Oz3E7zT9nz1nEU0flO92T30p8qlZSvRhZmg0MpQ8I5Sk8 HuXsHCF8BBk40SszwKOtFZMVH8Z1L8uC8ToEqKMJg2QntRYYcxAvWchJzLrydfkT Q7qQaAIp02X7dJdEY1yHcsyZX8HuJYrzh4k2hGVAXYPxHl6GSwag= Received: (qmail 101223 invoked by alias); 16 Dec 2016 13:46:14 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 101196 invoked by uid 89); 16 Dec 2016 13:46:13 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-5.0 required=5.0 tests=BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=throws X-Spam-User: qpsmtpd, 2 recipients X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 16 Dec 2016 13:46:03 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 686974D69E; Fri, 16 Dec 2016 13:46:02 +0000 (UTC) Received: from localhost (ovpn-116-120.ams2.redhat.com [10.36.116.120]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id uBGDk1ma030770; Fri, 16 Dec 2016 08:46:01 -0500 Date: Fri, 16 Dec 2016 13:46:01 +0000 From: Jonathan Wakely To: David Malcolm Cc: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: Re: RFC: Make iterator printers fail more gracefully Message-ID: <20161216134601.GF895@redhat.com> References: <20161215173917.GA12231@redhat.com> <1481825493.12007.27.camel@redhat.com> <20161215182923.GE22266@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20161215182923.GE22266@redhat.com> X-Clacks-Overhead: GNU Terry Pratchett User-Agent: Mutt/1.7.1 (2016-10-04) On 15/12/16 18:29 +0000, Jonathan Wakely wrote: >On 15/12/16 13:11 -0500, David Malcolm wrote: >>BTW, is it always a ValueError exception? >> >>(I'm a little wary of naked "except:" in Python, as it can catch >>*anything*, including syntax errors in the try/except-guarded code). > >Good point. As far as I know, the gdb.lookup_type method will throw a >ValueError in the case I'm trying to fix. If it can throw other things >we can deal with them later by adding other handlers. One case gets a ValueError from the find_type helper, and one case gets a gdb.error (which is derived from RuntimeError) because it uses gdb.lookup_type directly. Here's a new patch without naked "except:" commit 0f63cb5027505c26b2f90aeeb1275f459c3d2fbd Author: Jonathan Wakely Date: Fri Dec 16 13:42:48 2016 +0000 Make iterator printers fail more gracefully * python/libstdcxx/v6/printers.py (StdListIteratorPrinter.to_string): Handle exception from failed type lookup and return user-friendly string. (StdRbtreeIteratorPrinter.__init__): Handle exception from failed type lookup. (StdRbtreeIteratorPrinter.to_string): Return user-friendly string. diff --git a/libstdc++-v3/python/libstdcxx/v6/printers.py b/libstdc++-v3/python/libstdcxx/v6/printers.py index 86de1ca..1897154 100644 --- a/libstdc++-v3/python/libstdcxx/v6/printers.py +++ b/libstdc++-v3/python/libstdcxx/v6/printers.py @@ -202,10 +202,13 @@ class StdListIteratorPrinter: def to_string(self): if not self.val['_M_node']: return 'non-dereferenceable iterator for std::list' - nodetype = find_type(self.val.type, '_Node') - nodetype = nodetype.strip_typedefs().pointer() - node = self.val['_M_node'].cast(nodetype).dereference() - return str(get_value_from_list_node(node)) + try: + nodetype = find_type(self.val.type, '_Node') + nodetype = nodetype.strip_typedefs().pointer() + node = self.val['_M_node'].cast(nodetype).dereference() + return str(get_value_from_list_node(node)) + except ValueError: + return '' class StdSlistPrinter: "Print a __gnu_cxx::slist" @@ -496,12 +499,18 @@ class StdRbtreeIteratorPrinter: def __init__ (self, typename, val): self.val = val valtype = self.val.type.template_argument(0).strip_typedefs() - nodetype = gdb.lookup_type('std::_Rb_tree_node<' + str(valtype) + '>') - self.link_type = nodetype.strip_typedefs().pointer() + try: + # Throws gdb.error if debuginfo for _Rb_tree_node is missing: + nodetype = gdb.lookup_type('std::_Rb_tree_node<%s>' % str(valtype)) + self.link_type = nodetype.strip_typedefs().pointer() + except RuntimeError: + self.link_type = None def to_string (self): if not self.val['_M_node']: return 'non-dereferenceable iterator for associative container' + if self.link_type is None: + return "" node = self.val['_M_node'].cast(self.link_type).dereference() return str(get_value_from_Rb_tree_node(node))