public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH][gdb/symtab] Fix duplicate CUs in all_comp_units
@ 2022-07-19 16:48 Tom de Vries
  2022-07-22 19:15 ` Tom Tromey
  0 siblings, 1 reply; 2+ messages in thread
From: Tom de Vries @ 2022-07-19 16:48 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

Hi,

When running test-case gdb.cp/cpexprs-debug-types.exp with target board
cc-with-debug-names on a system with gcc 12.1.1 (defaulting to dwarf 5), I
run into:
...
(gdb) file cpexprs-debug-types^M
Reading symbols from cpexprs-debug-types...^M
warning: Section .debug_aranges in cpexprs-debug-types has duplicate \
  debug_info_offset 0x0, ignoring .debug_aranges.^M
gdb/dwarf2/read.h:309: internal-error: set_length: \
  Assertion `m_length == length' failed.^M
...

The exec contains a .debug_names section, which gdb rejects due to
.debug_names containing a list of TUs, while the exec doesn't contain a
.debug_types section (which is what you'd expect for dwarf 4).  Filed as
PR29385.

Gdb then falls back onto the cooked index, which calls create_all_comp_units
to create all_comp_units.  However, the failed index reading left some
elements in all_comp_units, so we end up with duplicates in all_comp_units,
which causes the misleading complaint and the assert.

Fix this by:
- asserting at the start of create_all_comp_units that all_comp_units is empty,
  as we do in create_cus_from_index and create_cus_from_debug_names, and
- cleaning up all_comp_units when failing in dwarf2_read_debug_names.

Add a similar cleanup in dwarf2_read_gdb_index.

Tested on x86_64-linux.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29381

Any comments?

Thanks,
- Tom

[gdb/symtab] Fix duplicate CUs in all_comp_units

---
 gdb/dwarf2/read.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 143bcfb5374..cfa15e166bb 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -2696,7 +2696,10 @@ dwarf2_read_gdb_index
       /* We can only handle a single .debug_types when we have an
 	 index.  */
       if (per_bfd->types.size () != 1)
-	return 0;
+	{
+	  per_bfd->all_comp_units.clear ();
+	  return 0;
+	}
 
       dwarf2_section_info *section = &per_bfd->types[0];
 
@@ -4701,7 +4704,10 @@ dwarf2_read_debug_names (dwarf2_per_objfile *per_objfile)
       /* We can only handle a single .debug_types when we have an
 	 index.  */
       if (per_bfd->types.size () != 1)
-	return false;
+	{
+	  per_bfd->all_comp_units.clear ();
+	  return false;
+	}
 
       dwarf2_section_info *section = &per_bfd->types[0];
 
@@ -7213,6 +7219,7 @@ static void
 create_all_comp_units (dwarf2_per_objfile *per_objfile)
 {
   htab_up types_htab;
+  gdb_assert (per_objfile->per_bfd->all_comp_units.empty ());
 
   read_comp_units_from_section (per_objfile, &per_objfile->per_bfd->info,
 				&per_objfile->per_bfd->abbrev, 0,

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

* Re: [PATCH][gdb/symtab] Fix duplicate CUs in all_comp_units
  2022-07-19 16:48 [PATCH][gdb/symtab] Fix duplicate CUs in all_comp_units Tom de Vries
@ 2022-07-22 19:15 ` Tom Tromey
  0 siblings, 0 replies; 2+ messages in thread
From: Tom Tromey @ 2022-07-22 19:15 UTC (permalink / raw)
  To: Tom de Vries via Gdb-patches; +Cc: Tom de Vries, Tom Tromey

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

Tom> Fix this by:
Tom> - asserting at the start of create_all_comp_units that all_comp_units is empty,
Tom>   as we do in create_cus_from_index and create_cus_from_debug_names, and
Tom> - cleaning up all_comp_units when failing in dwarf2_read_debug_names.

Tom> Add a similar cleanup in dwarf2_read_gdb_index.

Looks good.  Thank you.

Tom

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

end of thread, other threads:[~2022-07-22 19:15 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-19 16:48 [PATCH][gdb/symtab] Fix duplicate CUs in all_comp_units Tom de Vries
2022-07-22 19:15 ` 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).