[binutils-gdb] Fix handling of DW_TAG_unspecified_type for Ada
Tom Tromey
tromey@sourceware.org
Wed Jun 28 16:01:31 GMT 2023
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=6e27b5eb0072902173305d0ce41c33b82f5b2bb3
commit 6e27b5eb0072902173305d0ce41c33b82f5b2bb3
Author: Tom Tromey <tromey@adacore.com>
Date: Tue Jun 13 09:36:35 2023 -0600
Fix handling of DW_TAG_unspecified_type for Ada
Commit 80eaec735e ("[gdb/symtab] Handle named DW_TAG_unspecified_type
DIE") changed the handling of DW_TAG_unspecified_type. Before this
change, such types were not entered into the symbol table.
It turns out that, when such a type is in the symtab, it can cause
failures in Ada. In particular, a private type in another package may
be seen locally as "void".
Now, it would probably be better to fix this via check_typedef.
However, that is somewhat difficult given the state of the DWARF
reader -- in particular with gdb_index, this would require expanding
potentially many CUs to find the correct type.
Instead, this patch changes gdb to not enter a symbol for an
unspecified type -- but only for Ada.
Diff:
---
gdb/dwarf2/read.c | 5 ++++-
gdb/testsuite/gdb.ada/py_taft.exp | 5 +++++
2 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index a9c2a7d59d5..3508f2c29ee 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -19316,11 +19316,14 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
sym->set_domain (VAR_DOMAIN);
list_to_add = cu->list_in_scope;
break;
+ case DW_TAG_unspecified_type:
+ if (cu->lang () == language_ada)
+ break;
+ /* FALLTHROUGH */
case DW_TAG_array_type:
case DW_TAG_base_type:
case DW_TAG_subrange_type:
case DW_TAG_generic_subrange:
- case DW_TAG_unspecified_type:
sym->set_aclass_index (LOC_TYPEDEF);
sym->set_domain (VAR_DOMAIN);
list_to_add = cu->list_in_scope;
diff --git a/gdb/testsuite/gdb.ada/py_taft.exp b/gdb/testsuite/gdb.ada/py_taft.exp
index 0ce9df72005..1990e7e89ce 100644
--- a/gdb/testsuite/gdb.ada/py_taft.exp
+++ b/gdb/testsuite/gdb.ada/py_taft.exp
@@ -35,3 +35,8 @@ gdb_test "python print(v.dereference().type.code is gdb.TYPE_CODE_VOID)" \
"False"
gdb_test "python print(v.type.strip_typedefs().target().code is gdb.TYPE_CODE_VOID)" \
"False"
+
+# This was a convenient spot to put a regression test. GNAT will
+# create a DW_TAG_unspecified_type in the main.adb CU, and if gdb
+# isn't careful, this will result in this 'whatis' yielding 'void'.
+gdb_test "whatis pkg.value_record" "type = pkg.value_record"
More information about the Gdb-cvs
mailing list