Skip to content

Commit aa5b8b8

Browse files
committed
[gdb/symtab] Fix off-by-one error in cooked_indexer::recurse
Test-case gdb.dwarf2/pr13961.exp contains: ... <1><25>: Abbrev Number: 8 (DW_TAG_class_type) <26> DW_AT_specification: <0x2a> <1><2a>: Abbrev Number: 2 (DW_TAG_class_type) <2b> DW_AT_name : foo <2f> DW_AT_byte_size : 4 <30> DW_AT_decl_file : 1 <31> DW_AT_decl_line : 1 <32> DW_AT_sibling : <0x44> ... The DIE at 0x25 contains an intra-CU forward reference, and is deferred during DIE indexing in the cooked_index, by adding it to m_deferred_entries. The resulting cooked index entries are: ... [25] ((cooked_index_entry *) 0x333b5d0) name: foo canonical: foo qualified: foo DWARF tag: DW_TAG_class_type flags: 0x0 [] DIE offset: 0x2a parent: ((cooked_index_entry *) 0) [26] ((cooked_index_entry *) 0x333b630) name: foo canonical: foo qualified: foo::foo DWARF tag: DW_TAG_class_type flags: 0x0 [] DIE offset: 0x25 parent: ((cooked_index_entry *) 0x333b5d0) [foo] ... Notice that 0x2a is the parent of 0x25, and that this is why the qualified name of 0x25 is "foo::foo", which is incorrect, it's supposed to be "foo". The parent is set here in cooked_indexer::make_index: ... for (const auto &entry : m_deferred_entries) { void *obj = m_die_range_map.find (entry.spec_offset); cooked_index_entry *parent = static_cast<cooked_index_entry *> (obj); m_index_storage->add (entry.die_offset, entry.tag, entry.flags, entry.name, parent, m_per_cu); } ... and AFAICT, we store in m_die_range_map the parent of the respective spec_offset DIE (though that's not clear from the comment describing it). So, the root cause of this is that when we lookup the parent for DIE 0x25, we get m_die_range_map.find (0x2a) == 0x2a. This is an off-by-one error, fixed in cooked_indexer::recurse by: ... - CORE_ADDR start = form_addr (parent_entry->die_offset, + CORE_ADDR start = form_addr (parent_entry->die_offset + 1, ... which gives us: ... [12] ((cooked_index_entry *) 0x41e21f0) name: foo canonical: foo qualified: foo DWARF tag: DW_TAG_class_type flags: 0x0 [] DIE offset: 0x25 parent: ((cooked_index_entry *) 0) [13] ((cooked_index_entry *) 0x41e2190) name: foo canonical: foo qualified: foo DWARF tag: DW_TAG_class_type flags: 0x0 [] DIE offset: 0x2a parent: ((cooked_index_entry *) 0) ... Tested on x86_64-linux. Approved-By: Tom Tromey <[email protected]> PR symtab/30739 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30739
1 parent 8f258a6 commit aa5b8b8

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

gdb/dwarf2/read.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16477,7 +16477,9 @@ cooked_indexer::recurse (cutu_reader *reader,
1647716477

1647816478
if (parent_entry != nullptr)
1647916479
{
16480-
CORE_ADDR start = form_addr (parent_entry->die_offset,
16480+
/* Both start and end are inclusive, so use both "+ 1" and "- 1" to
16481+
limit the range to the children of parent_entry. */
16482+
CORE_ADDR start = form_addr (parent_entry->die_offset + 1,
1648116483
reader->cu->per_cu->is_dwz);
1648216484
CORE_ADDR end = form_addr (sect_offset (info_ptr - 1 - reader->buffer),
1648316485
reader->cu->per_cu->is_dwz);

gdb/testsuite/gdb.dwarf2/pr13961.exp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,13 @@ gdb_test "break -q main" "Breakpoint.*at.*"
3434

3535
# If we get this far gdb didn't crash.
3636
pass $testfile
37+
38+
# Regression test for PR symtab/30739.
39+
gdb_test_multiple "maint print objfiles $binfile" "no foo::foo" {
40+
-re -wrap "\r\n *qualified: *foo::foo\r\n.*" {
41+
fail $gdb_test_name
42+
}
43+
-re -wrap "" {
44+
pass $gdb_test_name
45+
}
46+
}

0 commit comments

Comments
 (0)