dwarf2: avoid decoding .debug_line for type units
Checks
| Context |
Check |
Description |
| linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 |
success
|
Build passed
|
| linaro-tcwg-bot/tcwg_gdb_build--master-arm |
success
|
Build passed
|
| linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 |
success
|
Test passed
|
| linaro-tcwg-bot/tcwg_gdb_check--master-arm |
success
|
Test passed
|
Commit Message
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)
---
gdb/dwarf2/read.c | 27 ++++++++++++++++++---------
1 file changed, 18 insertions(+), 9 deletions(-)
Comments
[AMD Official Use Only - AMD Internal Distribution Only]
PING
Can someone take a look at this?
Regards Bratislav
-----Original Message-----
From: Filipovic, Bratislav <Bratislav.Filipovic@amd.com>
Sent: Wednesday, March 18, 2026 2:36 PM
To: gdb-patches@sourceware.org
Cc: simon.marchi@efficios.com; Filipovic, Bratislav <Bratislav.Filipovic@amd.com>
Subject: [PATCH] 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)
---
gdb/dwarf2/read.c | 27 ++++++++++++++++++---------
1 file changed, 18 insertions(+), 9 deletions(-)
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 8b87d58d..2e897e65 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -15484,23 +15484,32 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
if (index_cst.has_value ())
{
file_name_index file_index = (file_name_index) *index_cst;
- struct file_entry *fe;
- if (file_cu->line_header == nullptr)
+ /* Resolve DW_AT_decl_file/DW_AT_call_file. These attributes are
+ indices into the file-name table, which lives in the unit's
+ decoded .debug_line header.
+ decode_line_header_for_cu is CU-only and asserts on debug_types.
+ For type units, the TU setup code runs before processing child
+ DIEs, 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);
}
if (file_cu->line_header != nullptr)
- fe = file_cu->line_header->file_name_at (file_index);
- else
- fe = NULL;
-
- if (fe == NULL)
- complaint (_("file index out of range"));
+ {
+ if (file_entry *fe
+ = file_cu->line_header->file_name_at (file_index);
+ fe != nullptr)
+ sym->set_symtab (fe->symtab (*file_cu));
+ else
+ complaint (_("file index out of range"));
+ }
else
- sym->set_symtab (fe->symtab (*file_cu));
+ complaint (_("missing .debug_line information to resolve file
+index"));
}
}
--
2.43.0
@@ -15484,23 +15484,32 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
if (index_cst.has_value ())
{
file_name_index file_index = (file_name_index) *index_cst;
- struct file_entry *fe;
- if (file_cu->line_header == nullptr)
+ /* Resolve DW_AT_decl_file/DW_AT_call_file. These attributes are
+ indices into the file-name table, which lives in the unit's
+ decoded .debug_line header.
+ decode_line_header_for_cu is CU-only and asserts on debug_types.
+ For type units, the TU setup code runs before processing child
+ DIEs, 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);
}
if (file_cu->line_header != nullptr)
- fe = file_cu->line_header->file_name_at (file_index);
- else
- fe = NULL;
-
- if (fe == NULL)
- complaint (_("file index out of range"));
+ {
+ if (file_entry *fe
+ = file_cu->line_header->file_name_at (file_index);
+ fe != nullptr)
+ sym->set_symtab (fe->symtab (*file_cu));
+ else
+ complaint (_("file index out of range"));
+ }
else
- sym->set_symtab (fe->symtab (*file_cu));
+ complaint (_("missing .debug_line information to resolve file index"));
}
}