Forráskód Böngészése

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.
Itamar 4 éve
szülő
commit
fb31aae20d

+ 20 - 0
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;
+}
+
 }

+ 2 - 0
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;