[gdb/symtab] Support .debug_names section with TUs in .debug_info
authorTom de Vries <tdevries@suse.de>
Tue, 6 Sep 2022 08:15:01 +0000 (10:15 +0200)
committerTom de Vries <tdevries@suse.de>
Tue, 6 Sep 2022 08:15:01 +0000 (10:15 +0200)
commitd878bb39e417fa23b8dc62fed916708e776a9b71
treeca07f1e7869b7e8d4b785c8052fd310aaf251569
parenta4fac33dc3ab42bd6a5f41c0ceca66e681a7de8b
[gdb/symtab] Support .debug_names section with TUs in .debug_info

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 more that one
.debug_types section, as can happen in a object file (see PR12984):
...
$ grep "\.debug_types" 11.s
        .section        .debug_types,"G",@progbits,wt.75c042c23a9a07ee,comdat
        .section        .debug_types,"G",@progbits,wt.c59c413bf50a4607,comdat
...

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
gdb/dwarf2/read.c
gdb/testsuite/gdb.dwarf2/debug-names-tu-dwarf5.exp [new file with mode: 0644]
gdb/testsuite/gdb.dwarf2/debug-names-tu.exp
gdb/testsuite/gdb.dwarf2/debug-names-tu.exp.tcl [new file with mode: 0644]
gdb/testsuite/lib/dwarf.exp