diff options
author | Tom Tromey <tromey@adacore.com> | 2021-04-15 10:14:11 -0600 |
---|---|---|
committer | Tom Tromey <tromey@adacore.com> | 2021-04-15 10:14:11 -0600 |
commit | a15a276b46bf07323a1d270d7abece83ef1ea78f (patch) | |
tree | 742b28318ab95c69c7cdbf446a4439d6e288ea5f /gdb/ada-valprint.c | |
parent | 644a2e75ace6b5e76f91d38c28c3b97fcfdeeaa5 (diff) | |
download | gdb-a15a276b46bf07323a1d270d7abece83ef1ea78f.zip gdb-a15a276b46bf07323a1d270d7abece83ef1ea78f.tar.gz gdb-a15a276b46bf07323a1d270d7abece83ef1ea78f.tar.bz2 |
Avoid crash in Ada value printing with optimized-out array
The Ada value-printing code could crash when printing an array which
had been optimized out.
The crash is difficult to reproduce, but I did manage to write a test
that at least shows that the previous behavior was incorrect -- before
the patch, the array is printed as if it is valid and every value is 0.
gdb/ChangeLog
2021-04-15 Tom Tromey <tromey@adacore.com>
* ada-valprint.c (ada_value_print_array): Handle optimized-out
arrays.
gdb/testsuite/ChangeLog
2021-04-15 Tom Tromey <tromey@adacore.com>
* gdb.dwarf2/arr-stride.exp: Add test.
Diffstat (limited to 'gdb/ada-valprint.c')
-rw-r--r-- | gdb/ada-valprint.c | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/gdb/ada-valprint.c b/gdb/ada-valprint.c index 0d5b6d7..61c903b 100644 --- a/gdb/ada-valprint.c +++ b/gdb/ada-valprint.c @@ -897,7 +897,10 @@ ada_value_print_array (struct value *val, struct ui_file *stream, int recurse, fprintf_filtered (stream, "("); print_optional_low_bound (stream, type, options); - if (TYPE_FIELD_BITSIZE (type, 0) > 0) + + if (value_entirely_optimized_out (val)) + val_print_optimized_out (val, stream); + else if (TYPE_FIELD_BITSIZE (type, 0) > 0) { const gdb_byte *valaddr = value_contents_for_printing (val); int offset_aligned = ada_aligned_value_addr (type, valaddr) - valaddr; |