llvm.org GIT mirror llvm / 7d46645
[ObjectYAML] Support for DWARF debug_info section This patch adds support for YAML<->DWARF for debug_info sections. This re-lands r290147, reverted in 290148, re-landed in r290204 after fixing the issue that caused bots to fail (thank you UBSan!), and reverted again in r290209 due to failures on big endian systems. After adding support for preserving endianness, this should be good now. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@290386 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Bieneman 2 years ago
11 changed file(s) with 860 addition(s) and 9 deletion(s). Raw diff Collapse all Expand all
8181 Optional getAsAddress() const;
8282 Optional getAsSectionOffset() const;
8383 Optional> getAsBlock() const;
84 Optional getAsCStringOffset() const;
85 Optional getAsReferenceUVal() const;
8486 /// Get the fixed byte size for a given form.
8587 ///
8688 /// If the form always has a fixed valid byte size that doesn't depend on a
1010 #define LLVM_LIB_DEBUGINFO_DWARFUNIT_H
1111
1212 #include "llvm/ADT/Optional.h"
13 #include "llvm/ADT/iterator_range.h"
1314 #include "llvm/ADT/STLExtras.h"
1415 #include "llvm/DebugInfo/DWARF/DWARFDebugAbbrev.h"
1516 #include "llvm/DebugInfo/DWARF/DWARFDebugInfoEntry.h"
126127 uint64_t BaseAddr;
127128 // The compile unit debug information entry items.
128129 std::vector DieArray;
130 typedef iterator_range::iterator>
131 die_iterator_range;
129132
130133 class DWOHolder {
131134 object::OwningBinary DWOFile;
292295 return 0;
293296 }
294297
298 die_iterator_range dies() {
299 extractDIEsIfNeeded(false);
300 return die_iterator_range(DieArray.begin(), DieArray.end());
301 }
302
295303 private:
296304 /// Size in bytes of the .debug_info data associated with this compile unit.
297305 size_t getDebugInfoSize() const { return Length + 4 - getHeaderSize(); }
6565 std::vector Entries;
6666 };
6767
68 struct FormValue {
69 llvm::yaml::Hex64 Value;
70 StringRef CStr;
71 std::vector BlockData;
72 };
73
74 struct Entry {
75 llvm::yaml::Hex32 AbbrCode;
76 std::vector Values;
77 };
78
79 struct Unit {
80 uint32_t Length;
81 uint16_t Version;
82 uint32_t AbbrOffset;
83 uint8_t AddrSize;
84 std::vector Entries;
85 };
86
6887 struct Data {
6988 bool IsLittleEndian;
7089 std::vector AbbrevDecls;
7594
7695 PubSection GNUPubNames;
7796 PubSection GNUPubTypes;
97
98 std::vector CompileUnits;
7899
79100 bool isEmpty() const;
80101 };
82103 } // namespace llvm::DWARFYAML
83104 } // namespace llvm
84105
106 LLVM_YAML_IS_SEQUENCE_VECTOR(uint8_t)
85107 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::StringRef)
108 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::yaml::Hex8)
86109 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::AttributeAbbrev)
87110 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::Abbrev)
88111 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::ARangeDescriptor)
89112 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::ARange)
90113 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::PubEntry)
114 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::Unit)
115 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::FormValue)
116 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::Entry)
91117
92118 namespace llvm {
93119 namespace yaml {
118144
119145 template <> struct MappingTraits {
120146 static void mapping(IO &IO, DWARFYAML::PubSection &Section);
147 };
148
149 template <> struct MappingTraits {
150 static void mapping(IO &IO, DWARFYAML::Unit &Unit);
151 };
152
153 template <> struct MappingTraits {
154 static void mapping(IO &IO, DWARFYAML::Entry &Entry);
155 };
156
157 template <> struct MappingTraits {
158 static void mapping(IO &IO, DWARFYAML::FormValue &FormValue);
121159 };
122160
123161 #define HANDLE_DW_TAG(unused, name) \
138138
139139 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::MachOYAML::LoadCommand)
140140 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::MachOYAML::Section)
141 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::yaml::Hex8)
142141 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::yaml::Hex64)
143142 LLVM_YAML_IS_SEQUENCE_VECTOR(int64_t)
144143 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::MachOYAML::RebaseOpcode)
660660 return makeArrayRef(Value.data, Value.uval);
661661 }
662662
663 Optional DWARFFormValue::getAsCStringOffset() const {
664 if (!isFormClass(FC_String) && Form == DW_FORM_string)
665 return None;
666 return Value.uval;
667 }
668
669 Optional DWARFFormValue::getAsReferenceUVal() const {
670 if (!isFormClass(FC_Reference))
671 return None;
672 return Value.uval;
673 }
674
2121
2222 namespace yaml {
2323
24 void MappingTraits::mapping(
25 IO &IO, DWARFYAML::Data &DWARF) {
24 void MappingTraits::mapping(IO &IO, DWARFYAML::Data &DWARF) {
25 auto oldContext = IO.getContext();
26 IO.setContext(&DWARF);
2627 IO.mapOptional("debug_str", DWARF.DebugStrings);
2728 IO.mapOptional("debug_abbrev", DWARF.AbbrevDecls);
2829 if(!DWARF.ARanges.empty() || !IO.outputting())
3536 IO.mapOptional("debug_gnu_pubnames", DWARF.GNUPubNames);
3637 if(!DWARF.GNUPubTypes.Entries.empty() || !IO.outputting())
3738 IO.mapOptional("debug_gnu_pubtypes", DWARF.GNUPubTypes);
39 IO.mapOptional("debug_info", DWARF.CompileUnits);
40 IO.setContext(&oldContext);
3841 }
3942
40 void MappingTraits::mapping(
41 IO &IO, DWARFYAML::Abbrev &Abbrev) {
43 void MappingTraits::mapping(IO &IO,
44 DWARFYAML::Abbrev &Abbrev) {
4245 IO.mapRequired("Code", Abbrev.Code);
4346 IO.mapRequired("Tag", Abbrev.Tag);
4447 IO.mapRequired("Children", Abbrev.Children);
8992 IO.setContext(OldContext);
9093 }
9194
95 void MappingTraits::mapping(IO &IO, DWARFYAML::Unit &Unit) {
96 IO.mapRequired("Length", Unit.Length);
97 IO.mapRequired("Version", Unit.Version);
98 IO.mapRequired("AbbrOffset", Unit.AbbrOffset);
99 IO.mapRequired("AddrSize", Unit.AddrSize);
100 IO.mapOptional("Entries", Unit.Entries);
101 }
102
103 void MappingTraits::mapping(IO &IO, DWARFYAML::Entry &Entry) {
104 IO.mapRequired("AbbrCode", Entry.AbbrCode);
105 IO.mapRequired("Values", Entry.Values);
106 }
107
108 void MappingTraits::mapping(IO &IO,
109 DWARFYAML::FormValue &FormValue) {
110 IO.mapOptional("Value", FormValue.Value);
111 if(!FormValue.CStr.empty() || !IO.outputting())
112 IO.mapOptional("CStr", FormValue.CStr);
113 if(!FormValue.BlockData.empty() || !IO.outputting())
114 IO.mapOptional("BlockData", FormValue.BlockData);
115 }
116
92117 } // namespace llvm::yaml
93118
94119 } // namespace llvm
0 # RUN: yaml2obj %s | obj2yaml | FileCheck %s
1
2 --- !mach-o
3 FileHeader:
4 magic: 0xFEEDFACF
5 cputype: 0x01000007
6 cpusubtype: 0x00000003
7 filetype: 0x0000000A
8 ncmds: 5
9 sizeofcmds: 1800
10 flags: 0x00000000
11 reserved: 0x00000000
12 LoadCommands:
13 - cmd: LC_SEGMENT_64
14 cmdsize: 72
15 segname: __PAGEZERO
16 vmaddr: 0
17 vmsize: 4294967296
18 fileoff: 0
19 filesize: 0
20 maxprot: 0
21 initprot: 0
22 nsects: 0
23 flags: 0
24 - cmd: LC_SEGMENT_64
25 cmdsize: 472
26 segname: __TEXT
27 vmaddr: 4294967296
28 vmsize: 4096
29 fileoff: 0
30 filesize: 0
31 maxprot: 7
32 initprot: 5
33 nsects: 5
34 flags: 0
35 Sections:
36 - sectname: __text
37 segname: __TEXT
38 addr: 0x0000000100000F50
39 size: 52
40 offset: 0x00000000
41 align: 4
42 reloff: 0x00000000
43 nreloc: 0
44 flags: 0x80000400
45 reserved1: 0x00000000
46 reserved2: 0x00000000
47 reserved3: 0x00000000
48 - sectname: __stubs
49 segname: __TEXT
50 addr: 0x0000000100000F84
51 size: 6
52 offset: 0x00000000
53 align: 1
54 reloff: 0x00000000
55 nreloc: 0
56 flags: 0x80000408
57 reserved1: 0x00000000
58 reserved2: 0x00000006
59 reserved3: 0x00000000
60 - sectname: __stub_helper
61 segname: __TEXT
62 addr: 0x0000000100000F8C
63 size: 26
64 offset: 0x00000000
65 align: 2
66 reloff: 0x00000000
67 nreloc: 0
68 flags: 0x80000400
69 reserved1: 0x00000000
70 reserved2: 0x00000000
71 reserved3: 0x00000000
72 - sectname: __cstring
73 segname: __TEXT
74 addr: 0x0000000100000FA6
75 size: 14
76 offset: 0x00000000
77 align: 0
78 reloff: 0x00000000
79 nreloc: 0
80 flags: 0x00000002
81 reserved1: 0x00000000
82 reserved2: 0x00000000
83 reserved3: 0x00000000
84 - sectname: __unwind_info
85 segname: __TEXT
86 addr: 0x0000000100000FB4
87 size: 72
88 offset: 0x00000000
89 align: 2
90 reloff: 0x00000000
91 nreloc: 0
92 flags: 0x00000000
93 reserved1: 0x00000000
94 reserved2: 0x00000000
95 reserved3: 0x00000000
96 - cmd: LC_SEGMENT_64
97 cmdsize: 232
98 segname: __DATA
99 vmaddr: 4294971392
100 vmsize: 4096
101 fileoff: 0
102 filesize: 0
103 maxprot: 7
104 initprot: 3
105 nsects: 2
106 flags: 0
107 Sections:
108 - sectname: __nl_symbol_ptr
109 segname: __DATA
110 addr: 0x0000000100001000
111 size: 16
112 offset: 0x00000000
113 align: 3
114 reloff: 0x00000000
115 nreloc: 0
116 flags: 0x00000006
117 reserved1: 0x00000001
118 reserved2: 0x00000000
119 reserved3: 0x00000000
120 - sectname: __la_symbol_ptr
121 segname: __DATA
122 addr: 0x0000000100001010
123 size: 8
124 offset: 0x00000000
125 align: 3
126 reloff: 0x00000000
127 nreloc: 0
128 flags: 0x00000007
129 reserved1: 0x00000003
130 reserved2: 0x00000000
131 reserved3: 0x00000000
132 - cmd: LC_SEGMENT_64
133 cmdsize: 72
134 segname: __LINKEDIT
135 vmaddr: 4294975488
136 vmsize: 4096
137 fileoff: 4096
138 filesize: 60
139 maxprot: 7
140 initprot: 1
141 nsects: 0
142 flags: 0
143 - cmd: LC_SEGMENT_64
144 cmdsize: 952
145 segname: __DWARF
146 vmaddr: 4294979584
147 vmsize: 4096
148 fileoff: 8192
149 filesize: 764
150 maxprot: 7
151 initprot: 3
152 nsects: 11
153 flags: 0
154 Sections:
155 - sectname: __debug_line
156 segname: __DWARF
157 addr: 0x0000000100003000
158 size: 69
159 offset: 0x00002000
160 align: 0
161 reloff: 0x00000000
162 nreloc: 0
163 flags: 0x00000000
164 reserved1: 0x00000000
165 reserved2: 0x00000000
166 reserved3: 0x00000000
167 - sectname: __debug_pubnames
168 segname: __DWARF
169 addr: 0x0000000100003045
170 size: 27
171 offset: 0x00002045
172 align: 0
173 reloff: 0x00000000
174 nreloc: 0
175 flags: 0x00000000
176 reserved1: 0x00000000
177 reserved2: 0x00000000
178 reserved3: 0x00000000
179 - sectname: __debug_pubtypes
180 segname: __DWARF
181 addr: 0x0000000100003060
182 size: 35
183 offset: 0x00002060
184 align: 0
185 reloff: 0x00000000
186 nreloc: 0
187 flags: 0x00000000
188 reserved1: 0x00000000
189 reserved2: 0x00000000
190 reserved3: 0x00000000
191 - sectname: __debug_aranges
192 segname: __DWARF
193 addr: 0x0000000100003083
194 size: 48
195 offset: 0x00002083
196 align: 0
197 reloff: 0x00000000
198 nreloc: 0
199 flags: 0x00000000
200 reserved1: 0x00000000
201 reserved2: 0x00000000
202 reserved3: 0x00000000
203 - sectname: __debug_info
204 segname: __DWARF
205 addr: 0x00000001000030B3
206 size: 121
207 offset: 0x000020B3
208 align: 0
209 reloff: 0x00000000
210 nreloc: 0
211 flags: 0x00000000
212 reserved1: 0x00000000
213 reserved2: 0x00000000
214 reserved3: 0x00000000
215 - sectname: __debug_abbrev
216 segname: __DWARF
217 addr: 0x000000010000312C
218 size: 76
219 offset: 0x0000212C
220 align: 0
221 reloff: 0x00000000
222 nreloc: 0
223 flags: 0x00000000
224 reserved1: 0x00000000
225 reserved2: 0x00000000
226 reserved3: 0x00000000
227 - sectname: __debug_str
228 segname: __DWARF
229 addr: 0x0000000100003178
230 size: 142
231 offset: 0x00002178
232 align: 0
233 reloff: 0x00000000
234 nreloc: 0
235 flags: 0x00000000
236 reserved1: 0x00000000
237 reserved2: 0x00000000
238 reserved3: 0x00000000
239 - sectname: __apple_names
240 segname: __DWARF
241 addr: 0x0000000100003206
242 size: 60
243 offset: 0x00002206
244 align: 0
245 reloff: 0x00000000
246 nreloc: 0
247 flags: 0x00000000
248 reserved1: 0x00000000
249 reserved2: 0x00000000
250 reserved3: 0x00000000
251 - sectname: __apple_namespac
252 segname: __DWARF
253 addr: 0x0000000100003242
254 size: 36
255 offset: 0x00002242
256 align: 0
257 reloff: 0x00000000
258 nreloc: 0
259 flags: 0x00000000
260 reserved1: 0x00000000
261 reserved2: 0x00000000
262 reserved3: 0x00000000
263 - sectname: __apple_types
264 segname: __DWARF
265 addr: 0x0000000100003266
266 size: 114
267 offset: 0x00002266
268 align: 0
269 reloff: 0x00000000
270 nreloc: 0
271 flags: 0x00000000
272 reserved1: 0x00000000
273 reserved2: 0x00000000
274 reserved3: 0x00000000
275 - sectname: __apple_objc
276 segname: __DWARF
277 addr: 0x00000001000032D8
278 size: 36
279 offset: 0x000022D8
280 align: 0
281 reloff: 0x00000000
282 nreloc: 0
283 flags: 0x00000000
284 reserved1: 0x00000000
285 reserved2: 0x00000000
286 reserved3: 0x00000000
287 LinkEditData:
288 NameList:
289 - n_strx: 2
290 n_type: 0x0F
291 n_sect: 1
292 n_desc: 16
293 n_value: 4294967296
294 - n_strx: 22
295 n_type: 0x0F
296 n_sect: 1
297 n_desc: 0
298 n_value: 4294971216
299 StringTable:
300 - ''
301 - ''
302 - __mh_execute_header
303 - _main
304 DWARF:
305 debug_abbrev:
306 - Code: 0x00000001
307 Tag: DW_TAG_compile_unit
308 Children: DW_CHILDREN_yes
309 Attributes:
310 - Attribute: DW_AT_producer
311 Form: DW_FORM_strp
312 - Attribute: DW_AT_language
313 Form: DW_FORM_data2
314 - Attribute: DW_AT_name
315 Form: DW_FORM_strp
316 - Attribute: DW_AT_stmt_list
317 Form: DW_FORM_sec_offset
318 - Attribute: DW_AT_comp_dir
319 Form: DW_FORM_strp
320 - Attribute: DW_AT_low_pc
321 Form: DW_FORM_addr
322 - Attribute: DW_AT_high_pc
323 Form: DW_FORM_data4
324 - Code: 0x00000002
325 Tag: DW_TAG_subprogram
326 Children: DW_CHILDREN_yes
327 Attributes:
328 - Attribute: DW_AT_low_pc
329 Form: DW_FORM_addr
330 - Attribute: DW_AT_high_pc
331 Form: DW_FORM_data4
332 - Attribute: DW_AT_frame_base
333 Form: DW_FORM_exprloc
334 - Attribute: DW_AT_name
335 Form: DW_FORM_strp
336 - Attribute: DW_AT_decl_file
337 Form: DW_FORM_data1
338 - Attribute: DW_AT_decl_line
339 Form: DW_FORM_data1
340 - Attribute: DW_AT_prototyped
341 Form: DW_FORM_flag_present
342 - Attribute: DW_AT_type
343 Form: DW_FORM_ref4
344 - Attribute: DW_AT_external
345 Form: DW_FORM_flag_present
346 - Code: 0x00000003
347 Tag: DW_TAG_formal_parameter
348 Children: DW_CHILDREN_no
349 Attributes:
350 - Attribute: DW_AT_location
351 Form: DW_FORM_exprloc
352 - Attribute: DW_AT_name
353 Form: DW_FORM_strp
354 - Attribute: DW_AT_decl_file
355 Form: DW_FORM_data1
356 - Attribute: DW_AT_decl_line
357 Form: DW_FORM_data1
358 - Attribute: DW_AT_type
359 Form: DW_FORM_ref4
360 - Code: 0x00000004
361 Tag: DW_TAG_base_type
362 Children: DW_CHILDREN_no
363 Attributes:
364 - Attribute: DW_AT_name
365 Form: DW_FORM_strp
366 - Attribute: DW_AT_encoding
367 Form: DW_FORM_data1
368 - Attribute: DW_AT_byte_size
369 Form: DW_FORM_data1
370 - Code: 0x00000005
371 Tag: DW_TAG_pointer_type
372 Children: DW_CHILDREN_no
373 Attributes:
374 - Attribute: DW_AT_type
375 Form: DW_FORM_ref4
376 debug_aranges:
377 - Length: 44
378 Version: 2
379 CuOffset: 0
380 AddrSize: 8
381 SegSize: 0
382 Descriptors:
383 - Address: 0x0000000100000F50
384 Length: 52
385 debug_info:
386 - Length: 117
387 Version: 4
388 AbbrOffset: 0
389 AddrSize: 8
390 Entries:
391 - AbbrCode: 0x00000001
392 Values:
393 - Value: 0x0000000000000001
394 - Value: 0x000000000000000C
395 - Value: 0x0000000000000038
396 - Value: 0x0000000000000000
397 - Value: 0x0000000000000046
398 - Value: 0x0000000100000F50
399 - Value: 0x0000000000000034
400 - AbbrCode: 0x00000002
401 Values:
402 - Value: 0x0000000100000F50
403 - Value: 0x0000000000000034
404 - Value: 0x0000000000000001
405 BlockData:
406 - 0x56
407 - Value: 0x0000000000000076
408 - Value: 0x0000000000000001
409 - Value: 0x0000000000000003
410 - Value: 0x0000000000000001
411 - Value: 0x0000000000000060
412 - Value: 0x0000000000000001
413 - AbbrCode: 0x00000003
414 Values:
415 - Value: 0x0000000000000002
416 BlockData:
417 - 0x91
418 - 0x78
419 - Value: 0x000000000000007B
420 - Value: 0x0000000000000001
421 - Value: 0x0000000000000003
422 - Value: 0x0000000000000060
423 - AbbrCode: 0x00000003
424 Values:
425 - Value: 0x0000000000000002
426 BlockData:
427 - 0x91
428 - 0x70
429 - Value: 0x0000000000000080
430 - Value: 0x0000000000000001
431 - Value: 0x0000000000000003
432 - Value: 0x0000000000000067
433 - AbbrCode: 0x00000000
434 Values:
435 - AbbrCode: 0x00000004
436 Values:
437 - Value: 0x0000000000000085
438 - Value: 0x0000000000000005
439 - Value: 0x0000000000000004
440 - AbbrCode: 0x00000005
441 Values:
442 - Value: 0x000000000000006C
443 - AbbrCode: 0x00000005
444 Values:
445 - Value: 0x0000000000000071
446 - AbbrCode: 0x00000004
447 Values:
448 - Value: 0x0000000000000089
449 - Value: 0x0000000000000006
450 - Value: 0x0000000000000001
451 - AbbrCode: 0x00000000
452 Values:
453 ...
454
455
456 #CHECK: DWARF:
457 #CHECK: debug_info:
458 #CHECK: - Length: 117
459 #CHECK: Version: 4
460 #CHECK: AbbrOffset: 0
461 #CHECK: AddrSize: 8
462 #CHECK: Entries:
463 #CHECK: - AbbrCode: 0x00000001
464 #CHECK: Values:
465 #CHECK: - Value: 0x0000000000000001
466 #CHECK: - Value: 0x000000000000000C
467 #CHECK: - Value: 0x0000000000000038
468 #CHECK: - Value: 0x0000000000000000
469 #CHECK: - Value: 0x0000000000000046
470 #CHECK: - Value: 0x0000000100000F50
471 #CHECK: - Value: 0x0000000000000034
472 #CHECK: - AbbrCode: 0x00000002
473 #CHECK: Values:
474 #CHECK: - Value: 0x0000000100000F50
475 #CHECK: - Value: 0x0000000000000034
476 #CHECK: - Value: 0x0000000000000001
477 #CHECK: BlockData:
478 #CHECK: - 0x56
479 #CHECK: - Value: 0x0000000000000076
480 #CHECK: - Value: 0x0000000000000001
481 #CHECK: - Value: 0x0000000000000003
482 #CHECK: - Value: 0x0000000000000001
483 #CHECK: - Value: 0x0000000000000060
484 #CHECK: - Value: 0x0000000000000001
485 #CHECK: - AbbrCode: 0x00000003
486 #CHECK: Values:
487 #CHECK: - Value: 0x0000000000000002
488 #CHECK: BlockData:
489 #CHECK: - 0x91
490 #CHECK: - 0x78
491 #CHECK: - Value: 0x000000000000007B
492 #CHECK: - Value: 0x0000000000000001
493 #CHECK: - Value: 0x0000000000000003
494 #CHECK: - Value: 0x0000000000000060
495 #CHECK: - AbbrCode: 0x00000003
496 #CHECK: Values:
497 #CHECK: - Value: 0x0000000000000002
498 #CHECK: BlockData:
499 #CHECK: - 0x91
500 #CHECK: - 0x70
501 #CHECK: - Value: 0x0000000000000080
502 #CHECK: - Value: 0x0000000000000001
503 #CHECK: - Value: 0x0000000000000003
504 #CHECK: - Value: 0x0000000000000067
505 #CHECK: - AbbrCode: 0x00000000
506 #CHECK: Values:
507 #CHECK: - AbbrCode: 0x00000004
508 #CHECK: Values:
509 #CHECK: - Value: 0x0000000000000085
510 #CHECK: - Value: 0x0000000000000005
511 #CHECK: - Value: 0x0000000000000004
512 #CHECK: - AbbrCode: 0x00000005
513 #CHECK: Values:
514 #CHECK: - Value: 0x000000000000006C
515 #CHECK: - AbbrCode: 0x00000005
516 #CHECK: Values:
517 #CHECK: - Value: 0x0000000000000071
518 #CHECK: - AbbrCode: 0x00000004
519 #CHECK: Values:
520 #CHECK: - Value: 0x0000000000000089
521 #CHECK: - Value: 0x0000000000000006
522 #CHECK: - Value: 0x0000000000000001
523 #CHECK: - AbbrCode: 0x00000000
524 #CHECK: Values:
99 #include "Error.h"
1010 #include "llvm/DebugInfo/DWARF/DWARFContext.h"
1111 #include "llvm/DebugInfo/DWARF/DWARFDebugArangeSet.h"
12 #include "llvm/DebugInfo/DWARF/DWARFFormValue.h"
1213 #include "llvm/ObjectYAML/DWARFYAML.h"
14
15 #include
1316
1417 using namespace llvm;
1518
98101 dumpPubSection(DCtx, Y.GNUPubTypes, DCtx.getGnuPubTypesSection());
99102 }
100103
101 std::error_code dwarf2yaml(DWARFContextInMemory &DCtx,
102 DWARFYAML::Data &Y) {
104 void dumpDebugInfo(DWARFContextInMemory &DCtx, DWARFYAML::Data &Y) {
105 for (const auto &CU : DCtx.compile_units()) {
106 DWARFYAML::Unit NewUnit;
107 NewUnit.Length = CU->getLength();
108 NewUnit.Version = CU->getVersion();
109 NewUnit.AbbrOffset = CU->getAbbreviations()->getOffset();
110 NewUnit.AddrSize = CU->getAddressByteSize();
111 for (auto DIE : CU->dies()) {
112 DWARFYAML::Entry NewEntry;
113 DataExtractor EntryData = CU->getDebugInfoExtractor();
114 uint32_t offset = DIE.getOffset();
115
116 assert(EntryData.isValidOffset(offset) && "Invalid DIE Offset");
117 if (!EntryData.isValidOffset(offset))
118 continue;
119
120 NewEntry.AbbrCode = EntryData.getULEB128(&offset);
121
122 auto AbbrevDecl = DIE.getAbbreviationDeclarationPtr();
123 if (AbbrevDecl) {
124 for (const auto &AttrSpec : AbbrevDecl->attributes()) {
125 DWARFYAML::FormValue NewValue;
126 NewValue.Value = 0xDEADBEEFDEADBEEF;
127 DWARFDie DIEWrapper(CU.get(), &DIE);
128 auto FormValue = DIEWrapper.getAttributeValue(AttrSpec.Attr);
129 if(!FormValue)
130 return;
131 auto Form = FormValue.getValue().getForm();
132 bool indirect = false;
133 do {
134 indirect = false;
135 switch (Form) {
136 case dwarf::DW_FORM_addr:
137 case dwarf::DW_FORM_GNU_addr_index:
138 if (auto Val = FormValue.getValue().getAsAddress())
139 NewValue.Value = Val.getValue();
140 break;
141 case dwarf::DW_FORM_ref_addr:
142 case dwarf::DW_FORM_ref1:
143 case dwarf::DW_FORM_ref2:
144 case dwarf::DW_FORM_ref4:
145 case dwarf::DW_FORM_ref8:
146 case dwarf::DW_FORM_ref_udata:
147 case dwarf::DW_FORM_ref_sig8:
148 if (auto Val = FormValue.getValue().getAsReferenceUVal())
149 NewValue.Value = Val.getValue();
150 break;
151 case dwarf::DW_FORM_exprloc:
152 case dwarf::DW_FORM_block:
153 case dwarf::DW_FORM_block1:
154 case dwarf::DW_FORM_block2:
155 case dwarf::DW_FORM_block4:
156 if (auto Val = FormValue.getValue().getAsBlock()) {
157 auto BlockData = Val.getValue();
158 std::copy(BlockData.begin(), BlockData.end(),
159 std::back_inserter(NewValue.BlockData));
160 }
161 NewValue.Value = NewValue.BlockData.size();
162 break;
163 case dwarf::DW_FORM_data1:
164 case dwarf::DW_FORM_flag:
165 case dwarf::DW_FORM_data2:
166 case dwarf::DW_FORM_data4:
167 case dwarf::DW_FORM_data8:
168 case dwarf::DW_FORM_sdata:
169 case dwarf::DW_FORM_udata:
170 if (auto Val = FormValue.getValue().getAsUnsignedConstant())
171 NewValue.Value = Val.getValue();
172 break;
173 case dwarf::DW_FORM_string:
174 if (auto Val = FormValue.getValue().getAsCString())
175 NewValue.CStr = Val.getValue();
176 break;
177 case dwarf::DW_FORM_indirect:
178 indirect = true;
179 if (auto Val = FormValue.getValue().getAsUnsignedConstant()) {
180 NewValue.Value = Val.getValue();
181 NewEntry.Values.push_back(NewValue);
182 Form = static_cast(Val.getValue());
183 }
184 break;
185 case dwarf::DW_FORM_strp:
186 case dwarf::DW_FORM_sec_offset:
187 case dwarf::DW_FORM_GNU_ref_alt:
188 case dwarf::DW_FORM_GNU_strp_alt:
189 case dwarf::DW_FORM_line_strp:
190 case dwarf::DW_FORM_strp_sup:
191 case dwarf::DW_FORM_ref_sup:
192 case dwarf::DW_FORM_GNU_str_index:
193 if (auto Val = FormValue.getValue().getAsCStringOffset())
194 NewValue.Value = Val.getValue();
195 break;
196 case dwarf::DW_FORM_flag_present:
197 NewValue.Value = 1;
198 break;
199 default:
200 break;
201 }
202 } while (indirect);
203 NewEntry.Values.push_back(NewValue);
204 }
205 }
206
207 NewUnit.Entries.push_back(NewEntry);
208 }
209 Y.CompileUnits.push_back(NewUnit);
210 }
211 }
212
213 std::error_code dwarf2yaml(DWARFContextInMemory &DCtx, DWARFYAML::Data &Y) {
103214 dumpDebugAbbrev(DCtx, Y);
104215 dumpDebugStrings(DCtx, Y);
105216 dumpDebugARanges(DCtx, Y);
106217 dumpDebugPubSections(DCtx, Y);
107
218 dumpDebugInfo(DCtx, Y);
108219 return obj2yaml_error::success;
109220 }
1717 #include "llvm/Support/raw_ostream.h"
1818 #include "llvm/Support/SwapByteOrder.h"
1919
20 #include
21
2022 using namespace llvm;
2123
2224 template
103105 OS.write(Entry.Name.data(), Entry.Name.size());
104106 OS.write('\0');
105107 }
106 }
108 }
109
110 void yaml2debug_info(raw_ostream &OS, const DWARFYAML::Data &DI) {
111
112 for (auto CU : DI.CompileUnits) {
113 writeInteger((uint32_t)CU.Length, OS, DI.IsLittleEndian);
114 writeInteger((uint16_t)CU.Version, OS, DI.IsLittleEndian);
115 writeInteger((uint32_t)CU.AbbrOffset, OS, DI.IsLittleEndian);
116 writeInteger((uint8_t)CU.AddrSize, OS, DI.IsLittleEndian);
117
118 auto FirstAbbrevCode = CU.Entries[0].AbbrCode;
119
120 for (auto Entry : CU.Entries) {
121 encodeULEB128(Entry.AbbrCode, OS);
122 if (Entry.AbbrCode == 0u)
123 continue;
124 bool Indirect = false;
125 assert(Entry.AbbrCode - FirstAbbrevCode < DI.AbbrevDecls.size() &&
126 "Out of range AbbCode");
127 auto &Abbrev = DI.AbbrevDecls[Entry.AbbrCode - FirstAbbrevCode];
128
129 auto FormVal = Entry.Values.begin();
130 auto AbbrForm = Abbrev.Attributes.begin();
131 for (;
132 FormVal != Entry.Values.end() && AbbrForm != Abbrev.Attributes.end();
133 ++FormVal, ++AbbrForm) {
134 dwarf::Form Form = AbbrForm->Form;
135 do {
136 bool Indirect = false;
137 switch (Form) {
138 case dwarf::DW_FORM_addr:
139 writeVariableSizedInteger(FormVal->Value, CU.AddrSize, OS,
140 DI.IsLittleEndian);
141 break;
142 case dwarf::DW_FORM_ref_addr: {
143 // TODO: Handle DWARF32/DWARF64 after Line Table data is done
144 auto writeSize = CU.Version == 2 ? CU.AddrSize : 4;
145 writeVariableSizedInteger(FormVal->Value, writeSize, OS,
146 DI.IsLittleEndian);
147 break;
148 }
149 case dwarf::DW_FORM_exprloc:
150 case dwarf::DW_FORM_block:
151 encodeULEB128(FormVal->BlockData.size(), OS);
152 OS.write(reinterpret_cast(&FormVal->BlockData[0]),
153 FormVal->BlockData.size());
154 break;
155 case dwarf::DW_FORM_block1: {
156 auto writeSize = FormVal->BlockData.size();
157 writeInteger((uint8_t)writeSize, OS, DI.IsLittleEndian);
158 OS.write(reinterpret_cast(&FormVal->BlockData[0]),
159 FormVal->BlockData.size());
160 break;
161 }
162 case dwarf::DW_FORM_block2: {
163 auto writeSize = FormVal->BlockData.size();
164 writeInteger((uint16_t)writeSize, OS, DI.IsLittleEndian);
165 OS.write(reinterpret_cast(&FormVal->BlockData[0]),
166 FormVal->BlockData.size());
167 break;
168 }
169 case dwarf::DW_FORM_block4: {
170 auto writeSize = FormVal->BlockData.size();
171 writeInteger((uint32_t)writeSize, OS, DI.IsLittleEndian);
172 OS.write(reinterpret_cast(&FormVal->BlockData[0]),
173 FormVal->BlockData.size());
174 break;
175 }
176 case dwarf::DW_FORM_data1:
177 case dwarf::DW_FORM_ref1:
178 case dwarf::DW_FORM_flag:
179 writeInteger((uint8_t)FormVal->Value, OS, DI.IsLittleEndian);
180 break;
181 case dwarf::DW_FORM_data2:
182 case dwarf::DW_FORM_ref2:
183 writeInteger((uint16_t)FormVal->Value, OS, DI.IsLittleEndian);
184 break;
185 case dwarf::DW_FORM_data4:
186 case dwarf::DW_FORM_ref4:
187 writeInteger((uint32_t)FormVal->Value, OS, DI.IsLittleEndian);
188 break;
189 case dwarf::DW_FORM_data8:
190 case dwarf::DW_FORM_ref8:
191 writeInteger((uint64_t)FormVal->Value, OS, DI.IsLittleEndian);
192 break;
193 case dwarf::DW_FORM_sdata:
194 encodeSLEB128(FormVal->Value, OS);
195 break;
196 case dwarf::DW_FORM_udata:
197 case dwarf::DW_FORM_ref_udata:
198 encodeULEB128(FormVal->Value, OS);
199 break;
200 case dwarf::DW_FORM_string:
201 OS.write(FormVal->CStr.data(), FormVal->CStr.size());
202 OS.write('\0');
203 break;
204 case dwarf::DW_FORM_indirect:
205 encodeULEB128(FormVal->Value, OS);
206 Indirect = true;
207 Form = static_cast((uint64_t)FormVal->Value);
208 ++FormVal;
209 break;
210 case dwarf::DW_FORM_strp:
211 case dwarf::DW_FORM_sec_offset:
212 case dwarf::DW_FORM_GNU_ref_alt:
213 case dwarf::DW_FORM_GNU_strp_alt:
214 case dwarf::DW_FORM_line_strp:
215 case dwarf::DW_FORM_strp_sup:
216 case dwarf::DW_FORM_ref_sup:
217 // TODO: Handle DWARF32/64
218 writeInteger((uint32_t)FormVal->Value, OS, DI.IsLittleEndian);
219 break;
220 case dwarf::DW_FORM_ref_sig8:
221 writeInteger((uint64_t)FormVal->Value, OS, DI.IsLittleEndian);
222 break;
223 case dwarf::DW_FORM_GNU_addr_index:
224 case dwarf::DW_FORM_GNU_str_index:
225 encodeULEB128(FormVal->Value, OS);
226 break;
227 default:
228 break;
229 }
230 } while (Indirect);
231 }
232 }
233 }
234 }
277277 yaml2pubsection(OS, Obj.DWARF.PubNames, Obj.IsLittleEndian);
278278 } else if (0 == strncmp(&Sec.sectname[0], "__debug_pubtypes", 16)) {
279279 yaml2pubsection(OS, Obj.DWARF.PubTypes, Obj.IsLittleEndian);
280 } else if (0 == strncmp(&Sec.sectname[0], "__debug_info", 16)) {
281 yaml2debug_info(OS, Obj.DWARF);
280282 }
281283 } else {
282284 // Fills section data with 0xDEADBEEF
4444 void yaml2pubsection(llvm::raw_ostream &OS,
4545 const llvm::DWARFYAML::PubSection &Sect,
4646 bool IsLittleEndian);
47 void yaml2debug_info(llvm::raw_ostream &OS, const llvm::DWARFYAML::Data &DI);
4748
4849 #endif