From 835efa1b6a5b7e3d77e8a19372da983a8289e899 Mon Sep 17 00:00:00 2001 From: Itamar Date: Sat, 19 Jun 2021 12:03:14 +0300 Subject: [PATCH] LibDebug: Add DwarfInfo::get_cached_die_at_offset This function returns a DIE object from the cache with the given offset in the debug_info section. --- Userland/Libraries/LibDebug/Dwarf/DwarfInfo.cpp | 11 +++++++++++ Userland/Libraries/LibDebug/Dwarf/DwarfInfo.h | 7 +++++++ 2 files changed, 18 insertions(+) diff --git a/Userland/Libraries/LibDebug/Dwarf/DwarfInfo.cpp b/Userland/Libraries/LibDebug/Dwarf/DwarfInfo.cpp index e00b74997b..5e581798d7 100644 --- a/Userland/Libraries/LibDebug/Dwarf/DwarfInfo.cpp +++ b/Userland/Libraries/LibDebug/Dwarf/DwarfInfo.cpp @@ -308,4 +308,15 @@ Optional DwarfInfo::get_die_at_address(FlatPtr address) const return iter->die; } +Optional DwarfInfo::get_cached_die_at_offset(FlatPtr offset) const +{ + if (!m_built_cached_dies) + build_cached_dies(); + + auto* die = m_cached_dies_by_offset.find(offset); + if (!die) + return {}; + return *die; +} + } diff --git a/Userland/Libraries/LibDebug/Dwarf/DwarfInfo.h b/Userland/Libraries/LibDebug/Dwarf/DwarfInfo.h index 6bdfe98567..4338643826 100644 --- a/Userland/Libraries/LibDebug/Dwarf/DwarfInfo.h +++ b/Userland/Libraries/LibDebug/Dwarf/DwarfInfo.h @@ -39,6 +39,13 @@ public: Optional get_die_at_address(FlatPtr) const; + // Note that even if there is a DIE at the given offset, + // but it does not exist in the DIE cache (because for example + // it does not contain an address range), then this function will not return it. + // To get any DIE object at a given offset in a compilation unit, + // use CompilationUnit::get_die_at_offset. + Optional get_cached_die_at_offset(FlatPtr) const; + private: void populate_compilation_units(); void build_cached_dies() const;