diff options
author | Itamar <itamar8910@gmail.com> | 2021-06-19 11:59:48 +0300 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-06-19 14:51:18 +0200 |
commit | fb31aae20d0df5e59a464b444bc0ec7a0161bfba (patch) | |
tree | 98347013dbd4fd031997a02f4c7a18c8c476eb52 /Userland | |
parent | 92d4962d0425f2d935102334e2bfc7db2717f08b (diff) | |
download | serenity-fb31aae20d0df5e59a464b444bc0ec7a0161bfba.zip |
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.
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Libraries/LibDebug/Dwarf/DwarfInfo.cpp | 20 | ||||
-rw-r--r-- | Userland/Libraries/LibDebug/Dwarf/DwarfInfo.h | 2 |
2 files changed, 22 insertions, 0 deletions
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<DIE> 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<DIE> get_die_at_address(FlatPtr) const; + private: void populate_compilation_units(); void build_cached_dies() const; |