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.
This commit is contained in:
Tom Tromey 2023-06-13 09:36:35 -06:00
parent 1d2ee87e60
commit 6e27b5eb00
2 changed files with 9 additions and 1 deletions

View File

@ -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;

View File

@ -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"