public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Fix handling of DW_TAG_unspecified_type for Ada
@ 2023-06-15 13:03 Tom Tromey
  2023-06-28 15:49 ` Tom Tromey
  0 siblings, 1 reply; 2+ messages in thread
From: Tom Tromey @ 2023-06-15 13:03 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

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.
---
 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"
-- 
2.40.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] Fix handling of DW_TAG_unspecified_type for Ada
  2023-06-15 13:03 [PATCH] Fix handling of DW_TAG_unspecified_type for Ada Tom Tromey
@ 2023-06-28 15:49 ` Tom Tromey
  0 siblings, 0 replies; 2+ messages in thread
From: Tom Tromey @ 2023-06-28 15:49 UTC (permalink / raw)
  To: Tom Tromey via Gdb-patches; +Cc: Tom Tromey

>>>>> "Tom" == Tom Tromey via Gdb-patches <gdb-patches@sourceware.org> writes:

Tom> Commit 80eaec735e ("[gdb/symtab] Handle named DW_TAG_unspecified_type
Tom> DIE") changed the handling of DW_TAG_unspecified_type.  Before this
Tom> change, such types were not entered into the symbol table.

Tom> It turns out that, when such a type is in the symtab, it can cause
Tom> failures in Ada.  In particular, a private type in another package may
Tom> be seen locally as "void".

Tom> Now, it would probably be better to fix this via check_typedef.
Tom> However, that is somewhat difficult given the state of the DWARF
Tom> reader -- in particular with gdb_index, this would require expanding
Tom> potentially many CUs to find the correct type.

Tom> Instead, this patch changes gdb to not enter a symbol for an
Tom> unspecified type -- but only for Ada.

I'm checking this in.

Tom

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-06-28 15:49 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-15 13:03 [PATCH] Fix handling of DW_TAG_unspecified_type for Ada Tom Tromey
2023-06-28 15:49 ` Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).