Bug 29321 - [gdb] read.h:311: internal-error: unit_type: Assertion `m_unit_type != 0' failed
Summary: [gdb] read.h:311: internal-error: unit_type: Assertion `m_unit_type != 0' failed
Status: RESOLVED FIXED
Alias: None
Product: gdb
Classification: Unclassified
Component: symtab (show other bugs)
Version: HEAD
: P2 normal
Target Milestone: 13.1
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-07-06 12:17 UTC by Tom de Vries
Modified: 2022-07-08 13:58 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments
Tentative patch (726 bytes, patch)
2022-07-06 12:45 UTC, Tom de Vries
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Tom de Vries 2022-07-06 12:17:55 UTC
When running test-case gdb.dwarf2/dw2-symtab-includes.exp with target board cc-with-debug-names (same with target boards cc-with-gdb-index and readnow), I run into:
...
(gdb) maint expand-symtab dw2-symtab-includes.h^M
/home/vries/gdb_versions/devel/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 2c474c46943 ("[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 speed optimization only worked in the normal usage case.
Comment 1 Tom de Vries 2022-07-06 12:45:56 UTC
Created attachment 14196 [details]
Tentative patch
Comment 2 Tom de Vries 2022-07-06 16:13:33 UTC
On openSUSE Tumbleweed, with gcc-12 defaulting to dwarf-5, I run into this PR with native:
...
FAIL: gdb.dwarf2/count.exp: runto: run to main (GDB internal error)
FAIL: gdb.dwarf2/implptrconst.exp: runto: run to main (GDB internal error)
FAIL: gdb.dwarf2/implptrpiece.exp: runto: run to main (GDB internal error)
...