]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb: handle non-const property types in ada_modulus (PR ada/26318)
authorSimon Marchi <simon.marchi@polymtl.ca>
Thu, 30 Jul 2020 18:56:08 +0000 (14:56 -0400)
committerSimon Marchi <simon.marchi@polymtl.ca>
Thu, 30 Jul 2020 18:56:08 +0000 (14:56 -0400)
PR 26318 shows that running `maint print symbols` on an Ada binary,
compiled with an Ada distribution that includes debug info for the
standard library, triggers this assertion:

    /home/simark/src/binutils-gdb/gdb/gdbtypes.h:526: internal-error: LONGEST dynamic_prop::const_val() const: Assertion `m_kind == PROP_CONST' failed.

The problem is in particular when printing type
`system__object_reader__decoded_ada_name__TTdecodedSP1___XDL_0`, which
has a dynamic high bound (PROP_LOCLIST kind).  When printing a concrete
value of this type, this type gets resolved to a type with a constant
high bound, so ada_modulus can return this constant value.

However, when printing the dynamic range type on its own, such as with
`maint print symbols`, the high bound is still of kind PROP_LOCLIST.
When ada_modulus tries to access the property as a const value, the
assert triggers.

There's no sensible numerical value to return in this case.  Ideally,
ada_modulus would return something to the caller indicating that the
value is dynamic and therefore can't be returned as an integer.  The
callers would handle it, for example `maint print symbols` would say
that the high bound of the type is dynamic.

However, this patch implements the simpler fix of returning 0 in that
case.  It kind of restores the previous behavior of before we validated
the dynamic property kind in the getters, where we would just return
whatever random integer value was in `const_val`.  Except now it's
consistently 0.

This is what we had before we added dynamic property getters:

$ ./gdb -q ~/foo -ex "maint expand-symtabs" -ex "maint print symbols" -batch | grep 'typedef <system__object_reader__decoded_ada_name__TTdecodedSP1'
     typedef <system__object_reader__decoded_ada_name__TTdecodedSP1: mod 107820865988257;

and this is what we have now:

$ ./gdb -q ~/foo -ex "maint expand-symtabs" -ex "maint print symbols" -batch | grep 'typedef <system__object_reader__decoded_ada_name__TTdecodedSP1'
     typedef <system__object_reader__decoded_ada_name__TTdecodedSP1: mod 0;

The value 107820865988257 is the `baton` field of the property's union
interpreted as an integer, so a bogus value.

gdb/ChangeLog:

PR ada/26318
* ada-lang.c (ada_modulus): Return 0 if property is not of const
kind.

Change-Id: I3f6d343a9c3cd7cd62a4fc591943a43541223d50

gdb/ChangeLog
gdb/ada-lang.c

index 5d5535692c8848d5cdcebe96caf5321b24461fd1..9e718361a6140a13b48acf48afc1cb8cd7b4533b 100644 (file)
@@ -1,3 +1,9 @@
+2020-07-30  Simon Marchi  <simon.marchi@polymtl.ca>
+
+       PR ada/26318
+       * ada-lang.c (ada_modulus): Return 0 if property is not of const
+       kind.
+
 2020-07-30  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>
 
        * breakpoint.c (set_breakpoint_condition): Do minor refactoring.
index 2be3fe45b35d6159d3bace8e0a83618b3ec3ed11..29951528e5e506b5174f8dbcffab3d4bc0c32bba 100644 (file)
@@ -11452,7 +11452,14 @@ ada_is_modular_type (struct type *type)
 ULONGEST
 ada_modulus (struct type *type)
 {
-  return (ULONGEST) type->bounds ()->high.const_val () + 1;
+  const dynamic_prop &high = type->bounds ()->high;
+
+  if (high.kind () == PROP_CONST)
+    return (ULONGEST) high.const_val () + 1;
+
+  /* If TYPE is unresolved, the high bound might be a location list.  Return
+     0, for lack of a better value to return.  */
+  return 0;
 }
 \f