[binutils-gdb] dwarf2: avoid decoding .debug_line for type units
Bratislav Filipovic via Gdb-cvs <[email protected]>
| Newsgroups | gmane.comp.gdb.cvs |
|---|---|
| Message-ID | <[email protected]> |
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=8f583ac13920391c22e864f9aa6487379edb3995 commit 8f583ac13920391c22e864f9aa6487379edb3995 Author: Bratislav Filipovic <[email protected]> Date: Thu Apr 23 16:17:20 2026 +0000 dwarf2: avoid decoding .debug_line for type units Running gdb.dwarf2/pr13961.exp with clang fails with an internal error: gdb/dwarf2/read.c: internal-error: decode_line_header_for_cu: Assertion `!cu->per_cu->is_debug_types ()' failed. pr13961 is a legacy .S test that references a .debug_line label from both a CU and a TU. The assembly includes an empty .debug_line section declaration: .section .debug_line,"",%progbits .Ldebug_line0: With gcc this results in a dummy (valid, but content-less) .debug_line header being emitted, so GDB can build a line header and resolve file indices. With clang the .debug_line section can be missing/empty, leaving the line header unset. During symbol creation, new_symbol may then try to lazily decode the CU-only line header while processing a type unit, which triggers the assertion above. Fix this by only decoding the line header for non-type units. If no line header is available, emit a complaint and continue without setting the symtab rather than attempting CU-only line decoding from a TU. Tested: gdb.dwarf2/pr13961.exp (CC_FOR_TARGET=clang-23) Diff: --- gdb/dwarf2/read.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index bc7b8b46d87..890a36809f7 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -15452,16 +15452,28 @@ new_symbol_file_line (struct die_info *die, struct dwarf2_cu *cu, if (!index_cst.has_value ()) return; - if (file_cu->line_header == nullptr) + /* decode_line_header_for_cu is CU-only and asserts on type units. + For type units, the line header setup runs before processing child + DIEs, in method dwarf2_cu::setup_type_unit_groups. So if + line_header is still nullptr here it means there is no usable line + table for this unit. */ + if (file_cu->line_header == nullptr + && !file_cu->per_cu->is_debug_types ()) { file_and_directory fnd (nullptr, nullptr); decode_line_header_for_cu (file_cu->dies, file_cu, fnd); } file_name_index file_index = (file_name_index) *index_cst; - struct file_entry *fe = nullptr; - if (file_cu->line_header != nullptr) - fe = file_cu->line_header->file_name_at (file_index); + + /* Check if we successfully got line_header. */ + if (file_cu->line_header == nullptr) + { + complaint (_("missing .debug_line information to resolve file index")); + return; + } + + struct file_entry *fe = file_cu->line_header->file_name_at (file_index); if (fe == nullptr) {