binutils-gdb/gdb/dwarf2
Tom de Vries 2fe9a3c41f [gdb/symtab] Fix bad compile unit index complaint
I noticed this code in dw2_debug_names_iterator::next:
...
        case DW_IDX_compile_unit:
          /* Don't crash on bad data.  */
          if (ull >= per_bfd->all_comp_units.size ())
            {
              complaint (_(".debug_names entry has bad CU index %s"
                           " [in module %s]"),
                         pulongest (ull),
                         objfile_name (objfile));
              continue;
            }
          per_cu = per_bfd->get_cu (ull);
          break;
...

This code used to DTRT, before we started keeping both CUs and TUs in
all_comp_units.

Fix by using "per_bfd->all_comp_units.size () - per_bfd->tu_stats.nr_tus"
instead.

It's hard to produce a test-case for this, but let's try at least to trigger
the complaint somehow.  We start out by creating an exec with .debug_types and
.debug_names:
...
$ gcc -g ~/hello.c -fdebug-types-section
$ gdb-add-index -dwarf-5 a.out
...
and verify that we don't see any complaints:
...
$ gdb -q -batch -iex "set complaints 100" ./a.out
...

We look at the CU and TU table using readelf -w and conclude that we have
nr_cus == 6 and nr_tus == 1.

Now override ull in dw2_debug_names_iterator::next for the DW_IDX_compile_unit
case to 6, and we have:
...
$ gdb -q -batch -iex "set complaints 100" ./a.out
During symbol reading: .debug_names entry has bad CU index 6 [in module a.out]
...

After this, it still crashes because this code in
dw2_debug_names_iterator::next:
...
  /* Skip if already read in.  */
  if (m_per_objfile->symtab_set_p (per_cu))
    goto again;
...
is called with per_cu == nullptr.

Fix this by skipping the entry if per_cu == nullptr.

Now revert the fix and observe that the complaint disappears, so we've
confirmed that the fix is required.

A somewhat similar issue for .gdb_index in dw2_symtab_iter_next has been filed
as PR29367.

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

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29336
2022-07-21 13:05:39 +02:00
..
abbrev-cache.c
abbrev-cache.h
abbrev.c
abbrev.h
attribute.c
attribute.h
comp-unit-head.c
comp-unit-head.h
cooked-index.c [gdb/symtab] Add get/set functions for per_cu->lang/unit_type 2022-07-04 10:28:42 +02:00
cooked-index.h [gdb/symtab] Fix data race in cooked_index_functions::expand_symtabs_matching 2022-07-14 20:47:54 +02:00
cu.c [gdb/symtab] Add dwarf2_cu::lang () 2022-07-12 17:12:17 +02:00
cu.h [gdb/symtab] Add dwarf2_cu::lang () 2022-07-12 17:12:17 +02:00
die.h
dwz.c
dwz.h
expr.c
expr.h
file-and-dir.h
frame-tailcall.c
frame-tailcall.h
frame.c
frame.h
index-cache.c
index-cache.h
index-common.c
index-common.h
index-write.c [gdb/symtab] Fix data race in per_cu->length 2022-07-11 11:36:54 +02:00
index-write.h
leb.c
leb.h
line-header.c
line-header.h
loc.c
loc.h
macro.c
macro.h
mapped-index.h
public.h
read.c [gdb/symtab] Fix bad compile unit index complaint 2022-07-21 13:05:39 +02:00
read.h [gdb/symtab] Make per_cu->m_lang atomic 2022-07-14 08:19:00 +02:00
sect-names.h
section.c
section.h
stringify.c
stringify.h
tag.h