Skip to content

Commit 6fa80cc

Browse files
committed
gdb/dwarf: add dwarf2_cu::find_die method
I added this small helper method in the series I'm writing, to make finding a DIE by section offset a bit nicer than using the unordered_set methods. It doesn't have any dependencies, so I thought I would submit it on its own. Change-Id: If7313194ab09d9bd6d6a52c24eb6fd9a9c1b76e0 Approved-by: Kevin Buettner <[email protected]>
1 parent ac4a350 commit 6fa80cc

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

gdb/dwarf2/cu.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,15 @@ struct dwarf2_cu
9999
void add_dependence (dwarf2_per_cu *ref_per_cu)
100100
{ m_dependencies.emplace (ref_per_cu); }
101101

102+
/* Find the DIE at section offset SECT_OFF.
103+
104+
Return nullptr if not found. */
105+
die_info *find_die (sect_offset sect_off) const
106+
{
107+
auto it = die_hash.find (sect_off);
108+
return it != die_hash.end () ? *it : nullptr;
109+
}
110+
102111
/* The header of the compilation unit. */
103112
struct comp_unit_head header;
104113

gdb/dwarf2/read.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18260,8 +18260,7 @@ follow_die_offset (sect_offset sect_off, int offset_in_dwz,
1826018260

1826118261
*ref_cu = target_cu;
1826218262

18263-
auto it = target_cu->die_hash.find (sect_off);
18264-
return it != target_cu->die_hash.end () ? *it : nullptr;
18263+
return target_cu->find_die (sect_off);
1826518264
}
1826618265

1826718266
/* Follow reference attribute ATTR of SRC_DIE.
@@ -18629,8 +18628,8 @@ follow_die_sig_1 (struct die_info *src_die, struct signatured_type *sig_type,
1862918628
gdb_assert (sig_cu != NULL);
1863018629
gdb_assert (to_underlying (sig_type->type_offset_in_section) != 0);
1863118630

18632-
if (auto die_it = sig_cu->die_hash.find (sig_type->type_offset_in_section);
18633-
die_it != sig_cu->die_hash.end ())
18631+
if (die_info *die = sig_cu->find_die (sig_type->type_offset_in_section);
18632+
die != nullptr)
1863418633
{
1863518634
/* For .gdb_index version 7 keep track of included TUs.
1863618635
http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
@@ -18639,7 +18638,7 @@ follow_die_sig_1 (struct die_info *src_die, struct signatured_type *sig_type,
1863918638
(*ref_cu)->per_cu->imported_symtabs.push_back (sig_cu->per_cu);
1864018639

1864118640
*ref_cu = sig_cu;
18642-
return *die_it;
18641+
return die;
1864318642
}
1864418643

1864518644
return NULL;

0 commit comments

Comments
 (0)