[gdb/symtab] Don't deduplicate variables in gdb-index
authorTom de Vries <tdevries@suse.de>
Sun, 13 Aug 2023 12:08:06 +0000 (14:08 +0200)
committerTom de Vries <tdevries@suse.de>
Sun, 13 Aug 2023 12:08:06 +0000 (14:08 +0200)
commitaef36dee93bf194cb0b976a4ae49a79a736a188d
tree8dc6c608f91aa689b068b1bd9496a0f5007a2e16
parent84004b2a709e4773b0fb1b01d629b0eb2fe81bbc
[gdb/symtab] Don't deduplicate variables in gdb-index

When running test-case gdb.python/py-symbol.exp with target board
cc-with-gdb-index, we run into:
...
(gdb) python print (len (gdb.lookup_static_symbols ('rr')))^M
1^M
(gdb) FAIL: gdb.python/py-symbol.exp: print (len (gdb.lookup_static_symbols ('rr')))
...

[ Note that the test-case contains rr in both py-symtab.c:
...
static int __attribute__ ((used)) rr = 42; /* line of rr */
...
and py-symtab-2.c:
...
static int __attribute__ ((used)) rr = 99; /* line of other rr */
... ]

This passes with gdb-12-branch, and fails with gdb-13-branch.

AFAIU the current code in symtab_index_entry::minimize makes the assumption
that it's fine to store only one copy of rr in the gdb-index, because
"print rr" will only ever print one, and always the same.

But that fails to recognize that gdb supports gdb.lookup_static_symbols, which
returns a list of variables rather than the first one.

In other words, the current approach breaks feature parity between cooked
index and gdb-index.

Note btw that also debug-names has both instances:
...
[  5] #00597969 rr:
        <4> DW_TAG_variable DW_IDX_compile_unit=3 DW_IDX_GNU_internal=1
        <4> DW_TAG_variable DW_IDX_compile_unit=4 DW_IDX_GNU_internal=1
...

Fix this in symtab_index_entry::minimize, by not deduplicating variables.

Tested on x86_64-linux, with target boards unix and cc-with-gdb-index.

Reviewed-by: Kevin Buettner <kevinb@redhat.com>
PR symtab/30720
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30720
gdb/dwarf2/index-write.c