aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Tromey <tromey@adacore.com>2021-04-15 08:54:06 -0600
committerTom Tromey <tromey@adacore.com>2021-04-30 07:33:01 -0600
commit2869ac4b59d58caf736f216f7bc65377116bd5f7 (patch)
tree41800bc393f05104e2e55de0cbaf48a3d0394b4f
parentd1fbc3ba09fb2e79acf633df29ccbe9285624419 (diff)
downloadgdb-2869ac4b59d58caf736f216f7bc65377116bd5f7.zip
gdb-2869ac4b59d58caf736f216f7bc65377116bd5f7.tar.gz
gdb-2869ac4b59d58caf736f216f7bc65377116bd5f7.tar.bz2
Fix crash with GNAT minimal encodings
Running the AdaCore internal test suite with -fgnat-encodings=minimal found a gdb crash. The bug is that GDB ends up with a typedef in ada_index_type, resulting in a NULL dereference. This crash can be reproduced using GCC 11 with the included test case. Tested on x86-64 Fedora 32. Because this is Ada-specific, and was already reviewed by Joel, I am going to check it in. 2021-04-30 Tom Tromey <tromey@adacore.com> * ada-lang.c (ada_index_type): Use ada_check_typedef. gdb/testsuite/ChangeLog 2021-04-30 Tom Tromey <tromey@adacore.com> * gdb.ada/enum_idx_packed/pck.ads (My_Enum, My_Array_Type) (Confused_Array): New types. * gdb.ada/enum_idx_packed/foo.adb (Confused_Array): New variable. * gdb.ada/enum_idx_packed.exp: Add new tests.
-rw-r--r--gdb/ChangeLog4
-rw-r--r--gdb/ada-lang.c7
-rw-r--r--gdb/testsuite/ChangeLog7
-rw-r--r--gdb/testsuite/gdb.ada/enum_idx_packed.exp3
-rw-r--r--gdb/testsuite/gdb.ada/enum_idx_packed/foo.adb4
-rw-r--r--gdb/testsuite/gdb.ada/enum_idx_packed/pck.ads5
6 files changed, 28 insertions, 2 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 8e77fa6..f89346d 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,7 @@
+2021-04-30 Tom Tromey <tromey@adacore.com>
+
+ * ada-lang.c (ada_index_type): Use ada_check_typedef.
+
2021-04-29 Simon Marchi <simon.marchi@efficios.com>
* auto-load.h: Split namespace declaration.
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 0b50a78..e15e583 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -2877,8 +2877,11 @@ ada_index_type (struct type *type, int n, const char *name)
int i;
for (i = 1; i < n; i += 1)
- type = TYPE_TARGET_TYPE (type);
- result_type = TYPE_TARGET_TYPE (type->index_type ());
+ {
+ type = ada_check_typedef (type);
+ type = TYPE_TARGET_TYPE (type);
+ }
+ result_type = TYPE_TARGET_TYPE (ada_check_typedef (type)->index_type ());
/* FIXME: The stabs type r(0,0);bound;bound in an array type
has a target type of TYPE_CODE_UNDEF. We compensate here, but
perhaps stabsread.c would make more sense. */
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 8e021d2..be39527 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,10 @@
+2021-04-30 Tom Tromey <tromey@adacore.com>
+
+ * gdb.ada/enum_idx_packed/pck.ads (My_Enum, My_Array_Type)
+ (Confused_Array): New types.
+ * gdb.ada/enum_idx_packed/foo.adb (Confused_Array): New variable.
+ * gdb.ada/enum_idx_packed.exp: Add new tests.
+
2021-04-30 Tom de Vries <tdevries@suse.de>
* gdb.mi/mi-sym-info.exp: Add with_timeout_factor, and increase
diff --git a/gdb/testsuite/gdb.ada/enum_idx_packed.exp b/gdb/testsuite/gdb.ada/enum_idx_packed.exp
index 1497f53..f7d57a7 100644
--- a/gdb/testsuite/gdb.ada/enum_idx_packed.exp
+++ b/gdb/testsuite/gdb.ada/enum_idx_packed.exp
@@ -122,4 +122,7 @@ foreach_with_prefix scenario {all minimal} {
gdb_test "print multi_access.all" \
" = \\(\\(8, 13, 21, 34, 55\\), \\(1, 1, 2, 3, 5\\)\\)"
+
+ gdb_test "print confused_array(red, green)" " = 2"
+ gdb_test "print confused_array(green, red)" " = 6"
}
diff --git a/gdb/testsuite/gdb.ada/enum_idx_packed/foo.adb b/gdb/testsuite/gdb.ada/enum_idx_packed/foo.adb
index 5d32949..2887ed4 100644
--- a/gdb/testsuite/gdb.ada/enum_idx_packed/foo.adb
+++ b/gdb/testsuite/gdb.ada/enum_idx_packed/foo.adb
@@ -26,6 +26,10 @@ procedure Foo is
:= new Multi_Dimension'(True => (1, 1, 2, 3, 5),
False => (8, 13, 21, 34, 55));
+ Confused_Array : Confused_Array_Type := (Red => (0, 1, 2),
+ Green => (5, 6, 7),
+ others => (others => 72));
+
begin
Do_Nothing (Full'Address); -- STOP
Do_Nothing (Primary'Address);
diff --git a/gdb/testsuite/gdb.ada/enum_idx_packed/pck.ads b/gdb/testsuite/gdb.ada/enum_idx_packed/pck.ads
index 7a0a7de..ff0b91a 100644
--- a/gdb/testsuite/gdb.ada/enum_idx_packed/pck.ads
+++ b/gdb/testsuite/gdb.ada/enum_idx_packed/pck.ads
@@ -48,5 +48,10 @@ package Pck is
pragma Pack (Multi_Dimension);
type Multi_Dimension_Access is access all Multi_Dimension;
+ type My_Enum is (Blue, Red, Green);
+
+ type My_Array_Type is array (My_Enum) of Integer;
+ type Confused_Array_Type is array (Color) of My_Array_Type;
+
procedure Do_Nothing (A : System.Address);
end Pck;