[PATCH][gdb/symtab] Support .debug_names section with TUs in .debug_info

Tom de Vries tdevries@suse.de
Fri Aug 12 15:48:33 GMT 2022


Hi,

[ Requires "[gdb/symtab] Fix assert in set_length" submitted here (
https://sourceware.org/pipermail/gdb-patches/2022-August/191313.html ). ]

When running test-case gdb.cp/cpexprs-debug-types.exp on target board
cc-with-debug-names/gdb:debug_flags=-gdwarf-5, we get an executable with
a .debug_names section, but no .debug_types section.  For dwarf-5, the TUs
are no longer put in a separate unit, but instead they're put in the
.debug_info section.

When loading the executable, the .debug_names section is silently ignored
because of this check in dwarf2_read_debug_names:
...
  if (map->tu_count != 0)
    {
      /* We can only handle a single .debug_types when we have an
         index.  */
      if (per_bfd->types.size () != 1)
        return false;
...
which triggers because per_bfd->types.size () == 0.

The intention of the check is to make sure we don't have both .debug_types and
.zdebug_types sections.

Fix this by:
- changing the check condition to "per_bfd->types.size () > 1", and
- handling per_bfd->types.size () == 0.

Tested on x86_64-linux.

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

Any comments?

Thanks,
- Tom

[gdb/symtab] Support .debug_names section with TUs in .debug_info

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

diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 6c6ca96f8d9..8e82f464293 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -4736,13 +4736,16 @@ 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)
+      if (per_bfd->types.size () > 1)
 	{
 	  per_bfd->all_comp_units.clear ();
 	  return false;
 	}
 
-      dwarf2_section_info *section = &per_bfd->types[0];
+      dwarf2_section_info *section
+	= (per_bfd->types.size () == 1
+	   ? &per_bfd->types[0]
+	   : &per_bfd->info);
 
       create_signatured_type_table_from_debug_names
 	(per_objfile, *map, section, &per_bfd->abbrev);


More information about the Gdb-patches mailing list