• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/ADT/ArrayRef.h"
14 #include "llvm/Support/DataExtractor.h"
15 #include "llvm/Support/Format.h"
16 #include "llvm/Support/raw_ostream.h"
17 #include <cstdint>
18 
19 namespace llvm {
20 
21 enum DWARFSectionKind {
22   DW_SECT_INFO = 1,
23   DW_SECT_TYPES,
24   DW_SECT_ABBREV,
25   DW_SECT_LINE,
26   DW_SECT_LOC,
27   DW_SECT_STR_OFFSETS,
28   DW_SECT_MACINFO,
29   DW_SECT_MACRO,
30 };
31 
32 class DWARFUnitIndex {
33   struct Header {
34     uint32_t Version;
35     uint32_t NumColumns;
36     uint32_t NumUnits;
37     uint32_t NumBuckets = 0;
38 
39     bool parse(DataExtractor IndexData, uint32_t *OffsetPtr);
40     void dump(raw_ostream &OS) const;
41   };
42 
43 public:
44   class Entry {
45   public:
46     struct SectionContribution {
47       uint32_t Offset;
48       uint32_t Length;
49     };
50 
51   private:
52     const DWARFUnitIndex *Index;
53     uint64_t Signature;
54     std::unique_ptr<SectionContribution[]> Contributions;
55     friend class DWARFUnitIndex;
56 
57   public:
58     const SectionContribution *getOffset(DWARFSectionKind Sec) const;
59     const SectionContribution *getOffset() const;
getOffsets()60     const SectionContribution *getOffsets() const {
61       return Contributions.get();
62     }
getSignature()63     uint64_t getSignature() const { return Signature; }
64   };
65 
66 private:
67   struct Header Header;
68 
69   DWARFSectionKind InfoColumnKind;
70   int InfoColumn = -1;
71   std::unique_ptr<DWARFSectionKind[]> ColumnKinds;
72   std::unique_ptr<Entry[]> Rows;
73 
74   static StringRef getColumnHeader(DWARFSectionKind DS);
75   bool parseImpl(DataExtractor IndexData);
76 
77 public:
78   bool parse(DataExtractor IndexData);
DWARFUnitIndex(DWARFSectionKind InfoColumnKind)79   DWARFUnitIndex(DWARFSectionKind InfoColumnKind)
80       : InfoColumnKind(InfoColumnKind) {}
81   void dump(raw_ostream &OS) const;
82   const Entry *getFromOffset(uint32_t Offset) const;
getColumnKinds()83   ArrayRef<DWARFSectionKind> getColumnKinds() const {
84     return makeArrayRef(ColumnKinds.get(), Header.NumColumns);
85   }
getRows()86   ArrayRef<Entry> getRows() const {
87     return makeArrayRef(Rows.get(), Header.NumBuckets);
88   }
89 };
90 }
91 
92 #endif
93