aboutsummaryrefslogtreecommitdiff
path: root/gdb/gdbtypes.c
diff options
context:
space:
mode:
authorTom Tromey <tromey@adacore.com>2023-12-21 08:24:18 -0700
committerTom Tromey <tromey@adacore.com>2024-02-05 07:13:37 -0700
commita8b1650962b074fb8025399199f50abc65090670 (patch)
tree8044b7d9173494fd688d50e0c2a78f62848dcab1 /gdb/gdbtypes.c
parentbae2a57f4c07f46093e7bf00fec2554868e77189 (diff)
downloadgdb-a8b1650962b074fb8025399199f50abc65090670.zip
gdb-a8b1650962b074fb8025399199f50abc65090670.tar.gz
gdb-a8b1650962b074fb8025399199f50abc65090670.tar.bz2
Handling of arrays with optimized-out bounds
In Ada, sometimes the compiler must emit array bounds by referencing an artificial variable that's created for this purpose. However, with optimization enabled, these variables can be optimized away. Currently this can result in displays like: (gdb) print mumble $1 = (warning: unable to get bounds of array, assuming null array ) This patch changes this to report that the array is optimized-out, instead, which is closer to the truth, and more generally useful. For example, Python pretty-printers can now recognize this situation. In order to accomplish this, I introduced a new PROP_OPTIMIZED_OUT enumerator and changed one place to use it. Reusing the "unknown" state wouldn't work properly, because in C it is normal for array bounds to be unknown.
Diffstat (limited to 'gdb/gdbtypes.c')
-rw-r--r--gdb/gdbtypes.c32
1 files changed, 23 insertions, 9 deletions
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index ece161d..dcd7321 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -2179,21 +2179,35 @@ resolve_dynamic_range (struct type *dyn_range_type,
gdb_assert (rank >= 0);
const struct dynamic_prop *prop = &dyn_range_type->bounds ()->low;
- if (resolve_p && dwarf2_evaluate_property (prop, frame, addr_stack, &value,
- { (CORE_ADDR) rank }))
- low_bound.set_const_val (value);
+ if (resolve_p)
+ {
+ if (dwarf2_evaluate_property (prop, frame, addr_stack, &value,
+ { (CORE_ADDR) rank }))
+ low_bound.set_const_val (value);
+ else if (prop->kind () == PROP_UNDEFINED)
+ low_bound.set_undefined ();
+ else
+ low_bound.set_optimized_out ();
+ }
else
low_bound.set_undefined ();
prop = &dyn_range_type->bounds ()->high;
- if (resolve_p && dwarf2_evaluate_property (prop, frame, addr_stack, &value,
- { (CORE_ADDR) rank }))
+ if (resolve_p)
{
- high_bound.set_const_val (value);
+ if (dwarf2_evaluate_property (prop, frame, addr_stack, &value,
+ { (CORE_ADDR) rank }))
+ {
+ high_bound.set_const_val (value);
- if (dyn_range_type->bounds ()->flag_upper_bound_is_count)
- high_bound.set_const_val
- (low_bound.const_val () + high_bound.const_val () - 1);
+ if (dyn_range_type->bounds ()->flag_upper_bound_is_count)
+ high_bound.set_const_val
+ (low_bound.const_val () + high_bound.const_val () - 1);
+ }
+ else if (prop->kind () == PROP_UNDEFINED)
+ high_bound.set_undefined ();
+ else
+ high_bound.set_optimized_out ();
}
else
high_bound.set_undefined ();