1 //===-- DWARFUnitIndex.h --------------------------------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #ifndef LLVM_LIB_DEBUGINFO_DWARFUNITINDEX_H 11 #define LLVM_LIB_DEBUGINFO_DWARFUNITINDEX_H 12 13 #include "llvm/Support/DataExtractor.h" 14 #include "llvm/Support/Format.h" 15 #include "llvm/Support/raw_ostream.h" 16 #include <cstdint> 17 18 namespace llvm { 19 20 enum DWARFSectionKind { 21 DW_SECT_INFO = 1, 22 DW_SECT_TYPES, 23 DW_SECT_ABBREV, 24 DW_SECT_LINE, 25 DW_SECT_LOC, 26 DW_SECT_STR_OFFSETS, 27 DW_SECT_MACINFO, 28 DW_SECT_MACRO, 29 }; 30 31 class DWARFUnitIndex { 32 struct Header { 33 uint32_t Version; 34 uint32_t NumColumns; 35 uint32_t NumUnits; 36 uint32_t NumBuckets = 0; 37 38 bool parse(DataExtractor IndexData, uint32_t *OffsetPtr); 39 void dump(raw_ostream &OS) const; 40 }; 41 42 public: 43 class Entry { 44 public: 45 struct SectionContribution { 46 uint32_t Offset; 47 uint32_t Length; 48 }; 49 50 private: 51 const DWARFUnitIndex *Index; 52 uint64_t Signature; 53 std::unique_ptr<SectionContribution[]> Contributions; 54 friend class DWARFUnitIndex; 55 56 public: 57 const SectionContribution *getOffset(DWARFSectionKind Sec) const; 58 const SectionContribution *getOffset() const; 59 }; 60 61 private: 62 struct Header Header; 63 64 DWARFSectionKind InfoColumnKind; 65 int InfoColumn = -1; 66 std::unique_ptr<DWARFSectionKind[]> ColumnKinds; 67 std::unique_ptr<Entry[]> Rows; 68 69 static StringRef getColumnHeader(DWARFSectionKind DS); 70 bool parseImpl(DataExtractor IndexData); 71 72 public: 73 bool parse(DataExtractor IndexData); 74 DWARFUnitIndex(DWARFSectionKind InfoColumnKind) 75 : InfoColumnKind(InfoColumnKind) {} 76 void dump(raw_ostream &OS) const; 77 const Entry *getFromOffset(uint32_t Offset) const; 78 }; 79 } 80 81 #endif 82