[gdb/symtab] Fix gdb-index writing for .debug_types
authorTom de Vries <tdevries@suse.de>
Thu, 7 Sep 2023 19:59:33 +0000 (21:59 +0200)
committerTom de Vries <tdevries@suse.de>
Thu, 7 Sep 2023 19:59:33 +0000 (21:59 +0200)
commitbe7d5d2c417a842452f5f5d4ed7fc8d058a970bf
tree3c52d06e20775a3b4447358f619f2df587f9f265
parent74c36641b0e997ce81294e5bd4fe2d2ce017ea57
[gdb/symtab] Fix gdb-index writing for .debug_types

With test-case gdb.ada/same_enum.exp and target board dwarf4-gdb-index we run
into:
...
(gdb) print red^M
No definition of "red" in current context.^M
(gdb) FAIL: gdb.ada/same_enum.exp: print red
...

[ This is a regression since commit 844a72efbce ("Simplify gdb_index writing"),
so this is broken in gdb 12 and 13. ]

The easiest way to see what's going wrong is with readelf.  We have in section
.gdb_index:
...
[7194] pck__red:
        2 [static, variable]
        3 [static, variable]
...
which points to the CUs 2 and 3 in the CU list (shown using "2" and "3"), but
should be pointing to the TUs 2 and 3 in the TU list (shown using "T2" and
"T3").

Fix this by removing the counter / types_counter distinction in
write_gdbindex, such that we get the expected:
...
[7194] pck__red:
        T2 [static, variable]
        T3 [static, variable]
...

[ While reading write_gdbindex I noticed a few oddities related to dwz
handling, I've filed PR30829 about this. ]

Tested on x86_64-linux.

Approved-By: Tom Tromey <tom@tromey.com>
PR symtab/30827
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30827
gdb/dwarf2/index-write.c