* [PATCH] gdb/dwarf: add dwarf2_cu::find_die method
@ 2025-04-24 20:36 simon.marchi
2025-04-24 21:42 ` Kevin Buettner
0 siblings, 1 reply; 3+ messages in thread
From: simon.marchi @ 2025-04-24 20:36 UTC (permalink / raw)
To: gdb-patches; +Cc: Simon Marchi
From: Simon Marchi <simon.marchi@efficios.com>
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
---
gdb/dwarf2/cu.h | 9 +++++++++
gdb/dwarf2/read.c | 9 ++++-----
2 files changed, 13 insertions(+), 5 deletions(-)
diff --git a/gdb/dwarf2/cu.h b/gdb/dwarf2/cu.h
index 5683291fbcfe..6eda19b80a61 100644
--- a/gdb/dwarf2/cu.h
+++ b/gdb/dwarf2/cu.h
@@ -99,6 +99,15 @@ struct dwarf2_cu
void add_dependence (dwarf2_per_cu *ref_per_cu)
{ m_dependencies.emplace (ref_per_cu); }
+ /* Find the DIE at section offset SECT_OFF.
+
+ Return nullptr if not found. */
+ die_info *find_die (sect_offset sect_off) const
+ {
+ auto it = die_hash.find (sect_off);
+ return it != die_hash.end () ? *it : nullptr;
+ }
+
/* The header of the compilation unit. */
struct comp_unit_head header;
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 2523ca869598..6b7f2c784768 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -18260,8 +18260,7 @@ follow_die_offset (sect_offset sect_off, int offset_in_dwz,
*ref_cu = target_cu;
- auto it = target_cu->die_hash.find (sect_off);
- return it != target_cu->die_hash.end () ? *it : nullptr;
+ return target_cu->find_die (sect_off);
}
/* 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,
gdb_assert (sig_cu != NULL);
gdb_assert (to_underlying (sig_type->type_offset_in_section) != 0);
- if (auto die_it = sig_cu->die_hash.find (sig_type->type_offset_in_section);
- die_it != sig_cu->die_hash.end ())
+ if (die_info *die = sig_cu->find_die (sig_type->type_offset_in_section);
+ die != nullptr)
{
/* For .gdb_index version 7 keep track of included TUs.
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,
(*ref_cu)->per_cu->imported_symtabs.push_back (sig_cu->per_cu);
*ref_cu = sig_cu;
- return *die_it;
+ return die;
}
return NULL;
base-commit: 876c853cb99cd9c097fa915c8d00bf6b9d7c5904
--
2.49.0
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] gdb/dwarf: add dwarf2_cu::find_die method
2025-04-24 20:36 [PATCH] gdb/dwarf: add dwarf2_cu::find_die method simon.marchi
@ 2025-04-24 21:42 ` Kevin Buettner
2025-04-25 2:46 ` Simon Marchi
0 siblings, 1 reply; 3+ messages in thread
From: Kevin Buettner @ 2025-04-24 21:42 UTC (permalink / raw)
To: simon.marchi; +Cc: gdb-patches, Simon Marchi
On Thu, 24 Apr 2025 16:36:02 -0400
simon.marchi@polymtl.ca wrote:
> 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.
LGTM.
Approved-by: Kevin Buettner <kevinb@redhat.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] gdb/dwarf: add dwarf2_cu::find_die method
2025-04-24 21:42 ` Kevin Buettner
@ 2025-04-25 2:46 ` Simon Marchi
0 siblings, 0 replies; 3+ messages in thread
From: Simon Marchi @ 2025-04-25 2:46 UTC (permalink / raw)
To: Kevin Buettner, simon.marchi; +Cc: gdb-patches
On 2025-04-24 17:42, Kevin Buettner wrote:
> On Thu, 24 Apr 2025 16:36:02 -0400
> simon.marchi@polymtl.ca wrote:
>
>> 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.
>
> LGTM.
>
> Approved-by: Kevin Buettner <kevinb@redhat.com>
>
Thanks, pushed.
Simon
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-04-25 2:47 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-04-24 20:36 [PATCH] gdb/dwarf: add dwarf2_cu::find_die method simon.marchi
2025-04-24 21:42 ` Kevin Buettner
2025-04-25 2:46 ` Simon Marchi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox