Ver Fonte

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.
Itamar há 4 anos atrás
pai
commit
835efa1b6a

+ 11 - 0
Userland/Libraries/LibDebug/Dwarf/DwarfInfo.cpp

@@ -308,4 +308,15 @@ Optional<DIE> DwarfInfo::get_die_at_address(FlatPtr address) const
     return iter->die;
 }
 
+Optional<DIE> 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;
+}
+
 }

+ 7 - 0
Userland/Libraries/LibDebug/Dwarf/DwarfInfo.h

@@ -39,6 +39,13 @@ public:
 
     Optional<DIE> 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<DIE> get_cached_die_at_offset(FlatPtr) const;
+
 private:
     void populate_compilation_units();
     void build_cached_dies() const;