LLVM: lib/DebugInfo/DWARF/DWARFDebugMacro.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
18#include
19
20using namespace llvm;
21using namespace dwarf;
22
23DwarfFormat DWARFDebugMacro::MacroHeader::getDwarfFormat() const {
25}
26
27uint8_t DWARFDebugMacro::MacroHeader::getOffsetByteSize() const {
29}
30
31void DWARFDebugMacro::MacroHeader::dumpMacroHeader(raw_ostream &OS) const {
32
33 OS << format("macro header: version = 0x%04" PRIx16, Version)
34 << format(", flags = 0x%02" PRIx8, Flags)
35 << ", format = " << FormatString(getDwarfFormat());
36 if (Flags & MACRO_DEBUG_LINE_OFFSET)
37 OS << format(", debug_line_offset = 0x%0*" PRIx64, 2 * getOffsetByteSize(),
38 DebugLineOffset);
39 OS << "\n";
40}
41
43 unsigned IndLevel = 0;
44 for (const auto &Macros : MacroLists) {
45 OS << format("0x%08" PRIx64 ":\n", Macros.Offset);
46 if (Macros.IsDebugMacro)
47 Macros.Header.dumpMacroHeader(OS);
48 for (const Entry &E : Macros.Macros) {
49
50
51 if (IndLevel > 0)
53
54 for (unsigned I = 0; I < IndLevel; I++)
55 OS << " ";
57
58 if (Macros.IsDebugMacro)
60 << (Macros.Header.Version < 5 ? GnuMacroString(E.Type)
62 else
64 switch (E.Type) {
65 default:
66
67
68 break;
69
70
71
72
73
74
75
76
77
78 case DW_MACRO_define:
79 case DW_MACRO_undef:
80 case DW_MACRO_define_strp:
81 case DW_MACRO_undef_strp:
82 case DW_MACRO_define_strx:
83 case DW_MACRO_undef_strx:
84 OS << " - lineno: " << E.Line;
85 OS << " macro: " << E.MacroStr;
86 break;
87 case DW_MACRO_start_file:
88 OS << " - lineno: " << E.Line;
89 OS << " filenum: " << E.File;
90 break;
91 case DW_MACRO_import:
92 OS << format(" - import offset: 0x%0*" PRIx64,
93 2 * Macros.Header.getOffsetByteSize(), E.ImportOffset);
94 break;
95 case DW_MACRO_end_file:
96 break;
98 OS << " - constant: " << E.ExtConstant;
99 OS << " string: " << E.ExtStr;
100 break;
101 }
102 OS << "\n";
103 }
104 }
105}
106
107Error DWARFDebugMacro::parseImpl(
108 std::optionalDWARFUnitVector::compile\_unit\_range Units,
110 bool IsMacro) {
112 MacroList *M = nullptr;
114 MacroToUnitsMap MacroToUnits;
115 if (IsMacro && Data.isValidOffset(Offset)) {
116
117
118 for (const auto &U : *Units)
119 if (auto CUDIE = U->getUnitDIE())
120
121 if (auto MacroOffset = toSectionOffset(CUDIE.find(DW_AT_macros)))
122 MacroToUnits.try_emplace(*MacroOffset, U.get());
123 }
125 if (!M) {
126 MacroLists.emplace_back();
127 M = &MacroLists.back();
129 M->IsDebugMacro = IsMacro;
130 if (IsMacro) {
131 auto Err = M->Header.parseMacroHeader(Data, &Offset);
132 if (Err)
133 return Err;
134 }
135 }
136
137 M->Macros.emplace_back();
138 Entry &E = M->Macros.back();
139
141
142 if (E.Type == 0) {
143
144 M = nullptr;
145 continue;
146 }
147
148 switch (E.Type) {
149 default:
150
151
154
155
156
157
158
159
160 case DW_MACRO_define:
161 case DW_MACRO_undef:
162
164
166 break;
167 case DW_MACRO_define_strp:
168 case DW_MACRO_undef_strp: {
169 if (!IsMacro) {
170
171
172
175 }
176 uint64_t StrOffset = 0;
177
179
180 StrOffset =
181 Data.getRelocatedValue(M->Header.getOffsetByteSize(), &Offset);
182 assert(StringExtractor && "String Extractor not found");
183 E.MacroStr = StringExtractor->getCStr(&StrOffset);
184 break;
185 }
186 case DW_MACRO_define_strx:
187 case DW_MACRO_undef_strx: {
188 if (!IsMacro) {
189
190
191
194 }
196 auto MacroContributionOffset = MacroToUnits.find(M->Offset);
197 if (MacroContributionOffset == MacroToUnits.end())
199 "Macro contribution of the unit not found");
200 Expected<uint64_t> StrOffset =
201 MacroContributionOffset->second->getStringOffsetSectionItem(
203 if (!StrOffset)
205 E.MacroStr =
206 MacroContributionOffset->second->getStringExtractor().getCStr(
207 &*StrOffset);
208 break;
209 }
210 case DW_MACRO_start_file:
211
213
215 break;
216 case DW_MACRO_end_file:
217 break;
218 case DW_MACRO_import:
219 E.ImportOffset =
220 Data.getRelocatedValue(M->Header.getOffsetByteSize(), &Offset);
221 break;
223
224 E.ExtConstant = Data.getULEB128(&Offset);
225
227 break;
228 }
229 }
231}
232
233Error DWARFDebugMacro::MacroHeader::parseMacroHeader(DWARFDataExtractor Data,
236 uint8_t FlagData = Data.getU8(Offset);
237
238
239 if (FlagData & MACRO_OPCODE_OPERANDS_TABLE)
241 "opcode_operands_table is not supported");
242 Flags = FlagData;
243 if (Flags & MACRO_DEBUG_LINE_OFFSET)
244 DebugLineOffset = Data.getUnsigned(Offset, getOffsetByteSize());
246}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This file defines the DenseMap class.
This file contains constants used for implementing Dwarf debug support.
void dump(raw_ostream &OS) const
Print the macro list found within the debug_macinfo/debug_macro section.
Definition DWARFDebugMacro.cpp:42
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
Error takeError()
Take ownership of the stored error.
An RAII object that temporarily switches an output stream to a specific color.
This class implements an extremely fast bulk output stream that can only output to a stream.
LLVM_ABI StringRef MacroString(unsigned Encoding)
LLVM_ABI StringRef FormatString(DwarfFormat Format)
LLVM_ABI StringRef GnuMacroString(unsigned Encoding)
LLVM_ABI StringRef MacinfoString(unsigned Encoding)
Calculates the starting offsets for various sections within the .debug_names section.
DwarfFormat
Constants that define the DWARF format as 32 or 64 bit.
std::optional< uint64_t > toSectionOffset(const std::optional< DWARFFormValue > &V)
Take an optional DWARFFormValue and try to extract an section offset.
uint8_t getDwarfOffsetByteSize(DwarfFormat Format)
The size of a reference determined by the DWARF 32/64-bit format.
@ DW_MACINFO_invalid
Macinfo type for invalid results.
This is an optimization pass for GlobalISel generic memory operations.
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
FunctionAddr VTableAddr uintptr_t uintptr_t Version
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
FunctionAddr VTableAddr uintptr_t uintptr_t Data