llvm.org GIT mirror llvm / da6d07a
[ObjectYAML] Add support for DWARF5 Unit header In DWARF5 the Unit header added a new field, UnitType, and swapped the order of the address size and abbreviation offset fields. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@297183 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Bieneman 2 years ago
5 changed file(s) with 606 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
9999 struct Unit {
100100 InitialLength Length;
101101 uint16_t Version;
102 llvm::dwarf::UnitType Type; // Added in DWARF 5
102103 uint32_t AbbrOffset;
103104 uint8_t AddrSize;
104105 std::vector Entries;
284285 }
285286 };
286287
288 #define HANDLE_DW_UT(unused, name) \
289 io.enumCase(value, "DW_UT_" #name, dwarf::DW_UT_##name);
290
291 template <> struct ScalarEnumerationTraits {
292 static void enumeration(IO &io, dwarf::UnitType &value) {
293 #include "llvm/Support/Dwarf.def"
294 io.enumFallback(value);
295 }
296 };
297
287298 template <> struct ScalarEnumerationTraits {
288299 static void enumeration(IO &io, dwarf::Constants &value) {
289300 io.enumCase(value, "DW_CHILDREN_no", dwarf::DW_CHILDREN_no);
129129 virtual void onStartCompileUnit(const DWARFYAML::Unit &CU) {
130130 writeInitialLength(CU.Length, OS, DebugInfo.IsLittleEndian);
131131 writeInteger((uint16_t)CU.Version, OS, DebugInfo.IsLittleEndian);
132 writeInteger((uint32_t)CU.AbbrOffset, OS, DebugInfo.IsLittleEndian);
133 writeInteger((uint8_t)CU.AddrSize, OS, DebugInfo.IsLittleEndian);
132 if(CU.Version >= 5) {
133 writeInteger((uint8_t)CU.Type, OS, DebugInfo.IsLittleEndian);
134 writeInteger((uint8_t)CU.AddrSize, OS, DebugInfo.IsLittleEndian);
135 writeInteger((uint32_t)CU.AbbrOffset, OS, DebugInfo.IsLittleEndian);
136 }else {
137 writeInteger((uint32_t)CU.AbbrOffset, OS, DebugInfo.IsLittleEndian);
138 writeInteger((uint8_t)CU.AddrSize, OS, DebugInfo.IsLittleEndian);
139 }
140
134141 }
135142
136143 virtual void onStartDIE(const DWARFYAML::Unit &CU,
9898 void MappingTraits::mapping(IO &IO, DWARFYAML::Unit &Unit) {
9999 IO.mapRequired("Length", Unit.Length);
100100 IO.mapRequired("Version", Unit.Version);
101 if (Unit.Version >= 5)
102 IO.mapRequired("UnitType", Unit.Type);
101103 IO.mapRequired("AbbrOffset", Unit.AbbrOffset);
102104 IO.mapRequired("AddrSize", Unit.AddrSize);
103105 IO.mapOptional("Entries", Unit.Entries);
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: 765
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: 122
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: 0x0000212D
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: 0x00002179
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: 0x00002207
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: 0x00002243
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: 0x00002267
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: 0x000022D9
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:
378 TotalLength: 44
379 Version: 2
380 CuOffset: 0
381 AddrSize: 8
382 SegSize: 0
383 Descriptors:
384 - Address: 0x0000000100000F50
385 Length: 52
386 debug_info:
387 - Length:
388 TotalLength: 118
389 Version: 5
390 UnitType: DW_UT_compile
391 AbbrOffset: 0
392 AddrSize: 8
393 Entries:
394 - AbbrCode: 0x00000001
395 Values:
396 - Value: 0x0000000000000001
397 - Value: 0x000000000000000C
398 - Value: 0x0000000000000038
399 - Value: 0x0000000000000000
400 - Value: 0x0000000000000046
401 - Value: 0x0000000100000F50
402 - Value: 0x0000000000000034
403 - AbbrCode: 0x00000002
404 Values:
405 - Value: 0x0000000100000F50
406 - Value: 0x0000000000000034
407 - Value: 0x0000000000000001
408 BlockData:
409 - 0x56
410 - Value: 0x0000000000000076
411 - Value: 0x0000000000000001
412 - Value: 0x0000000000000003
413 - Value: 0x0000000000000001
414 - Value: 0x0000000000000060
415 - Value: 0x0000000000000001
416 - AbbrCode: 0x00000003
417 Values:
418 - Value: 0x0000000000000002
419 BlockData:
420 - 0x91
421 - 0x78
422 - Value: 0x000000000000007B
423 - Value: 0x0000000000000001
424 - Value: 0x0000000000000003
425 - Value: 0x0000000000000060
426 - AbbrCode: 0x00000003
427 Values:
428 - Value: 0x0000000000000002
429 BlockData:
430 - 0x91
431 - 0x70
432 - Value: 0x0000000000000080
433 - Value: 0x0000000000000001
434 - Value: 0x0000000000000003
435 - Value: 0x0000000000000067
436 - AbbrCode: 0x00000000
437 Values:
438 - AbbrCode: 0x00000004
439 Values:
440 - Value: 0x0000000000000085
441 - Value: 0x0000000000000005
442 - Value: 0x0000000000000004
443 - AbbrCode: 0x00000005
444 Values:
445 - Value: 0x000000000000006C
446 - AbbrCode: 0x00000005
447 Values:
448 - Value: 0x0000000000000071
449 - AbbrCode: 0x00000004
450 Values:
451 - Value: 0x0000000000000089
452 - Value: 0x0000000000000006
453 - Value: 0x0000000000000001
454 - AbbrCode: 0x00000000
455 Values:
456 debug_line:
457 - Length:
458 TotalLength: 65
459 Version: 2
460 PrologueLength: 36
461 MinInstLength: 1
462 DefaultIsStmt: 1
463 LineBase: 251
464 LineRange: 14
465 OpcodeBase: 13
466 StandardOpcodeLengths:
467 - 0
468 - 1
469 - 1
470 - 1
471 - 1
472 - 0
473 - 0
474 - 0
475 - 1
476 - 0
477 - 0
478 - 1
479 IncludeDirs:
480 Files:
481 - Name: hello_world.c
482 DirIdx: 0
483 ModTime: 0
484 Length: 0
485 Opcodes:
486 - Opcode: DW_LNS_extended_op
487 ExtLen: 9
488 SubOpcode: DW_LNE_set_address
489 Data: 4294971216
490 - Opcode: 0x14
491 Data: 4294971216
492 - Opcode: DW_LNS_set_column
493 Data: 3
494 - Opcode: DW_LNS_set_prologue_end
495 Data: 3
496 - Opcode: DW_LNS_const_add_pc
497 Data: 3
498 - Opcode: 0xBB
499 Data: 3
500 - Opcode: 0xBB
501 Data: 3
502 - Opcode: DW_LNS_advance_pc
503 Data: 11
504 - Opcode: DW_LNS_extended_op
505 ExtLen: 1
506 SubOpcode: DW_LNE_end_sequence
507 Data: 11
508 ...
509
510
511 #CHECK: DWARF:
512 #CHECK: debug_info:
513 #CHECK: - Length:
514 #CHECK: TotalLength: 118
515 #CHECK: Version: 5
516 #CHECK: UnitType: DW_UT_compile
517 #CHECK: AbbrOffset: 0
518 #CHECK: AddrSize: 8
519 #CHECK: Entries:
520 #CHECK: - AbbrCode: 0x00000001
521 #CHECK: Values:
522 #CHECK: - Value: 0x0000000000000001
523 #CHECK: - Value: 0x000000000000000C
524 #CHECK: - Value: 0x0000000000000038
525 #CHECK: - Value: 0x0000000000000000
526 #CHECK: - Value: 0x0000000000000046
527 #CHECK: - Value: 0x0000000100000F50
528 #CHECK: - Value: 0x0000000000000034
529 #CHECK: - AbbrCode: 0x00000002
530 #CHECK: Values:
531 #CHECK: - Value: 0x0000000100000F50
532 #CHECK: - Value: 0x0000000000000034
533 #CHECK: - Value: 0x0000000000000001
534 #CHECK: BlockData:
535 #CHECK: - 0x56
536 #CHECK: - Value: 0x0000000000000076
537 #CHECK: - Value: 0x0000000000000001
538 #CHECK: - Value: 0x0000000000000003
539 #CHECK: - Value: 0x0000000000000001
540 #CHECK: - Value: 0x0000000000000060
541 #CHECK: - Value: 0x0000000000000001
542 #CHECK: - AbbrCode: 0x00000003
543 #CHECK: Values:
544 #CHECK: - Value: 0x0000000000000002
545 #CHECK: BlockData:
546 #CHECK: - 0x91
547 #CHECK: - 0x78
548 #CHECK: - Value: 0x000000000000007B
549 #CHECK: - Value: 0x0000000000000001
550 #CHECK: - Value: 0x0000000000000003
551 #CHECK: - Value: 0x0000000000000060
552 #CHECK: - AbbrCode: 0x00000003
553 #CHECK: Values:
554 #CHECK: - Value: 0x0000000000000002
555 #CHECK: BlockData:
556 #CHECK: - 0x91
557 #CHECK: - 0x70
558 #CHECK: - Value: 0x0000000000000080
559 #CHECK: - Value: 0x0000000000000001
560 #CHECK: - Value: 0x0000000000000003
561 #CHECK: - Value: 0x0000000000000067
562 #CHECK: - AbbrCode: 0x00000000
563 #CHECK: Values:
564 #CHECK: - AbbrCode: 0x00000004
565 #CHECK: Values:
566 #CHECK: - Value: 0x0000000000000085
567 #CHECK: - Value: 0x0000000000000005
568 #CHECK: - Value: 0x0000000000000004
569 #CHECK: - AbbrCode: 0x00000005
570 #CHECK: Values:
571 #CHECK: - Value: 0x000000000000006C
572 #CHECK: - AbbrCode: 0x00000005
573 #CHECK: Values:
574 #CHECK: - Value: 0x0000000000000071
575 #CHECK: - AbbrCode: 0x00000004
576 #CHECK: Values:
577 #CHECK: - Value: 0x0000000000000089
578 #CHECK: - Value: 0x0000000000000006
579 #CHECK: - Value: 0x0000000000000001
580 #CHECK: - AbbrCode: 0x00000000
581 #CHECK: Values:
115115 DWARFYAML::Unit NewUnit;
116116 NewUnit.Length.setLength(CU->getLength());
117117 NewUnit.Version = CU->getVersion();
118 if(NewUnit.Version >= 5)
119 NewUnit.Type = (dwarf::UnitType)CU->getUnitType();
118120 NewUnit.AbbrOffset = CU->getAbbreviations()->getOffset();
119121 NewUnit.AddrSize = CU->getAddressByteSize();
120122 for (auto DIE : CU->dies()) {