dwarfdump: Use the index to find the right abbrev offset in DWP files
[oota-llvm.git] / include / llvm / DebugInfo / DWARF / DWARFUnitIndex.h
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;
37
38     bool parse(DataExtractor IndexData, uint32_t *OffsetPtr);
39     void dump(raw_ostream &OS) const;
40   };
41
42 public:
43   class Entry {
44     const DWARFUnitIndex *Index;
45     uint64_t Signature;
46     struct SectionContribution {
47       uint32_t Offset;
48       uint32_t Length;
49     };
50     std::unique_ptr<SectionContribution[]> Contributions;
51     friend class DWARFUnitIndex;
52
53   public:
54     const SectionContribution *getOffset(DWARFSectionKind Sec) const;
55     const SectionContribution *getOffset() const;
56   };
57
58   struct Header Header;
59
60   int InfoColumn = -1;
61   std::unique_ptr<DWARFSectionKind[]> ColumnKinds;
62   std::unique_ptr<Entry[]> Rows;
63
64   static StringRef getColumnHeader(DWARFSectionKind DS);
65
66 public:
67   bool parse(DataExtractor IndexData);
68   void dump(raw_ostream &OS) const;
69   const Entry *getFromOffset(uint32_t Offset) const;
70 };
71 }
72
73 #endif