binutils-gdb/gdb/dwarf2
Tom de Vries 2762d28853 [gdb/symtab] Fix CU list in .debug_names for dummy CUs
With current trunk and target board cc-with-debug-names we have:
...
(gdb) file dw2-ranges-psym^M
Reading symbols from dw2-ranges-psym...^M
warning: Section .debug_names in 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
...

The executable has 8 compilation units:
...
$ readelf -wi 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:
...
of which the ones at 0xc7 and 0x145 are dummy CUs (that is, they do not
contain a single DIE), which were added by recent commit 5ef670d81f
"[gdb/testsuite] Add dummy start and end CUs in dwarf assembly".

The .debug_names section contains this CU table:
...
[  0] 0x0
[  1] 0x2e
[  2] 0xa5
[  3] 0xd2
[  4] 0x150
[  5] 0x308
[  6] 0x1
[  7] 0x0
...
The last two entries are incorrect, and the entries for the dummy CUs are
missing.

The last two entries are incorrect because here in write_debug_names we write
the dimension of the CU list as 8:
...
  /* 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);
...
while the actual dimension of the CU list is 6.

The discrepancy is caused by this code which skips the dummy CUs:
...
  for (int i = 0; i < per_objfile->per_bfd->all_comp_units.size (); ++i)
    {
      ...
      /* 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;
...
because they have a null partial symtab.

We can fix this by writing the actual dimension of the CU list, but that still
leaves the dummy CUs out of the CU list.  The purpose of having these is to
delimit the end of preceding CUs.

So, fix this by:
- removing the code that skips the dummy CUs (note that the same change
  was done for .gdb_index in commit efba5c2319 '[gdb/symtab] Handle PU
  without import in "save gdb-index"'.
- verifying that all units are represented in the CU/TU lists
- using the actual CU list size when writing the dimension of the CU list
  (and likewise for the TU list).

Tested on x86_64-linux with native and target board cc-with-debug-names.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=28261
2021-09-14 12:57:58 +02:00
..
abbrev.c Remove Irix 6 workaround from DWARF abbrev reader 2021-03-13 09:41:05 -07:00
abbrev.h Constify abbrev_table::lookup_abbrev 2021-03-13 09:41:05 -07:00
attribute.c [gdb/symtab] Handle DW_AT_decl_file with form DW_FORM_implicit_const 2021-02-24 23:58:42 +01:00
attribute.h [gdb/symtab] Handle DW_AT_decl_file with form DW_FORM_implicit_const 2021-02-24 23:58:42 +01:00
comp-unit-head.c Rename dwarf2/comp-unit.h 2021-05-17 14:16:07 -06:00
comp-unit-head.h Rename dwarf2/comp-unit.h 2021-05-17 14:16:07 -06:00
cu.c Remove dwarf2_cu::language 2021-06-25 12:23:05 -06:00
cu.h Remove dwarf2_cu::language 2021-06-25 12:23:05 -06:00
die.h gdb/dwarf: split dwarf2_cu::ranges_base in two 2021-02-02 10:42:11 -05:00
dwz.c Move dwarf2_get_dwz_file to dwarf2/dwz.h 2021-03-06 09:26:40 -07:00
dwz.h Move dwarf2_get_dwz_file to dwarf2/dwz.h 2021-03-06 09:26:40 -07:00
expr.c Fix register regression in DWARF evaluator 2021-08-16 09:38:15 -06:00
expr.h Add as_lval argument to expression evaluator 2021-08-05 16:41:05 +01:00
frame-tailcall.c gdb: add names to unwinders, add debug messages when looking for unwinder 2021-06-29 12:05:03 -04:00
frame-tailcall.h Update copyright year range in all GDB files 2021-01-01 12:12:21 +04:00
frame.c Add as_lval argument to expression evaluator 2021-08-05 16:41:05 +01:00
frame.h Update copyright year range in all GDB files 2021-01-01 12:12:21 +04:00
index-cache.c gdb: generate the prefix name for prefix commands on demand 2021-05-12 11:19:22 +01:00
index-cache.h Update copyright year range in all GDB files 2021-01-01 12:12:21 +04:00
index-common.c Update copyright year range in all GDB files 2021-01-01 12:12:21 +04:00
index-common.h Handle unaligned mapping of .gdb_index 2021-04-17 13:56:36 -06:00
index-write.c [gdb/symtab] Fix CU list in .debug_names for dummy CUs 2021-09-14 12:57:58 +02:00
index-write.h Introduce dwarf2/public.h 2021-03-20 17:23:40 -06:00
leb.c Update copyright year range in all GDB files 2021-01-01 12:12:21 +04:00
leb.h Update copyright year range in all GDB files 2021-01-01 12:12:21 +04:00
line-header.c Fix file-name handling regression with DWARF index 2021-07-17 11:08:18 -06:00
line-header.h Fix file-name handling regression with DWARF index 2021-07-17 11:08:18 -06:00
loc.c Add as_lval argument to expression evaluator 2021-08-05 16:41:05 +01:00
loc.h Add as_lval argument to expression evaluator 2021-08-05 16:41:05 +01:00
macro.c Include objfiles.h in a few .c files 2021-08-08 08:53:17 -06:00
macro.h gdb: avoid dereferencing empty str_offsets_base optional in dwarf_decode_macros 2021-08-04 15:26:22 -04:00
public.h Simplify DWARF reader initialization 2021-03-28 10:43:15 -06:00
read.c Fix two regressions caused by CU / TU merging 2021-08-24 07:51:46 -06:00
read.h Fix two regressions caused by CU / TU merging 2021-08-24 07:51:46 -06:00
sect-names.h Move dwarf2_get_dwz_file to dwarf2/dwz.h 2021-03-06 09:26:40 -07:00
section.c gdb: Handle missing .debug_str section 2021-04-07 11:31:30 +01:00
section.h Update copyright year range in all GDB files 2021-01-01 12:12:21 +04:00
stringify.c Reimplement dwarf_unit_type_name 2021-03-18 12:08:41 -06:00
stringify.h Fix typo in dwarf2/stringify.h 2021-03-31 09:48:56 -06:00