LLVM 22.0.0git
DWARFUnitIndex.h
Go to the documentation of this file.
1//===- DWARFUnitIndex.h -----------------------------------------*- C++ -*-===//
2//
3// 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
6//
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"
15#include <cstdint>
16#include <memory>
17
18namespace llvm {
19
20class raw_ostream;
21class DataExtractor;
22
23/// The enum of section identifiers to be used in internal interfaces.
24///
25/// Pre-standard implementation of package files defined a number of section
26/// identifiers with values that clash definitions in the DWARFv5 standard.
27/// See https://gcc.gnu.org/wiki/DebugFissionDWP and Section 7.3.5.3 in DWARFv5.
28///
29/// The following identifiers are the same in the proposal and in DWARFv5:
30/// - DW_SECT_INFO = 1 (.debug_info.dwo)
31/// - DW_SECT_ABBREV = 3 (.debug_abbrev.dwo)
32/// - DW_SECT_LINE = 4 (.debug_line.dwo)
33/// - DW_SECT_STR_OFFSETS = 6 (.debug_str_offsets.dwo)
34///
35/// The following identifiers are defined only in DWARFv5:
36/// - DW_SECT_LOCLISTS = 5 (.debug_loclists.dwo)
37/// - DW_SECT_RNGLISTS = 8 (.debug_rnglists.dwo)
38///
39/// The following identifiers are defined only in the GNU proposal:
40/// - DW_SECT_TYPES = 2 (.debug_types.dwo)
41/// - DW_SECT_LOC = 5 (.debug_loc.dwo)
42/// - DW_SECT_MACINFO = 7 (.debug_macinfo.dwo)
43///
44/// DW_SECT_MACRO for the .debug_macro.dwo section is defined in both standards,
45/// but with different values, 8 in GNU and 7 in DWARFv5.
46///
47/// This enum defines constants to represent the identifiers of both sets.
48/// For DWARFv5 ones, the values are the same as defined in the standard.
49/// For pre-standard ones that correspond to sections being deprecated in
50/// DWARFv5, the values are chosen arbitrary and a tag "_EXT_" is added to
51/// the names.
52///
53/// The enum is for internal use only. The user should not expect the values
54/// to correspond to any input/output constants. Special conversion functions,
55/// serializeSectionKind() and deserializeSectionKind(), should be used for
56/// the translation.
58 /// Denotes a value read from an index section that does not correspond
59 /// to any of the supported standards.
61#define HANDLE_DW_SECT(ID, NAME) DW_SECT_##NAME = ID,
62#include "llvm/BinaryFormat/Dwarf.def"
66};
67
68inline const char *toString(DWARFSectionKind Kind) {
69 switch (Kind) {
71 return "Unknown DW_SECT value 0";
72#define STRINGIZE(X) #X
73#define HANDLE_DW_SECT(ID, NAME) \
74 case DW_SECT_##NAME: \
75 return "DW_SECT_" STRINGIZE(NAME);
76#include "llvm/BinaryFormat/Dwarf.def"
78 return "DW_SECT_TYPES";
79 case DW_SECT_EXT_LOC:
80 return "DW_SECT_LOC";
82 return "DW_SECT_MACINFO";
83 }
84 llvm_unreachable("unknown DWARFSectionKind");
85}
86
87/// Convert the internal value for a section kind to an on-disk value.
88///
89/// The conversion depends on the version of the index section.
90/// IndexVersion is expected to be either 2 for pre-standard GNU proposal
91/// or 5 for DWARFv5 package file.
93 unsigned IndexVersion);
94
95/// Convert a value read from an index section to the internal representation.
96///
97/// The conversion depends on the index section version, which is expected
98/// to be either 2 for pre-standard GNU proposal or 5 for DWARFv5 package file.
100 unsigned IndexVersion);
101
103 struct Header {
104 uint32_t Version;
105 uint32_t NumColumns;
106 uint32_t NumUnits;
107 uint32_t NumBuckets = 0;
108
109 LLVM_ABI bool parse(DataExtractor IndexData, uint64_t *OffsetPtr);
110 LLVM_ABI void dump(raw_ostream &OS) const;
111 };
112
113public:
114 class Entry {
115 public:
117 private:
118 uint64_t Offset;
119 uint64_t Length;
120
121 public:
122 SectionContribution() : Offset(0), Length(0) {}
124 : Offset(Offset), Length(Length) {}
125
126 void setOffset(uint64_t Value) { Offset = Value; }
128 uint64_t getOffset() const { return Offset; }
129 uint64_t getLength() const { return Length; }
130 uint32_t getOffset32() const { return (uint32_t)Offset; }
131 uint32_t getLength32() const { return (uint32_t)Length; }
132 };
133
134 private:
135 const DWARFUnitIndex *Index;
136 uint64_t Signature;
137 std::unique_ptr<SectionContribution[]> Contributions;
138 friend class DWARFUnitIndex;
139
140 public:
145
147 return Contributions.get();
148 }
149
150 uint64_t getSignature() const { return Signature; }
151 bool isValid() { return Index; }
152 };
153
154private:
155 struct Header Header;
156
157 DWARFSectionKind InfoColumnKind;
158 int InfoColumn = -1;
159 std::unique_ptr<DWARFSectionKind[]> ColumnKinds;
160 // This is a parallel array of section identifiers as they read from the input
161 // file. The mapping from raw values to DWARFSectionKind is not revertable in
162 // case of unknown identifiers, so we keep them here.
163 std::unique_ptr<uint32_t[]> RawSectionIds;
164 std::unique_ptr<Entry[]> Rows;
165 mutable std::vector<Entry *> OffsetLookup;
166
167 static StringRef getColumnHeader(DWARFSectionKind DS);
168
169 bool parseImpl(DataExtractor IndexData);
170
171public:
173 : InfoColumnKind(InfoColumnKind) {}
174
175 explicit operator bool() const { return Header.NumBuckets; }
176
177 LLVM_ABI bool parse(DataExtractor IndexData);
178 LLVM_ABI void dump(raw_ostream &OS) const;
179
180 uint32_t getVersion() const { return Header.Version; }
181
182 LLVM_ABI const Entry *getFromOffset(uint64_t Offset) const;
183 LLVM_ABI const Entry *getFromHash(uint64_t Offset) const;
184
186 return ArrayRef(ColumnKinds.get(), Header.NumColumns);
187 }
188
190 return ArrayRef(Rows.get(), Header.NumBuckets);
191 }
192
194 return MutableArrayRef(Rows.get(), Header.NumBuckets);
195 }
196};
197
198} // end namespace llvm
199
200#endif // LLVM_DEBUGINFO_DWARF_DWARFUNITINDEX_H
#define LLVM_ABI
Definition: Compiler.h:213
uint32_t Index
raw_pwrite_stream & OS
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
SectionContribution(uint64_t Offset, uint64_t Length)
uint64_t getSignature() const
LLVM_ABI const SectionContribution * getContribution() const
const SectionContribution * getContributions() const
uint32_t getVersion() const
MutableArrayRef< Entry > getMutableRows()
LLVM_ABI void dump(raw_ostream &OS) const
DWARFUnitIndex(DWARFSectionKind InfoColumnKind)
LLVM_ABI const Entry * getFromHash(uint64_t Offset) const
ArrayRef< DWARFSectionKind > getColumnKinds() const
ArrayRef< Entry > getRows() const
LLVM_ABI const Entry * getFromOffset(uint64_t Offset) const
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
Definition: ArrayRef.h:303
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:55
LLVM Value Representation.
Definition: Value.h:75
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
void dump(const SparseBitVector< ElementSize > &LHS, raw_ostream &out)
@ Offset
Definition: DWP.cpp:477
@ Length
Definition: DWP.cpp:477
LLVM_ABI DWARFSectionKind deserializeSectionKind(uint32_t Value, unsigned IndexVersion)
Convert a value read from an index section to the internal representation.
DWARFSectionKind
The enum of section identifiers to be used in internal interfaces.
@ DW_SECT_EXT_LOC
@ DW_SECT_EXT_unknown
Denotes a value read from an index section that does not correspond to any of the supported standards...
@ DW_SECT_EXT_TYPES
@ DW_SECT_EXT_MACINFO
LLVM_ABI uint32_t serializeSectionKind(DWARFSectionKind Kind, unsigned IndexVersion)
Convert the internal value for a section kind to an on-disk value.
const char * toString(DWARFSectionKind Kind)
Definition: regcomp.c:186