[RFA/commit] gdb-gdb.py.in: Fix error when printing range type

Message ID 20190302134939.24157-1-brobecker@adacore.com
State New
Headers show
Series
  • [RFA/commit] gdb-gdb.py.in: Fix error when printing range type
Related show

Commit Message

Joel Brobecker March 2, 2019, 1:49 p.m.
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 <class 'gdb.error'> 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(-)

-- 
2.17.1

Comments

Joel Brobecker March 26, 2019, 10:37 p.m. | #1
> 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).


FTR, I pushed this patch to master today.

-- 
Joel

Patch

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.