DWARFUnit: Add a couple of helpers to access the DIE array.
authorFrederic Riss <friss@apple.com>
Fri, 13 Feb 2015 23:18:24 +0000 (23:18 +0000)
committerFrederic Riss <friss@apple.com>
Fri, 13 Feb 2015 23:18:24 +0000 (23:18 +0000)
To be used in dsymutil (or any other client that wants to take
advantage of the fact that DIEs are stored in a vector).

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@229179 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/DebugInfo/DWARF/DWARFUnit.h

index ff6a4022ffc52b3620795eba6d26cfe2bbbbe784..628852f219e62162da17c358215e062d9d5a7d2c 100644 (file)
@@ -233,6 +233,26 @@ public:
     return DIE - &DieArray[0];
   }
 
+  /// \brief Return the DIE object at the given index.
+  const DWARFDebugInfoEntryMinimal *getDIEAtIndex(unsigned Index) const {
+    assert(Index < DieArray.size());
+    return &DieArray[Index];
+  }
+
+  /// \brief Return the DIE object for a given offset inside the
+  /// unit's DIE vector.
+  ///
+  /// The unit needs to have his DIEs extracted for this method to work.
+  const DWARFDebugInfoEntryMinimal *getDIEForOffset(uint32_t Offset) const {
+    assert(!DieArray.empty());
+    auto it = std::lower_bound(
+        DieArray.begin(), DieArray.end(), Offset,
+        [=](const DWARFDebugInfoEntryMinimal &LHS, uint32_t Offset) {
+          return LHS.getOffset() < Offset;
+        });
+    return it == DieArray.end() ? nullptr : &*it;
+  }
+
 private:
   /// Size in bytes of the .debug_info data associated with this compile unit.
   size_t getDebugInfoSize() const { return Length + 4 - getHeaderSize(); }