With current trunk, we run into: ... (gdb) file /home/vries/gdb_versions/devel/build/gdb/testsuite/outputs/gdb.dwarf2/dw2-ranges-psym/dw2-ranges-psym^M Reading symbols from /home/vries/gdb_versions/devel/build/gdb/testsuite/outputs/gdb.dwarf2/dw2-ranges-psym/dw2-ranges-psym...^M warning: Section .debug_names in /home/vries/gdb_versions/devel/build/gdb/testsuite/outputs/gdb.dwarf2/dw2-ranges-psym/dw2-ranges-psym has abbreviation_table of size 1 vs. written as 28, ignoring .debug_names.^M (gdb) set complaints 0^M (gdb) FAIL: gdb.dwarf2/dw2-ranges-psym.exp: No complaints ...
Bisects to: ... commit 5ef670d81fd222ae5edfa1428ad48710f5e10d35 (HEAD) Author: Tom de Vries <tdevries@suse.de> Date: Mon Aug 23 12:08:25 2021 +0200 [gdb/testsuite] Add dummy start and end CUs in dwarf assembly ...
So we have these CUs: ... $ readelf -wi ./outputs/gdb.dwarf2/dw2-ranges-psym/dw2-ranges-psym | grep @ Compilation Unit @ offset 0x0: Compilation Unit @ offset 0x2e: Compilation Unit @ offset 0xa5: Compilation Unit @ offset 0xc7: Compilation Unit @ offset 0xd2: Compilation Unit @ offset 0x145: Compilation Unit @ offset 0x150: Compilation Unit @ offset 0x308: ... with 0xc7 a dummy CU: ... Compilation Unit @ offset 0xc7: Length: 0x7 (32-bit) Version: 4 Abbrev Offset: 0x64 Pointer Size: 8 Compilation Unit @ offset 0xd2: ... as well as 0x145: ... Compilation Unit @ offset 0x145: Length: 0x7 (32-bit) Version: 4 Abbrev Offset: 0xaa Pointer Size: 8 Compilation Unit @ offset 0x150: ... And in the .debug_names section we have: ... Version 5 Augmentation string: 47 44 42 00 ("GDB") CU table: [ 0] 0x0 [ 1] 0x2e [ 2] 0xa5 [ 3] 0xd2 [ 4] 0x150 [ 5] 0x308 [ 6] 0x1 [ 7] 0x0 ... The entries for the dummy CUs are missing, and the last two entries are incorrect.
Fixed by: ... diff --git a/gdb/dwarf2/index-write.c b/gdb/dwarf2/index-write.c index 4e00c716d91..813c19ef850 100644 --- a/gdb/dwarf2/index-write.c +++ b/gdb/dwarf2/index-write.c @@ -1428,16 +1428,10 @@ write_debug_names (dwarf2_per_objfile *per_objfile, = per_objfile->per_bfd->all_comp_units[i].get (); partial_symtab *psymtab = per_cu->v.psymtab; - /* CU of a shared file from 'dwz -m' may be unused by this main - file. It may be referenced from a local scope but in such - case it does not need to be present in .debug_names. */ - if (psymtab == NULL) - continue; - int &this_counter = per_cu->is_debug_types ? types_counter : counter; data_buf &this_list = per_cu->is_debug_types ? types_cu_list : cu_list; - if (psymtab->user == NULL) + if (psymtab != nullptr && psymtab->user == nullptr) nametable.recursively_write_psymbols (objfile, psymtab, psyms_seen, this_counter); ... which gives us: ... CU table: [ 0] 0x0 [ 1] 0x2e [ 2] 0xa5 [ 3] 0xc7 [ 4] 0xd2 [ 5] 0x145 [ 6] 0x150 [ 7] 0x308 ...
Alternatively, we can do: ... diff --git a/gdb/dwarf2/index-write.c b/gdb/dwarf2/index-write.c index 4e00c716d91..7333e2b2d55 100644 --- a/gdb/dwarf2/index-write.c +++ b/gdb/dwarf2/index-write.c @@ -1481,14 +1481,11 @@ write_debug_names (dwarf2_per_objfile *per_objfile, header.append_uint (2, dwarf5_byte_order, 0); /* comp_unit_count - The number of CUs in the CU list. */ - header.append_uint (4, dwarf5_byte_order, - per_objfile->per_bfd->all_comp_units.size () - - per_objfile->per_bfd->tu_stats.nr_tus); + header.append_uint (4, dwarf5_byte_order, counter); /* local_type_unit_count - The number of TUs in the local TU list. */ - header.append_uint (4, dwarf5_byte_order, - per_objfile->per_bfd->tu_stats.nr_tus); + header.append_uint (4, dwarf5_byte_order, types_counter); /* foreign_type_unit_count - The number of TUs in the foreign TU list. */ ... which gives us: ... CU table: [ 0] 0x0 [ 1] 0x2e [ 2] 0xa5 [ 3] 0xd2 [ 4] 0x150 [ 5] 0x308 ... but then we run into: ... $ gdb -q -batch \ -ex "set trace-commands on" \ -x outputs/gdb.dwarf2/dw2-ranges-psym/gdb.in.6 +set height 0 +set width 0 +dir +dir /home/vries/gdb_versions/devel/src/gdb/testsuite/gdb.dwarf2 +show complaints Max number of complaints about incorrect symbols is 0. +set complaints 5 +file ./outputs/gdb.dwarf2/dw2-ranges-psym/dw2-ranges-psym +set complaints 0 +delete breakpoints +info breakpoints No breakpoints or watchpoints. +break -qualified main Breakpoint 1 at 0x4004ab +run Breakpoint 1, 0x00000000004004ab in main () +break someothername src/gdb/dwarf2/read.c:6627: internal-error: cutu_reader::cutu_reader(dwarf2_per_cu_data*, dwarf2_per_objfile*, abbrev_table*, dwarf2_cu*, bool): Assertion `this_cu->length == cu->header.get_length ()' failed. ...
https://sourceware.org/pipermail/gdb-patches/2021-August/181672.html
https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=2762d288534f48dc8653524b878883472037a57c : [gdb/symtab] Fix CU list in .debug_names for dummy CUs