summaryrefslogtreecommitdiff
path: root/include/llvm/DebugInfo/DWARF/DWARFAcceleratorTable.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/llvm/DebugInfo/DWARF/DWARFAcceleratorTable.h')
-rw-r--r--include/llvm/DebugInfo/DWARF/DWARFAcceleratorTable.h58
1 files changed, 51 insertions, 7 deletions
diff --git a/include/llvm/DebugInfo/DWARF/DWARFAcceleratorTable.h b/include/llvm/DebugInfo/DWARF/DWARFAcceleratorTable.h
index eb6d0f541c1ed..0bade10f6201b 100644
--- a/include/llvm/DebugInfo/DWARF/DWARFAcceleratorTable.h
+++ b/include/llvm/DebugInfo/DWARF/DWARFAcceleratorTable.h
@@ -13,7 +13,7 @@
#include "llvm/ADT/SmallVector.h"
#include "llvm/BinaryFormat/Dwarf.h"
#include "llvm/DebugInfo/DWARF/DWARFDataExtractor.h"
-#include "llvm/DebugInfo/DWARF/DWARFRelocMap.h"
+#include "llvm/DebugInfo/DWARF/DWARFFormValue.h"
#include <cstdint>
#include <utility>
@@ -21,6 +21,9 @@ namespace llvm {
class raw_ostream;
+/// This implements the Apple accelerator table format, a precursor of the
+/// DWARF 5 accelerator table format.
+/// TODO: Factor out a common base class for both formats.
class DWARFAcceleratorTable {
struct Header {
uint32_t Magic;
@@ -43,13 +46,51 @@ class DWARFAcceleratorTable {
struct HeaderData HdrData;
DWARFDataExtractor AccelSection;
DataExtractor StringSection;
+ bool IsValid = false;
public:
+ /// An iterator for the entries associated with one key. Each entry can have
+ /// multiple DWARFFormValues.
+ class ValueIterator : public std::iterator<std::input_iterator_tag,
+ ArrayRef<DWARFFormValue>> {
+ const DWARFAcceleratorTable *AccelTable = nullptr;
+ SmallVector<DWARFFormValue, 3> AtomForms; ///< The decoded data entry.
+
+ unsigned DataOffset = 0; ///< Offset into the section.
+ unsigned Data = 0; ///< Current data entry.
+ unsigned NumData = 0; ///< Number of data entries.
+
+ /// Advance the iterator.
+ void Next();
+ public:
+ /// Construct a new iterator for the entries at \p DataOffset.
+ ValueIterator(const DWARFAcceleratorTable &AccelTable, unsigned DataOffset);
+ /// End marker.
+ ValueIterator() = default;
+
+ const ArrayRef<DWARFFormValue> operator*() const {
+ return AtomForms;
+ }
+ ValueIterator &operator++() { Next(); return *this; }
+ ValueIterator operator++(int) {
+ ValueIterator I = *this;
+ Next();
+ return I;
+ }
+ friend bool operator==(const ValueIterator &A, const ValueIterator &B) {
+ return A.NumData == B.NumData && A.DataOffset == B.DataOffset;
+ }
+ friend bool operator!=(const ValueIterator &A, const ValueIterator &B) {
+ return !(A == B);
+ }
+ };
+
+
DWARFAcceleratorTable(const DWARFDataExtractor &AccelSection,
DataExtractor StringSection)
: AccelSection(AccelSection), StringSection(StringSection) {}
- bool extract();
+ llvm::Error extract();
uint32_t getNumBuckets();
uint32_t getNumHashes();
uint32_t getSizeHdr();
@@ -61,12 +102,15 @@ public:
/// performing a lookup by name.
///
/// \param HashDataOffset an offset into the hash data table
- /// \returns DIEOffset the offset into the .debug_info section for the DIE
- /// related to the input hash data offset. Currently this function returns
- /// only the DIEOffset but it can be modified to return more data regarding
- /// the DIE
- uint32_t readAtoms(uint32_t &HashDataOffset);
+ /// \returns <DieOffset, DieTag>
+ /// DieOffset is the offset into the .debug_info section for the DIE
+ /// related to the input hash data offset.
+ /// DieTag is the tag of the DIE
+ std::pair<uint32_t, dwarf::Tag> readAtoms(uint32_t &HashDataOffset);
void dump(raw_ostream &OS) const;
+
+ /// Look up all entries in the accelerator table matching \c Key.
+ iterator_range<ValueIterator> equal_range(StringRef Key) const;
};
} // end namespace llvm