blob: fc8c707c512e50212d6721e9253e9dc8c91e3720 [file] [log] [blame]
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001//===- DWARFUnitIndex.h -----------------------------------------*- C++ -*-===//
2//
Andrew Walbran16937d02019-10-22 13:54:20 +01003// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01006//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_DEBUGINFO_DWARF_DWARFUNITINDEX_H
10#define LLVM_DEBUGINFO_DWARF_DWARFUNITINDEX_H
11
12#include "llvm/ADT/ArrayRef.h"
13#include "llvm/ADT/StringRef.h"
14#include "llvm/Support/DataExtractor.h"
15#include <cstdint>
16#include <memory>
17
18namespace llvm {
19
20class raw_ostream;
21
22enum DWARFSectionKind {
23 DW_SECT_INFO = 1,
24 DW_SECT_TYPES,
25 DW_SECT_ABBREV,
26 DW_SECT_LINE,
27 DW_SECT_LOC,
28 DW_SECT_STR_OFFSETS,
29 DW_SECT_MACINFO,
30 DW_SECT_MACRO,
31};
32
33class DWARFUnitIndex {
34 struct Header {
35 uint32_t Version;
36 uint32_t NumColumns;
37 uint32_t NumUnits;
38 uint32_t NumBuckets = 0;
39
40 bool parse(DataExtractor IndexData, uint32_t *OffsetPtr);
41 void dump(raw_ostream &OS) const;
42 };
43
44public:
45 class Entry {
46 public:
47 struct SectionContribution {
48 uint32_t Offset;
49 uint32_t Length;
50 };
51
52 private:
53 const DWARFUnitIndex *Index;
54 uint64_t Signature;
55 std::unique_ptr<SectionContribution[]> Contributions;
56 friend class DWARFUnitIndex;
57
58 public:
59 const SectionContribution *getOffset(DWARFSectionKind Sec) const;
60 const SectionContribution *getOffset() const;
61
62 const SectionContribution *getOffsets() const {
63 return Contributions.get();
64 }
65
66 uint64_t getSignature() const { return Signature; }
67 };
68
69private:
70 struct Header Header;
71
72 DWARFSectionKind InfoColumnKind;
73 int InfoColumn = -1;
74 std::unique_ptr<DWARFSectionKind[]> ColumnKinds;
75 std::unique_ptr<Entry[]> Rows;
Andrew Scull0372a572018-11-16 15:47:06 +000076 mutable std::vector<Entry *> OffsetLookup;
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010077
78 static StringRef getColumnHeader(DWARFSectionKind DS);
79
80 bool parseImpl(DataExtractor IndexData);
81
82public:
83 DWARFUnitIndex(DWARFSectionKind InfoColumnKind)
84 : InfoColumnKind(InfoColumnKind) {}
85
86 explicit operator bool() const { return Header.NumBuckets; }
87
88 bool parse(DataExtractor IndexData);
89 void dump(raw_ostream &OS) const;
90
91 const Entry *getFromOffset(uint32_t Offset) const;
92 const Entry *getFromHash(uint64_t Offset) const;
93
94 ArrayRef<DWARFSectionKind> getColumnKinds() const {
95 return makeArrayRef(ColumnKinds.get(), Header.NumColumns);
96 }
97
98 ArrayRef<Entry> getRows() const {
99 return makeArrayRef(Rows.get(), Header.NumBuckets);
100 }
101};
102
103} // end namespace llvm
104
105#endif // LLVM_DEBUGINFO_DWARF_DWARFUNITINDEX_H