[PATCH 1/9] Avoid crash in ada-lang.c:to_fixed_array_type

Tom Tromey
2020-09-30T20:06:39Z

When debugging Ada programs compiled by certain versions of GNAT with
-fgnat-encodings=minimal, gdb can crash. These crashes occur when
running the gdb test suite, once some of the later patches in this
series have been applied.

This patch works around the bug by throwing an exception in the
failing case. I did not implement a full fix because GNAT has been
changed to emit better DWARF, and so in the near future this will stop
being a problem. (Currently, users don't generally use
-fgnat-encodings=minimal, and the GNAT default will only be changed in
a fully-patched compiler.)

gdb/ChangeLog
2020-09-30 Tom Tromey <tromey@adacore.com>

* ada-lang.c (to_fixed_array_type): Error if
decode_constrained_packed_array_type returns NULL.
---
gdb/ChangeLog | 5 +++++
gdb/ada-lang.c | 6 +++++-
2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 0df406bff48..b4b7e838114 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -8368,7 +8368,11 @@ to_fixed_array_type (struct type *type0, struct value *dval,

constrained_packed_array_p = ada_is_constrained_packed_array_type (type0);
if (constrained_packed_array_p)
- type0 = decode_constrained_packed_array_type (type0);
+ {
+ type0 = decode_constrained_packed_array_type (type0);
+ if (type0 == nullptr)
+ error (_("could not decode constrained packed array type"));
+ }

index_type_desc = ada_find_parallel_type (type0, xa_suffix);

--
2.26.2