binutils-gdb/gdb/dwarf2
Tom de Vries 8728fb3385 [gdb/symtab] Fix assert in process_imported_unit_die
When running test-case gdb.dwarf2/dw2-symtab-includes.exp with target board
cc-with-debug-names, I run into:
...
(gdb) maint expand-symtab dw2-symtab-includes.h^M
src/gdb/dwarf2/read.h:311: internal-error: unit_type: \
  Assertion `m_unit_type != 0' failed.^M
A problem internal to GDB has been detected,^M
further debugging may prove unreliable.^M
----- Backtrace -----^M
FAIL: gdb.dwarf2/dw2-symtab-includes.exp: maint expand-symtab \
  dw2-symtab-includes.h (GDB internal error)
...

The assert was recently added in commit 2c474c4694 ("[gdb/symtab] Add get/set
functions for per_cu->lang/unit_type").

The assert is triggered here:
...
    /* We're importing a C++ compilation unit with tag DW_TAG_compile_unit
       into another compilation unit, at root level.  Regard this as a hint,
       and ignore it.  */
    if (die->parent && die->parent->parent == NULL
        && per_cu->unit_type () == DW_UT_compile
        && per_cu->lang () == language_cplus)
      return;
...

We're trying to access unit_type / lang which hasn't been set yet.

Normally, these are set during cooked index creation, but that's not the case
when using an index (or using -readnow).

In other words, this lto binary reading speed optimization only works in the
normal use case.

IWBN to have this working in all use cases, but for now, allow lang () and
unit_type () to return language_unknown and 0 here.

Tested on x86_64-linux.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29321
2022-07-08 15:56:06 +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 Remove addrmap::create_fixed 2022-06-12 10:49:48 -06:00
cu.c [gdb/symtab] Add get/set functions for per_cu->lang/unit_type 2022-07-04 10:28:42 +02:00
cu.h
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] Add get/set functions for per_cu->lang/unit_type 2022-07-04 10:28:42 +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 assert in process_imported_unit_die 2022-07-08 15:56:06 +02:00
read.h [gdb/symtab] Fix assert in process_imported_unit_die 2022-07-08 15:56:06 +02:00
sect-names.h
section.c
section.h
stringify.c
stringify.h
tag.h