binutils-gdb/gdb/dwarf2
Tom de Vries 263ad5cc81 [gdb/symtab] Fix duplicate CUs in all_comp_units
When running test-case gdb.cp/cpexprs-debug-types.exp with target board
cc-with-debug-names on a system with gcc 12.1.1 (defaulting to dwarf 5), I
run into:
...
(gdb) file cpexprs-debug-types^M
Reading symbols from cpexprs-debug-types...^M
warning: Section .debug_aranges in cpexprs-debug-types has duplicate \
  debug_info_offset 0x0, ignoring .debug_aranges.^M
gdb/dwarf2/read.h:309: internal-error: set_length: \
  Assertion `m_length == length' failed.^M
...

The exec contains a .debug_names section, which gdb rejects due to
.debug_names containing a list of TUs, while the exec doesn't contain a
.debug_types section (which is what you'd expect for dwarf 4).

Gdb then falls back onto the cooked index, which calls create_all_comp_units
to create all_comp_units.  However, the failed index reading left some
elements in all_comp_units, so we end up with duplicates in all_comp_units,
which causes the misleading complaint and the assert.

Fix this by:
- asserting at the start of create_all_comp_units that all_comp_units is empty,
  as we do in create_cus_from_index and create_cus_from_debug_names, and
- cleaning up all_comp_units when failing in dwarf2_read_debug_names.

Add a similar cleanup in dwarf2_read_gdb_index.

Tested on x86_64-linux.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29381
2022-07-22 23:50:48 +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
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 duplicate CUs in all_comp_units 2022-07-22 23:50:48 +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