From fb31aae20d0df5e59a464b444bc0ec7a0161bfba Mon Sep 17 00:00:00 2001 From: Itamar Date: Sat, 19 Jun 2021 11:59:48 +0300 Subject: LibDebug:: Add DwarfInfo::get_die_at_address This function returns the die object whose address range intersects with the given address. This function will also construct the DIE cache, if it hasn't been constructed yet. --- Userland/Libraries/LibDebug/Dwarf/DwarfInfo.cpp | 20 ++++++++++++++++++++ Userland/Libraries/LibDebug/Dwarf/DwarfInfo.h | 2 ++ 2 files changed, 22 insertions(+) (limited to 'Userland') diff --git a/Userland/Libraries/LibDebug/Dwarf/DwarfInfo.cpp b/Userland/Libraries/LibDebug/Dwarf/DwarfInfo.cpp index ab1a5ac341..e00b74997b 100644 --- a/Userland/Libraries/LibDebug/Dwarf/DwarfInfo.cpp +++ b/Userland/Libraries/LibDebug/Dwarf/DwarfInfo.cpp @@ -288,4 +288,24 @@ void DwarfInfo::build_cached_dies() const m_built_cached_dies = true; } +Optional DwarfInfo::get_die_at_address(FlatPtr address) const +{ + if (!m_built_cached_dies) + build_cached_dies(); + + auto iter = m_cached_dies_by_range.find_largest_not_above_iterator(address); + while (!iter.is_end() && !iter.is_begin() && iter->range.end_address < address) { + --iter; + } + + if (iter.is_end()) + return {}; + + if (iter->range.start_address > address || iter->range.end_address < address) { + return {}; + } + + return iter->die; +} + } diff --git a/Userland/Libraries/LibDebug/Dwarf/DwarfInfo.h b/Userland/Libraries/LibDebug/Dwarf/DwarfInfo.h index 5af366a20a..6bdfe98567 100644 --- a/Userland/Libraries/LibDebug/Dwarf/DwarfInfo.h +++ b/Userland/Libraries/LibDebug/Dwarf/DwarfInfo.h @@ -37,6 +37,8 @@ public: AttributeValue get_attribute_value(AttributeDataForm form, ssize_t implicit_const_value, InputMemoryStream& debug_info_stream, const CompilationUnit* unit = nullptr) const; + Optional get_die_at_address(FlatPtr) const; + private: void populate_compilation_units(); void build_cached_dies() const; -- cgit v1.2.3