aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@polymtl.ca>2020-07-30 14:56:08 -0400
committerSimon Marchi <simon.marchi@polymtl.ca>2020-07-30 14:56:08 -0400
commit5e500d33230ce2683001038177ad335365764793 (patch)
tree66e9dd74aba605f5213392bd8866452d7f20fac1
parent78319c1568ce20c41f5002e61bd9427a1cf59aac (diff)
downloadgdb-5e500d33230ce2683001038177ad335365764793.zip
gdb-5e500d33230ce2683001038177ad335365764793.tar.gz
gdb-5e500d33230ce2683001038177ad335365764793.tar.bz2
gdb: handle non-const property types in ada_modulus (PR ada/26318)
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
-rw-r--r--gdb/ChangeLog6
-rw-r--r--gdb/ada-lang.c9
2 files changed, 14 insertions, 1 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 5d55356..9e71836 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -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.
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 2be3fe4..2995152 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -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;
}