llvm.org GIT mirror llvm / ad76c97
[ObjectYAML] [DWARF] Abstract DWARF Initial Length values In the DWARF 4 Spec section 7.2.2, data in many DWARF sections, and some DWARF structures start with "Initial Length Values", which are a 32-bit length, and an optional 64-bit length if the 32 bit value == UINT32_MAX. This patch abstracts the Initial Length type in YAML, and extends its use to all the DWARF structures that are supported in the DWARFYAML code that have Initial Length values. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@296911 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Bieneman 2 years ago
9 changed file(s) with 98 addition(s) and 49 deletion(s). Raw diff Collapse all Expand all
1212 ///
1313 //===----------------------------------------------------------------------===//
1414
15
1615 #ifndef LLVM_OBJECTYAML_DWARFYAML_H
1716 #define LLVM_OBJECTYAML_DWARFYAML_H
1817
2120
2221 namespace llvm {
2322 namespace DWARFYAML {
23
24 struct InitialLength {
25 uint32_t TotalLength;
26 uint64_t TotalLength64;
27
28 bool isDWARF64() const { return TotalLength == UINT32_MAX; }
29
30 uint64_t getLength() const {
31 return isDWARF64() ? TotalLength64 : TotalLength;
32 }
33
34 void setLength(uint64_t Len) {
35 if (Len >= (uint64_t)UINT32_MAX) {
36 TotalLength64 = Len;
37 TotalLength = UINT32_MAX;
38 } else {
39 TotalLength = Len;
40 }
41 }
42 };
2443
2544 struct AttributeAbbrev {
2645 llvm::dwarf::Attribute Attribute;
4059 };
4160
4261 struct ARange {
43 uint32_t Length;
62 InitialLength Length;
4463 uint16_t Version;
4564 uint32_t CuOffset;
4665 uint8_t AddrSize;
5776 struct PubSection {
5877 PubSection() : IsGNUStyle(false) {}
5978
60 uint32_t Length;
79 InitialLength Length;
6180 uint16_t Version;
6281 uint32_t UnitOffset;
6382 uint32_t UnitSize;
7796 };
7897
7998 struct Unit {
80 uint32_t Length;
99 InitialLength Length;
81100 uint16_t Version;
82101 uint32_t AbbrOffset;
83102 uint8_t AddrSize;
103122 };
104123
105124 struct LineTable {
106 uint32_t TotalLength;
107 uint64_t TotalLength64;
125 InitialLength Length;
108126 uint16_t Version;
109127 uint64_t PrologueLength;
110128 uint8_t MinInstLength;
129147
130148 PubSection GNUPubNames;
131149 PubSection GNUPubTypes;
132
150
133151 std::vector CompileUnits;
134152
135153 std::vector DebugLines;
202220 template <> struct MappingTraits {
203221 static void mapping(IO &IO, DWARFYAML::File &File);
204222 };
205
223
206224 template <> struct MappingTraits {
207225 static void mapping(IO &IO, DWARFYAML::LineTableOpcode &LineTableOpcode);
208226 };
209227
210228 template <> struct MappingTraits {
211229 static void mapping(IO &IO, DWARFYAML::LineTable &LineTable);
230 };
231
232 template <> struct MappingTraits {
233 static void mapping(IO &IO, DWARFYAML::InitialLength &DWARF);
212234 };
213235
214236 #define HANDLE_DW_TAG(unused, name) \
4949 OS.write(reinterpret_cast(FillData.data()), Size);
5050 }
5151
52 void writeInitialLength(const DWARFYAML::InitialLength &Length, raw_ostream &OS,
53 bool IsLittleEndian) {
54 writeInteger((uint32_t)Length.TotalLength, OS, IsLittleEndian);
55 if (Length.isDWARF64())
56 writeInteger((uint64_t)Length.TotalLength64, OS, IsLittleEndian);
57 }
58
5259 void DWARFYAML::EmitDebugStr(raw_ostream &OS, const DWARFYAML::Data &DI) {
5360 for (auto Str : DI.DebugStrings) {
5461 OS.write(Str.data(), Str.size());
7380 void DWARFYAML::EmitDebugAranges(raw_ostream &OS, const DWARFYAML::Data &DI) {
7481 for (auto Range : DI.ARanges) {
7582 auto HeaderStart = OS.tell();
76 writeInteger((uint32_t)Range.Length, OS, DI.IsLittleEndian);
83 writeInitialLength(Range.Length, OS, DI.IsLittleEndian);
7784 writeInteger((uint16_t)Range.Version, OS, DI.IsLittleEndian);
7885 writeInteger((uint32_t)Range.CuOffset, OS, DI.IsLittleEndian);
7986 writeInteger((uint8_t)Range.AddrSize, OS, DI.IsLittleEndian);
96103 void DWARFYAML::EmitPubSection(raw_ostream &OS,
97104 const DWARFYAML::PubSection &Sect,
98105 bool IsLittleEndian) {
99 writeInteger((uint32_t)Sect.Length, OS, IsLittleEndian);
106 writeInitialLength(Sect.Length, OS, IsLittleEndian);
100107 writeInteger((uint16_t)Sect.Version, OS, IsLittleEndian);
101108 writeInteger((uint32_t)Sect.UnitOffset, OS, IsLittleEndian);
102109 writeInteger((uint32_t)Sect.UnitSize, OS, IsLittleEndian);
112119 void DWARFYAML::EmitDebugInfo(raw_ostream &OS, const DWARFYAML::Data &DI) {
113120
114121 for (auto CU : DI.CompileUnits) {
115 writeInteger((uint32_t)CU.Length, OS, DI.IsLittleEndian);
122 writeInitialLength(CU.Length, OS, DI.IsLittleEndian);
116123 writeInteger((uint16_t)CU.Version, OS, DI.IsLittleEndian);
117124 writeInteger((uint32_t)CU.AbbrOffset, OS, DI.IsLittleEndian);
118125 writeInteger((uint8_t)CU.AddrSize, OS, DI.IsLittleEndian);
245252
246253 void DWARFYAML::EmitDebugLine(raw_ostream &OS, const DWARFYAML::Data &DI) {
247254 for (const auto &LineTable : DI.DebugLines) {
248 writeInteger((uint32_t)LineTable.TotalLength, OS, DI.IsLittleEndian);
249 uint64_t SizeOfPrologueLength = 4;
250 if (LineTable.TotalLength == UINT32_MAX) {
251 writeInteger((uint64_t)LineTable.TotalLength64, OS, DI.IsLittleEndian);
252 SizeOfPrologueLength = 8;
253 }
255 writeInitialLength(LineTable.Length, OS, DI.IsLittleEndian);
256 uint64_t SizeOfPrologueLength = LineTable.Length.isDWARF64() ? 8 : 4;
254257 writeInteger((uint16_t)LineTable.Version, OS, DI.IsLittleEndian);
255258 writeVariableSizedInteger(LineTable.PrologueLength, SizeOfPrologueLength,
256259 OS, DI.IsLittleEndian);
143143
144144 void MappingTraits::mapping(
145145 IO &IO, DWARFYAML::LineTable &LineTable) {
146 IO.mapRequired("TotalLength", LineTable.TotalLength);
147 if (LineTable.TotalLength == UINT32_MAX)
148 IO.mapRequired("TotalLength64", LineTable.TotalLength64);
146 IO.mapRequired("Length", LineTable.Length);
149147 IO.mapRequired("Version", LineTable.Version);
150148 IO.mapRequired("PrologueLength", LineTable.PrologueLength);
151149 IO.mapRequired("MinInstLength", LineTable.MinInstLength);
161159 IO.mapRequired("Opcodes", LineTable.Opcodes);
162160 }
163161
162 void MappingTraits::mapping(
163 IO &IO, DWARFYAML::InitialLength &InitialLength) {
164 IO.mapRequired("TotalLength", InitialLength.TotalLength);
165 if (InitialLength.isDWARF64())
166 IO.mapRequired("TotalLength64", InitialLength.TotalLength64);
167 }
168
164169 } // namespace llvm::yaml
165170
166171 } // namespace llvm
312312 - _main
313313 DWARF:
314314 debug_aranges:
315 - Length: 44
315 - Length:
316 TotalLength: 44
316317 Version: 2
317318 CuOffset: 0
318319 AddrSize: 8
324325
325326 #CHECK: DWARF:
326327 #CHECK: debug_aranges:
327 #CHECK: - Length: 44
328 #CHECK: - Length:
329 #CHECK: TotalLength: 44
328330 #CHECK: Version: 2
329331 #CHECK: CuOffset: 0
330332 #CHECK: AddrSize: 8
374374 - Attribute: DW_AT_type
375375 Form: DW_FORM_ref4
376376 debug_aranges:
377 - Length: 44
377 - Length:
378 TotalLength: 44
378379 Version: 2
379380 CuOffset: 0
380381 AddrSize: 8
383384 - Address: 0x0000000100000F50
384385 Length: 52
385386 debug_info:
386 - Length: 117
387 - Length:
388 TotalLength: 117
387389 Version: 4
388390 AbbrOffset: 0
389391 AddrSize: 8
451453 - AbbrCode: 0x00000000
452454 Values:
453455 debug_line:
454 - TotalLength: 65
456 - Length:
457 TotalLength: 65
455458 Version: 2
456459 PrologueLength: 36
457460 MinInstLength: 1
507510
508511 #CHECK: DWARF:
509512 #CHECK: debug_info:
510 #CHECK: - Length: 117
513 #CHECK: - Length:
514 #CHECK: TotalLength: 117
511515 #CHECK: Version: 4
512516 #CHECK: AbbrOffset: 0
513517 #CHECK: AddrSize: 8
393393 - Attribute: DW_AT_type
394394 Form: DW_FORM_ref4
395395 debug_aranges:
396 - Length: 44
396 - Length:
397 TotalLength: 44
397398 Version: 2
398399 CuOffset: 0
399400 AddrSize: 8
402403 - Address: 0x0000000100000F50
403404 Length: 52
404405 debug_pubnames:
405 Length: 23
406 Length:
407 TotalLength: 23
406408 Version: 2
407409 UnitOffset: 0
408410 UnitSize: 121
410412 - DieOffset: 0x0000002A
411413 Name: main
412414 debug_pubtypes:
413 Length: 31
415 Length:
416 TotalLength: 31
414417 Version: 2
415418 UnitOffset: 0
416419 UnitSize: 121
420423 - DieOffset: 0x00000071
421424 Name: char
422425 debug_info:
423 - Length: 117
426 - Length:
427 TotalLength: 117
424428 Version: 4
425429 AbbrOffset: 0
426430 AddrSize: 8
488492 - AbbrCode: 0x00000000
489493 Values:
490494 debug_line:
491 - TotalLength: 65
495 - Length:
496 TotalLength: 65
492497 Version: 2
493498 PrologueLength: 36
494499 MinInstLength: 1
541546 ...
542547
543548 #CHECK: debug_line:
544 #CHECK: - TotalLength: 65
549 #CHECK: - Length:
550 #CHECK: TotalLength: 65
545551 #CHECK: Version: 2
546552 #CHECK: PrologueLength: 36
547553 #CHECK: MinInstLength: 1
313313 - int
314314 - char
315315 debug_pubnames:
316 Length: 23
316 Length:
317 TotalLength: 23
317318 Version: 2
318319 UnitOffset: 0
319320 UnitSize: 121
321322 - DieOffset: 0x0000002A
322323 Name: main
323324 debug_pubtypes:
324 Length: 31
325 Length:
326 TotalLength: 31
325327 Version: 2
326328 UnitOffset: 0
327329 UnitSize: 121
334336
335337 #CHECK: DWARF:
336338 #CHECK: debug_pubnames:
337 #CHECK: Length: 23
339 #CHECK: Length:
340 #CHECK: TotalLength: 23
338341 #CHECK: Version: 2
339342 #CHECK: UnitOffset: 0
340343 #CHECK: UnitSize: 121
342345 #CHECK: - DieOffset: 0x0000002A
343346 #CHECK: Name: main
344347 #CHECK: debug_pubtypes:
345 #CHECK: Length: 31
348 #CHECK: Length:
349 #CHECK: TotalLength: 31
346350 #CHECK: Version: 2
347351 #CHECK: UnitOffset: 0
348352 #CHECK: UnitSize: 121
1515 #include
1616
1717 using namespace llvm;
18
19 void dumpInitialLength(DataExtractor &Data, uint32_t &Offset,
20 DWARFYAML::InitialLength &InitialLength) {
21 InitialLength.TotalLength = Data.getU32(&Offset);
22 if (InitialLength.isDWARF64())
23 InitialLength.TotalLength64 = Data.getU64(&Offset);
24 }
1825
1926 void dumpDebugAbbrev(DWARFContextInMemory &DCtx, DWARFYAML::Data &Y) {
2027 auto AbbrevSetPtr = DCtx.getDebugAbbrev();
5461
5562 while (Set.extract(ArangesData, &Offset)) {
5663 DWARFYAML::ARange Range;
57 Range.Length = Set.getHeader().Length;
64 Range.Length.setLength(Set.getHeader().Length);
5865 Range.Version = Set.getHeader().Version;
5966 Range.CuOffset = Set.getHeader().CuOffset;
6067 Range.AddrSize = Set.getHeader().AddrSize;
7380 StringRef Section) {
7481 DataExtractor PubSectionData(Section, DCtx.isLittleEndian(), 0);
7582 uint32_t Offset = 0;
76 Y.Length = PubSectionData.getU32(&Offset);
83 dumpInitialLength(PubSectionData, Offset, Y.Length);
7784 Y.Version = PubSectionData.getU16(&Offset);
7885 Y.UnitOffset = PubSectionData.getU32(&Offset);
7986 Y.UnitSize = PubSectionData.getU32(&Offset);
80 while (Offset < Y.Length) {
87 while (Offset < Y.Length.getLength()) {
8188 DWARFYAML::PubEntry NewEntry;
8289 NewEntry.DieOffset = PubSectionData.getU32(&Offset);
8390 if (Y.IsGNUStyle)
104111 void dumpDebugInfo(DWARFContextInMemory &DCtx, DWARFYAML::Data &Y) {
105112 for (const auto &CU : DCtx.compile_units()) {
106113 DWARFYAML::Unit NewUnit;
107 NewUnit.Length = CU->getLength();
114 NewUnit.Length.setLength(CU->getLength());
108115 NewUnit.Version = CU->getVersion();
109116 NewUnit.AbbrOffset = CU->getAbbreviations()->getOffset();
110117 NewUnit.AddrSize = CU->getAddressByteSize();
232239 DataExtractor LineData(DCtx.getLineSection().Data, DCtx.isLittleEndian(),
233240 CU->getAddressByteSize());
234241 uint32_t Offset = *StmtOffset;
235 uint64_t SizeOfPrologueLength = 4;
236 DebugLines.TotalLength = LineData.getU32(&Offset);
237 uint64_t LineTableLength = DebugLines.TotalLength;
238 if (DebugLines.TotalLength == UINT32_MAX) {
239 DebugLines.TotalLength64 = LineData.getU64(&Offset);
240 LineTableLength = DebugLines.TotalLength64;
241 SizeOfPrologueLength = 8;
242 }
242 dumpInitialLength(LineData, Offset, DebugLines.Length);
243 uint64_t LineTableLength = DebugLines.Length.getLength();
244 uint64_t SizeOfPrologueLength = DebugLines.Length.isDWARF64() ? 8 : 4;
243245 DebugLines.Version = LineData.getU16(&Offset);
244246 DebugLines.PrologueLength =
245247 LineData.getUnsigned(&Offset, SizeOfPrologueLength);
11711171 " Children: DW_CHILDREN_yes\n"
11721172 " Attributes:\n"
11731173 "debug_info:\n"
1174 " - Length: 9\n"
1174 " - Length:\n"
1175 " TotalLength: 9\n"
11751176 " Version: 4\n"
11761177 " AbbrOffset: 0\n"
11771178 " AddrSize: 8\n"