[PATCH v2] [gdb/symtab] Fix dwarf version of DWO TU

Tom de Vries
2025-01-20T08:57:50Z

When running test-case gdb.ada/access_tagged_param.exp with target board
fission, we run into:
...
(gdb) break pck.adb:19^M
gdb/dwarf2/read.h:289: internal-error: version: \
Assertion `m_dwarf_version != 0' failed.^M
...

The assertion happens when calling cu->per_cu->version () in this workaround
in read_subroutine_type:
...
/* PR gas/29517 occurs in 2.39, and is fixed in 2.40, but it's only fixed
for dwarf version >= 3 which supports DW_TAG_unspecified_type. */
if (type->code () == TYPE_CODE_VOID
&& !type->is_stub ()
&& die->child == nullptr
&& (cu->per_cu->version () == 2
|| producer_is_gas_2_39 (cu)))
{
...
for a TU in a dwo file.

Fix this by using cu->header.version instead.

Tested on aarch64-linux.

PR symtab/32309
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32309
---
gdb/dwarf2/read.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 4503977d62b..824604261f5 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -14019,7 +14019,7 @@ read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu)
if (type->code () == TYPE_CODE_VOID
&& !type->is_stub ()
&& die->child == nullptr
- && (cu->per_cu->version () == 2
+ && (cu->header.version == 2
|| producer_is_gas_2_39 (cu)))
{
/* Work around PR gas/29517, pretend we have an DW_TAG_unspecified_type

base-commit: c99345db064e1bd645bc08db65174bae7ac20b0e
--
2.43.0