llvm.org GIT mirror llvm / 4138b67
Revert "[ObjectYAML] Support for DWARF debug_info section" This reverts commit r290204. Still breaking bots... In a meeting now, so I can't fix it immediately. Bot URL: http://lab.llvm.org:8011/builders/clang-s390x-linux/builds/2415 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@290209 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Bieneman 2 years ago
11 changed file(s) with 8 addition(s) and 857 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;
8684 /// Get the fixed byte size for a given form.
8785 ///
8886 /// 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"
1413 #include "llvm/ADT/STLExtras.h"
1514 #include "llvm/DebugInfo/DWARF/DWARFDebugAbbrev.h"
1615 #include "llvm/DebugInfo/DWARF/DWARFDebugInfoEntry.h"
127126 uint64_t BaseAddr;
128127 // The compile unit debug information entry items.
129128 std::vector DieArray;
130 typedef iterator_range::iterator>
131 die_iterator_range;
132129
133130 class DWOHolder {
134131 object::OwningBinary DWOFile;
290287 return 0;
291288 }
292289
293 die_iterator_range dies() {
294 extractDIEsIfNeeded(false);
295 return die_iterator_range(DieArray.begin(), DieArray.end());
296 }
297
298290 private:
299291 /// Size in bytes of the .debug_info data associated with this compile unit.
300292 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
8768 struct Data {
8869 std::vector AbbrevDecls;
8970 std::vector DebugStrings;
9374
9475 PubSection GNUPubNames;
9576 PubSection GNUPubTypes;
96
97 std::vector CompileUnits;
9877
9978 bool isEmpty() const;
10079 };
10281 } // namespace llvm::DWARFYAML
10382 } // namespace llvm
10483
105 LLVM_YAML_IS_SEQUENCE_VECTOR(uint8_t)
10684 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::StringRef)
107 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::yaml::Hex8)
10885 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::AttributeAbbrev)
10986 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::Abbrev)
11087 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::ARangeDescriptor)
11188 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::ARange)
11289 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::PubEntry)
113 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::Unit)
114 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::FormValue)
115 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::Entry)
11690
11791 namespace llvm {
11892 namespace yaml {
143117
144118 template <> struct MappingTraits {
145119 static void mapping(IO &IO, DWARFYAML::PubSection &Section);
146 };
147
148 template <> struct MappingTraits {
149 static void mapping(IO &IO, DWARFYAML::Unit &Unit);
150 };
151
152 template <> struct MappingTraits {
153 static void mapping(IO &IO, DWARFYAML::Entry &Entry);
154 };
155
156 template <> struct MappingTraits {
157 static void mapping(IO &IO, DWARFYAML::FormValue &FormValue);
158120 };
159121
160122 #define HANDLE_DW_TAG(unused, name) \
137137
138138 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::MachOYAML::LoadCommand)
139139 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::MachOYAML::Section)
140 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::yaml::Hex8)
140141 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::yaml::Hex64)
141142 LLVM_YAML_IS_SEQUENCE_VECTOR(int64_t)
142143 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(IO &IO, DWARFYAML::Data &DWARF) {
25 auto oldContext = IO.getContext();
26 IO.setContext(&DWARF);
24 void MappingTraits::mapping(
25 IO &IO, DWARFYAML::Data &DWARF) {
2726 IO.mapOptional("debug_str", DWARF.DebugStrings);
2827 IO.mapOptional("debug_abbrev", DWARF.AbbrevDecls);
2928 if(!DWARF.ARanges.empty() || !IO.outputting())
3635 IO.mapOptional("debug_gnu_pubnames", DWARF.GNUPubNames);
3736 if(!DWARF.GNUPubTypes.Entries.empty() || !IO.outputting())
3837 IO.mapOptional("debug_gnu_pubtypes", DWARF.GNUPubTypes);
39 IO.mapOptional("debug_info", DWARF.CompileUnits);
40 IO.setContext(&oldContext);
4138 }
4239
43 void MappingTraits::mapping(IO &IO,
44 DWARFYAML::Abbrev &Abbrev) {
40 void MappingTraits::mapping(
41 IO &IO, DWARFYAML::Abbrev &Abbrev) {
4542 IO.mapRequired("Code", Abbrev.Code);
4643 IO.mapRequired("Tag", Abbrev.Tag);
4744 IO.mapRequired("Children", Abbrev.Children);
9289 IO.setContext(OldContext);
9390 }
9491
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
11792 } // namespace llvm::yaml
11893
11994 } // namespace llvm
+0
-525
test/ObjectYAML/MachO/DWARF-debug_info.yaml less more
None # 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"
1312 #include "llvm/ObjectYAML/DWARFYAML.h"
14
15 #include
1613
1714 using namespace llvm;
1815
10198 dumpPubSection(DCtx, Y.GNUPubTypes, DCtx.getGnuPubTypesSection());
10299 }
103100
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) {
101 std::error_code dwarf2yaml(DWARFContextInMemory &DCtx,
102 DWARFYAML::Data &Y) {
214103 dumpDebugAbbrev(DCtx, Y);
215104 dumpDebugStrings(DCtx, Y);
216105 dumpDebugARanges(DCtx, Y);
217106 dumpDebugPubSections(DCtx, Y);
218 dumpDebugInfo(DCtx, Y);
107
219108 return obj2yaml_error::success;
220109 }
1515 #include "llvm/Support/Error.h"
1616 #include "llvm/Support/LEB128.h"
1717 #include "llvm/Support/raw_ostream.h"
18
19 #include
2018
2119 using namespace llvm;
2220
8179 OS.write('\0');
8280 }
8381 }
84
85 void yaml2debug_info(raw_ostream &OS, const DWARFYAML::Data &DI) {
86
87 for (auto CU : DI.CompileUnits) {
88 OS.write(reinterpret_cast(&CU.Length), 4);
89 OS.write(reinterpret_cast(&CU.Version), 2);
90 OS.write(reinterpret_cast(&CU.AbbrOffset), 4);
91 OS.write(reinterpret_cast(&CU.AddrSize), 1);
92
93 auto FirstAbbrevCode = CU.Entries[0].AbbrCode;
94
95 for (auto Entry : CU.Entries) {
96 encodeULEB128(Entry.AbbrCode, OS);
97 if(Entry.AbbrCode == 0u)
98 continue;
99 bool Indirect = false;
100 assert(Entry.AbbrCode-FirstAbbrevCode < DI.AbbrevDecls.size() &&
101 "Out of range AbbCode");
102 auto &Abbrev = DI.AbbrevDecls[Entry.AbbrCode-FirstAbbrevCode];
103
104 auto FormVal = Entry.Values.begin();
105 auto AbbrForm = Abbrev.Attributes.begin();
106 for (;
107 FormVal != Entry.Values.end() && AbbrForm != Abbrev.Attributes.end();
108 ++FormVal, ++AbbrForm) {
109 dwarf::Form Form = AbbrForm->Form;
110 do {
111 bool Indirect = false;
112 switch (Form) {
113 case dwarf::DW_FORM_addr:
114 OS.write(reinterpret_cast(&FormVal->Value), CU.AddrSize);
115 break;
116 case dwarf::DW_FORM_ref_addr: {
117 // TODO: Handle DWARF32/DWARF64 after Line Table data is done
118 auto writeSize = CU.Version == 2 ? CU.AddrSize : 4;
119 OS.write(reinterpret_cast(&FormVal->Value), writeSize);
120 break;
121 }
122 case dwarf::DW_FORM_exprloc:
123 case dwarf::DW_FORM_block:
124 encodeULEB128(FormVal->BlockData.size(), OS);
125 OS.write(reinterpret_cast(&FormVal->BlockData[0]),
126 FormVal->BlockData.size());
127 break;
128 case dwarf::DW_FORM_block1: {
129 auto writeSize = FormVal->BlockData.size();
130 OS.write(reinterpret_cast(&writeSize), 1);
131 OS.write(reinterpret_cast(&FormVal->BlockData[0]),
132 FormVal->BlockData.size());
133 break;
134 }
135 case dwarf::DW_FORM_block2: {
136 auto writeSize = FormVal->BlockData.size();
137 OS.write(reinterpret_cast(&writeSize), 2);
138 OS.write(reinterpret_cast(&FormVal->BlockData[0]),
139 FormVal->BlockData.size());
140 break;
141 }
142 case dwarf::DW_FORM_block4: {
143 auto writeSize = FormVal->BlockData.size();
144 OS.write(reinterpret_cast(&writeSize), 4);
145 OS.write(reinterpret_cast(&FormVal->BlockData[0]),
146 FormVal->BlockData.size());
147 break;
148 }
149 case dwarf::DW_FORM_data1:
150 case dwarf::DW_FORM_ref1:
151 case dwarf::DW_FORM_flag:
152 OS.write(reinterpret_cast(&FormVal->Value), 1);
153 break;
154 case dwarf::DW_FORM_data2:
155 case dwarf::DW_FORM_ref2:
156 OS.write(reinterpret_cast(&FormVal->Value), 2);
157 break;
158 case dwarf::DW_FORM_data4:
159 case dwarf::DW_FORM_ref4:
160 OS.write(reinterpret_cast(&FormVal->Value), 4);
161 break;
162 case dwarf::DW_FORM_data8:
163 case dwarf::DW_FORM_ref8:
164 OS.write(reinterpret_cast(&FormVal->Value), 8);
165 break;
166 case dwarf::DW_FORM_sdata:
167 encodeSLEB128(FormVal->Value, OS);
168 break;
169 case dwarf::DW_FORM_udata:
170 case dwarf::DW_FORM_ref_udata:
171 encodeULEB128(FormVal->Value, OS);
172 break;
173 case dwarf::DW_FORM_string:
174 OS.write(FormVal->CStr.data(), FormVal->CStr.size());
175 OS.write('\0');
176 break;
177 case dwarf::DW_FORM_indirect:
178 encodeULEB128(FormVal->Value, OS);
179 Indirect = true;
180 Form = static_cast((uint64_t)FormVal->Value);
181 ++FormVal;
182 break;
183 case dwarf::DW_FORM_strp:
184 case dwarf::DW_FORM_sec_offset:
185 case dwarf::DW_FORM_GNU_ref_alt:
186 case dwarf::DW_FORM_GNU_strp_alt:
187 case dwarf::DW_FORM_line_strp:
188 case dwarf::DW_FORM_strp_sup:
189 case dwarf::DW_FORM_ref_sup:
190 // TODO: Handle DWARF32/64
191 OS.write(reinterpret_cast(&FormVal->Value), 4);
192 break;
193 case dwarf::DW_FORM_ref_sig8:
194 OS.write(reinterpret_cast(&FormVal->Value), 8);
195 break;
196 case dwarf::DW_FORM_GNU_addr_index:
197 case dwarf::DW_FORM_GNU_str_index:
198 encodeULEB128(FormVal->Value, OS);
199 break;
200 default:
201 break;
202 }
203 } while (Indirect);
204 }
205 }
206 }
207 }
397397 yaml2pubsection(OS, Obj.DWARF.PubNames);
398398 } else if (0 == strncmp(&Section.sectname[0], "__debug_pubtypes", 16)) {
399399 yaml2pubsection(OS, Obj.DWARF.PubTypes);
400 } else if (0 == strncmp(&Section.sectname[0], "__debug_info", 16)) {
401 yaml2debug_info(OS, Obj.DWARF);
402400 }
403401 }
404402 return Error::success();
4545 void yaml2debug_aranges(llvm::raw_ostream &OS, const llvm::DWARFYAML::Data &DI);
4646 void yaml2pubsection(llvm::raw_ostream &OS,
4747 const llvm::DWARFYAML::PubSection &Sect);
48 void yaml2debug_info(llvm::raw_ostream &OS, const llvm::DWARFYAML::Data &DI);
4948
5049 #endif