From patchwork Sat Mar 2 13:49:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Brobecker X-Patchwork-Id: 31700 Received: (qmail 13162 invoked by alias); 2 Mar 2019 13:49:49 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 13123 invoked by uid 89); 2 Mar 2019 13:49:48 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=Exception, Hx-languages-length:2397, img X-HELO: rock.gnat.com Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 02 Mar 2019 13:49:47 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id B3A625602B for ; Sat, 2 Mar 2019 08:49:45 -0500 (EST) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 2JBRRcbNNIVd for ; Sat, 2 Mar 2019 08:49:45 -0500 (EST) Received: from joel.gnat.com (localhost.localdomain [127.0.0.1]) by rock.gnat.com (Postfix) with ESMTP id 4EFD35602A for ; Sat, 2 Mar 2019 08:49:45 -0500 (EST) Received: by joel.gnat.com (Postfix, from userid 1000) id B852C838C2; Sat, 2 Mar 2019 17:49:40 +0400 (+04) From: Joel Brobecker To: gdb-patches@sourceware.org Subject: [RFA/commit] gdb-gdb.py.in: Fix error when printing range type Date: Sat, 2 Mar 2019 17:49:39 +0400 Message-Id: <20190302134939.24157-1-brobecker@adacore.com> Hello, I noticed that trying to print the contents of a struct main_type would fail when the type was a TYPE_CODE_RANGE: (gdb) p *type.main_type $1 = Python Exception There is no member named low_undefined.: And indeed, Python is right, fields "low_undefined" has been removed from struct range_bounds back in ... 2014! It was done when we introduced dynamic bounds handling. This patch fixes gdb-gdb.py.in according to the new structure. gdb/ChangeLog: * gdb-gdb.py.in (StructMainTypePrettyPrinter.bound_img): New method. (StructMainTypePrettyPrinter.bounds_img): Use new "bound_img" method to compute the bounds of range types. Also print "[evaluated]" if the bounds' values come from a dynamic evaluation. Tested on x86_64-linux (likely worth nothing, but done anyway). --- gdb/gdb-gdb.py.in | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/gdb/gdb-gdb.py.in b/gdb/gdb-gdb.py.in index 4b8296420e9..8700689f3dd 100644 --- a/gdb/gdb-gdb.py.in +++ b/gdb/gdb-gdb.py.in @@ -181,17 +181,31 @@ class StructMainTypePrettyPrinter: fields.append(self.struct_field_location_img(f)) return label + "\n" + " {" + ",\n ".join(fields) + "}" + def bound_img(self, bound_name): + """Return an image of the given main_type's bound.""" + b = self.val['flds_bnds']['bounds'].dereference()[bound_name] + bnd_kind = str(b['kind']) + if bnd_kind == 'PROP_CONST': + return str(b['data']['const_val']) + elif bnd_kind == 'PROP_UNDEFINED': + return '(undefined)' + else: + info = [bnd_kind] + if bound_name == 'high' and b['flag_upper_bound_is_count']: + info.append('upper_bound_is_count') + return '{} ({})'.format(str(b['data']['baton']), ','.join(info)) + def bounds_img(self): """Return an image of the main_type bounds. """ b = self.val['flds_bnds']['bounds'].dereference() - low = str(b['low']) - if b['low_undefined'] != 0: - low += " (undefined)" - high = str(b['high']) - if b['high_undefined'] != 0: - high += " (undefined)" - return "flds_bnds.bounds = {%s, %s}" % (low, high) + low = self.bound_img('low') + high = self.bound_img('high') + + img = "flds_bnds.bounds = {%s, %s}" % (low, high) + if b['flag_bound_evaluated']: + img += ' [evaluated]' + return img def type_specific_img(self): """Return a string image of the main_type type_specific union.