llvm.org GIT mirror llvm / b7b948c
[ObjectYAML] Support for DWARF line tables This patch adds support for the DWARF debug_lines section. The line table state machine opcodes are preserved, so this can be used to test the state machine evaluation directly. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@291470 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Bieneman 2 years ago
9 changed file(s) with 1004 addition(s) and 12 deletion(s). Raw diff Collapse all Expand all
8484 std::vector Entries;
8585 };
8686
87 struct File {
88 StringRef Name;
89 uint64_t DirIdx;
90 uint64_t ModTime;
91 uint64_t Length;
92 };
93
94 struct LineTableOpcode {
95 dwarf::LineNumberOps Opcode;
96 uint64_t ExtLen;
97 dwarf::LineNumberExtendedOps SubOpcode;
98 uint64_t Data;
99 int64_t SData;
100 File FileEntry;
101 std::vector UnknownOpcodeData;
102 std::vector StandardOpcodeData;
103 };
104
105 struct LineTable {
106 uint32_t TotalLength;
107 uint64_t TotalLength64;
108 uint16_t Version;
109 uint64_t PrologueLength;
110 uint8_t MinInstLength;
111 uint8_t MaxOpsPerInst;
112 uint8_t DefaultIsStmt;
113 uint8_t LineBase;
114 uint8_t LineRange;
115 uint8_t OpcodeBase;
116 std::vector StandardOpcodeLengths;
117 std::vector IncludeDirs;
118 std::vector Files;
119 std::vector Opcodes;
120 };
121
87122 struct Data {
88123 bool IsLittleEndian;
89124 std::vector AbbrevDecls;
97132
98133 std::vector CompileUnits;
99134
135 std::vector DebugLines;
136
100137 bool isEmpty() const;
101138 };
102139
104141 } // namespace llvm
105142
106143 LLVM_YAML_IS_SEQUENCE_VECTOR(uint8_t)
144 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::yaml::Hex64)
107145 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::StringRef)
108146 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::yaml::Hex8)
109147 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::AttributeAbbrev)
114152 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::Unit)
115153 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::FormValue)
116154 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::Entry)
155 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::File)
156 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::LineTable)
157 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::LineTableOpcode)
117158
118159 namespace llvm {
119160 namespace yaml {
158199 static void mapping(IO &IO, DWARFYAML::FormValue &FormValue);
159200 };
160201
202 template <> struct MappingTraits {
203 static void mapping(IO &IO, DWARFYAML::File &File);
204 };
205
206 template <> struct MappingTraits {
207 static void mapping(IO &IO, DWARFYAML::LineTableOpcode &LineTableOpcode);
208 };
209
210 template <> struct MappingTraits {
211 static void mapping(IO &IO, DWARFYAML::LineTable &LineTable);
212 };
213
161214 #define HANDLE_DW_TAG(unused, name) \
162215 io.enumCase(value, "DW_TAG_" #name, dwarf::DW_TAG_##name);
163216
164217 template <> struct ScalarEnumerationTraits {
165218 static void enumeration(IO &io, dwarf::Tag &value) {
219 #include "llvm/Support/Dwarf.def"
220 io.enumFallback(value);
221 }
222 };
223
224 #define HANDLE_DW_LNS(unused, name) \
225 io.enumCase(value, "DW_LNS_" #name, dwarf::DW_LNS_##name);
226
227 template <> struct ScalarEnumerationTraits {
228 static void enumeration(IO &io, dwarf::LineNumberOps &value) {
229 #include "llvm/Support/Dwarf.def"
230 io.enumFallback(value);
231 }
232 };
233
234 #define HANDLE_DW_LNE(unused, name) \
235 io.enumCase(value, "DW_LNE_" #name, dwarf::DW_LNE_##name);
236
237 template <> struct ScalarEnumerationTraits {
238 static void enumeration(IO &io, dwarf::LineNumberExtendedOps &value) {
166239 #include "llvm/Support/Dwarf.def"
167240 io.enumFallback(value);
168241 }
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::Hex64)
142141 LLVM_YAML_IS_SEQUENCE_VECTOR(int64_t)
143142 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::MachOYAML::RebaseOpcode)
144143 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::MachOYAML::BindOpcode)
2626 IO.setContext(&DWARF);
2727 IO.mapOptional("debug_str", DWARF.DebugStrings);
2828 IO.mapOptional("debug_abbrev", DWARF.AbbrevDecls);
29 if(!DWARF.ARanges.empty() || !IO.outputting())
29 if (!DWARF.ARanges.empty() || !IO.outputting())
3030 IO.mapOptional("debug_aranges", DWARF.ARanges);
31 if(!DWARF.PubNames.Entries.empty() || !IO.outputting())
31 if (!DWARF.PubNames.Entries.empty() || !IO.outputting())
3232 IO.mapOptional("debug_pubnames", DWARF.PubNames);
33 if(!DWARF.PubTypes.Entries.empty() || !IO.outputting())
33 if (!DWARF.PubTypes.Entries.empty() || !IO.outputting())
3434 IO.mapOptional("debug_pubtypes", DWARF.PubTypes);
35 if(!DWARF.GNUPubNames.Entries.empty() || !IO.outputting())
35 if (!DWARF.GNUPubNames.Entries.empty() || !IO.outputting())
3636 IO.mapOptional("debug_gnu_pubnames", DWARF.GNUPubNames);
37 if(!DWARF.GNUPubTypes.Entries.empty() || !IO.outputting())
37 if (!DWARF.GNUPubTypes.Entries.empty() || !IO.outputting())
3838 IO.mapOptional("debug_gnu_pubtypes", DWARF.GNUPubTypes);
3939 IO.mapOptional("debug_info", DWARF.CompileUnits);
40 IO.mapOptional("debug_line", DWARF.DebugLines);
4041 IO.setContext(&oldContext);
4142 }
4243
6162 }
6263
6364 void MappingTraits::mapping(IO &IO,
64 DWARFYAML::ARange &Range) {
65 DWARFYAML::ARange &Range) {
6566 IO.mapRequired("Length", Range.Length);
6667 IO.mapRequired("Version", Range.Version);
6768 IO.mapRequired("CuOffset", Range.CuOffset);
105106 IO.mapRequired("Values", Entry.Values);
106107 }
107108
108 void MappingTraits::mapping(IO &IO,
109 DWARFYAML::FormValue &FormValue) {
109 void MappingTraits::mapping(
110 IO &IO, DWARFYAML::FormValue &FormValue) {
110111 IO.mapOptional("Value", FormValue.Value);
111 if(!FormValue.CStr.empty() || !IO.outputting())
112 if (!FormValue.CStr.empty() || !IO.outputting())
112113 IO.mapOptional("CStr", FormValue.CStr);
113 if(!FormValue.BlockData.empty() || !IO.outputting())
114 if (!FormValue.BlockData.empty() || !IO.outputting())
114115 IO.mapOptional("BlockData", FormValue.BlockData);
116 }
117
118 void MappingTraits::mapping(IO &IO, DWARFYAML::File &File) {
119 IO.mapRequired("Name", File.Name);
120 IO.mapRequired("DirIdx", File.DirIdx);
121 IO.mapRequired("ModTime", File.ModTime);
122 IO.mapRequired("Length", File.Length);
123 }
124
125 void MappingTraits::mapping(
126 IO &IO, DWARFYAML::LineTableOpcode &LineTableOpcode) {
127 IO.mapRequired("Opcode", LineTableOpcode.Opcode);
128 if (LineTableOpcode.Opcode == 0) {
129 IO.mapRequired("ExtLen", LineTableOpcode.ExtLen);
130 IO.mapRequired("SubOpcode", LineTableOpcode.SubOpcode);
131 }
132
133 if (!LineTableOpcode.UnknownOpcodeData.empty() || !IO.outputting())
134 IO.mapOptional("UnknownOpcodeData", LineTableOpcode.UnknownOpcodeData);
135 if (!LineTableOpcode.UnknownOpcodeData.empty() || !IO.outputting())
136 IO.mapOptional("StandardOpcodeData", LineTableOpcode.StandardOpcodeData);
137 if (!LineTableOpcode.FileEntry.Name.empty() || !IO.outputting())
138 IO.mapOptional("FileEntry", LineTableOpcode.FileEntry);
139 if (LineTableOpcode.Opcode == dwarf::DW_LNS_advance_line || !IO.outputting())
140 IO.mapOptional("SData", LineTableOpcode.SData);
141 IO.mapOptional("Data", LineTableOpcode.Data);
142 }
143
144 void MappingTraits::mapping(
145 IO &IO, DWARFYAML::LineTable &LineTable) {
146 IO.mapRequired("TotalLength", LineTable.TotalLength);
147 if (LineTable.TotalLength == UINT32_MAX)
148 IO.mapRequired("TotalLength64", LineTable.TotalLength64);
149 IO.mapRequired("Version", LineTable.Version);
150 IO.mapRequired("PrologueLength", LineTable.PrologueLength);
151 IO.mapRequired("MinInstLength", LineTable.MinInstLength);
152 IO.mapRequired("MaxOpsPerInst", LineTable.MaxOpsPerInst);
153 IO.mapRequired("DefaultIsStmt", LineTable.DefaultIsStmt);
154 IO.mapRequired("LineBase", LineTable.LineBase);
155 IO.mapRequired("LineRange", LineTable.LineRange);
156 IO.mapRequired("OpcodeBase", LineTable.OpcodeBase);
157 IO.mapRequired("StandardOpcodeLengths", LineTable.StandardOpcodeLengths);
158 IO.mapRequired("IncludeDirs", LineTable.IncludeDirs);
159 IO.mapRequired("Files", LineTable.Files);
160 IO.mapRequired("Opcodes", LineTable.Opcodes);
115161 }
116162
117163 } // namespace llvm::yaml
450450 - Value: 0x0000000000000001
451451 - AbbrCode: 0x00000000
452452 Values:
453 debug_line:
454 - TotalLength: 65
455 Version: 2
456 PrologueLength: 36
457 MinInstLength: 1
458 MaxOpsPerInst: 0
459 DefaultIsStmt: 1
460 LineBase: 251
461 LineRange: 14
462 OpcodeBase: 13
463 StandardOpcodeLengths:
464 - 0
465 - 1
466 - 1
467 - 1
468 - 1
469 - 0
470 - 0
471 - 0
472 - 1
473 - 0
474 - 0
475 - 1
476 IncludeDirs:
477 Files:
478 - Name: hello_world.c
479 DirIdx: 0
480 ModTime: 0
481 Length: 0
482 Opcodes:
483 - Opcode: DW_LNS_extended_op
484 ExtLen: 9
485 SubOpcode: DW_LNE_set_address
486 Data: 4294971216
487 - Opcode: 0x0014
488 Data: 4294971216
489 - Opcode: DW_LNS_set_column
490 Data: 3
491 - Opcode: DW_LNS_set_prologue_end
492 Data: 3
493 - Opcode: DW_LNS_const_add_pc
494 Data: 3
495 - Opcode: 0x00BB
496 Data: 3
497 - Opcode: 0x00BB
498 Data: 3
499 - Opcode: DW_LNS_advance_pc
500 Data: 11
501 - Opcode: DW_LNS_extended_op
502 ExtLen: 1
503 SubOpcode: DW_LNE_end_sequence
504 Data: 11
505 ...
453506 ...
454507
455508
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: 7
9 sizeofcmds: 1848
10 flags: 0x00000000
11 reserved: 0x00000000
12 LoadCommands:
13 - cmd: LC_UUID
14 cmdsize: 24
15 uuid: B4D48511-37F4-3ED4-AFA7-1683DCE69AC4
16 - cmd: LC_SYMTAB
17 cmdsize: 24
18 symoff: 4096
19 nsyms: 2
20 stroff: 4128
21 strsize: 28
22 - cmd: LC_SEGMENT_64
23 cmdsize: 72
24 segname: __PAGEZERO
25 vmaddr: 0
26 vmsize: 4294967296
27 fileoff: 0
28 filesize: 0
29 maxprot: 0
30 initprot: 0
31 nsects: 0
32 flags: 0
33 - cmd: LC_SEGMENT_64
34 cmdsize: 472
35 segname: __TEXT
36 vmaddr: 4294967296
37 vmsize: 4096
38 fileoff: 0
39 filesize: 0
40 maxprot: 7
41 initprot: 5
42 nsects: 5
43 flags: 0
44 Sections:
45 - sectname: __text
46 segname: __TEXT
47 addr: 0x0000000100000F50
48 size: 52
49 offset: 0x00000000
50 align: 4
51 reloff: 0x00000000
52 nreloc: 0
53 flags: 0x80000400
54 reserved1: 0x00000000
55 reserved2: 0x00000000
56 reserved3: 0x00000000
57 - sectname: __stubs
58 segname: __TEXT
59 addr: 0x0000000100000F84
60 size: 6
61 offset: 0x00000000
62 align: 1
63 reloff: 0x00000000
64 nreloc: 0
65 flags: 0x80000408
66 reserved1: 0x00000000
67 reserved2: 0x00000006
68 reserved3: 0x00000000
69 - sectname: __stub_helper
70 segname: __TEXT
71 addr: 0x0000000100000F8C
72 size: 26
73 offset: 0x00000000
74 align: 2
75 reloff: 0x00000000
76 nreloc: 0
77 flags: 0x80000400
78 reserved1: 0x00000000
79 reserved2: 0x00000000
80 reserved3: 0x00000000
81 - sectname: __cstring
82 segname: __TEXT
83 addr: 0x0000000100000FA6
84 size: 14
85 offset: 0x00000000
86 align: 0
87 reloff: 0x00000000
88 nreloc: 0
89 flags: 0x00000002
90 reserved1: 0x00000000
91 reserved2: 0x00000000
92 reserved3: 0x00000000
93 - sectname: __unwind_info
94 segname: __TEXT
95 addr: 0x0000000100000FB4
96 size: 72
97 offset: 0x00000000
98 align: 2
99 reloff: 0x00000000
100 nreloc: 0
101 flags: 0x00000000
102 reserved1: 0x00000000
103 reserved2: 0x00000000
104 reserved3: 0x00000000
105 - cmd: LC_SEGMENT_64
106 cmdsize: 232
107 segname: __DATA
108 vmaddr: 4294971392
109 vmsize: 4096
110 fileoff: 0
111 filesize: 0
112 maxprot: 7
113 initprot: 3
114 nsects: 2
115 flags: 0
116 Sections:
117 - sectname: __nl_symbol_ptr
118 segname: __DATA
119 addr: 0x0000000100001000
120 size: 16
121 offset: 0x00000000
122 align: 3
123 reloff: 0x00000000
124 nreloc: 0
125 flags: 0x00000006
126 reserved1: 0x00000001
127 reserved2: 0x00000000
128 reserved3: 0x00000000
129 - sectname: __la_symbol_ptr
130 segname: __DATA
131 addr: 0x0000000100001010
132 size: 8
133 offset: 0x00000000
134 align: 3
135 reloff: 0x00000000
136 nreloc: 0
137 flags: 0x00000007
138 reserved1: 0x00000003
139 reserved2: 0x00000000
140 reserved3: 0x00000000
141 - cmd: LC_SEGMENT_64
142 cmdsize: 72
143 segname: __LINKEDIT
144 vmaddr: 4294975488
145 vmsize: 4096
146 fileoff: 4096
147 filesize: 60
148 maxprot: 7
149 initprot: 1
150 nsects: 0
151 flags: 0
152 - cmd: LC_SEGMENT_64
153 cmdsize: 952
154 segname: __DWARF
155 vmaddr: 4294979584
156 vmsize: 4096
157 fileoff: 8192
158 filesize: 764
159 maxprot: 7
160 initprot: 3
161 nsects: 11
162 flags: 0
163 Sections:
164 - sectname: __debug_line
165 segname: __DWARF
166 addr: 0x0000000100003000
167 size: 69
168 offset: 0x00002000
169 align: 0
170 reloff: 0x00000000
171 nreloc: 0
172 flags: 0x00000000
173 reserved1: 0x00000000
174 reserved2: 0x00000000
175 reserved3: 0x00000000
176 - sectname: __debug_pubnames
177 segname: __DWARF
178 addr: 0x0000000100003045
179 size: 27
180 offset: 0x00002045
181 align: 0
182 reloff: 0x00000000
183 nreloc: 0
184 flags: 0x00000000
185 reserved1: 0x00000000
186 reserved2: 0x00000000
187 reserved3: 0x00000000
188 - sectname: __debug_pubtypes
189 segname: __DWARF
190 addr: 0x0000000100003060
191 size: 35
192 offset: 0x00002060
193 align: 0
194 reloff: 0x00000000
195 nreloc: 0
196 flags: 0x00000000
197 reserved1: 0x00000000
198 reserved2: 0x00000000
199 reserved3: 0x00000000
200 - sectname: __debug_aranges
201 segname: __DWARF
202 addr: 0x0000000100003083
203 size: 48
204 offset: 0x00002083
205 align: 0
206 reloff: 0x00000000
207 nreloc: 0
208 flags: 0x00000000
209 reserved1: 0x00000000
210 reserved2: 0x00000000
211 reserved3: 0x00000000
212 - sectname: __debug_info
213 segname: __DWARF
214 addr: 0x00000001000030B3
215 size: 121
216 offset: 0x000020B3
217 align: 0
218 reloff: 0x00000000
219 nreloc: 0
220 flags: 0x00000000
221 reserved1: 0x00000000
222 reserved2: 0x00000000
223 reserved3: 0x00000000
224 - sectname: __debug_abbrev
225 segname: __DWARF
226 addr: 0x000000010000312C
227 size: 76
228 offset: 0x0000212C
229 align: 0
230 reloff: 0x00000000
231 nreloc: 0
232 flags: 0x00000000
233 reserved1: 0x00000000
234 reserved2: 0x00000000
235 reserved3: 0x00000000
236 - sectname: __debug_str
237 segname: __DWARF
238 addr: 0x0000000100003178
239 size: 142
240 offset: 0x00002178
241 align: 0
242 reloff: 0x00000000
243 nreloc: 0
244 flags: 0x00000000
245 reserved1: 0x00000000
246 reserved2: 0x00000000
247 reserved3: 0x00000000
248 - sectname: __apple_names
249 segname: __DWARF
250 addr: 0x0000000100003206
251 size: 60
252 offset: 0x00002206
253 align: 0
254 reloff: 0x00000000
255 nreloc: 0
256 flags: 0x00000000
257 reserved1: 0x00000000
258 reserved2: 0x00000000
259 reserved3: 0x00000000
260 - sectname: __apple_namespac
261 segname: __DWARF
262 addr: 0x0000000100003242
263 size: 36
264 offset: 0x00002242
265 align: 0
266 reloff: 0x00000000
267 nreloc: 0
268 flags: 0x00000000
269 reserved1: 0x00000000
270 reserved2: 0x00000000
271 reserved3: 0x00000000
272 - sectname: __apple_types
273 segname: __DWARF
274 addr: 0x0000000100003266
275 size: 114
276 offset: 0x00002266
277 align: 0
278 reloff: 0x00000000
279 nreloc: 0
280 flags: 0x00000000
281 reserved1: 0x00000000
282 reserved2: 0x00000000
283 reserved3: 0x00000000
284 - sectname: __apple_objc
285 segname: __DWARF
286 addr: 0x00000001000032D8
287 size: 36
288 offset: 0x000022D8
289 align: 0
290 reloff: 0x00000000
291 nreloc: 0
292 flags: 0x00000000
293 reserved1: 0x00000000
294 reserved2: 0x00000000
295 reserved3: 0x00000000
296 LinkEditData:
297 NameList:
298 - n_strx: 2
299 n_type: 0x0F
300 n_sect: 1
301 n_desc: 16
302 n_value: 4294967296
303 - n_strx: 22
304 n_type: 0x0F
305 n_sect: 1
306 n_desc: 0
307 n_value: 4294971216
308 StringTable:
309 - ''
310 - ''
311 - __mh_execute_header
312 - _main
313 DWARF:
314 debug_str:
315 - ''
316 - 'clang version 4.0.0 (trunk 288923) (llvm/trunk 288991)'
317 - hello_world.c
318 - /Users/cbieneman/dev/open-source/llvm-build-rel
319 - main
320 - argc
321 - argv
322 - int
323 - char
324 debug_abbrev:
325 - Code: 0x00000001
326 Tag: DW_TAG_compile_unit
327 Children: DW_CHILDREN_yes
328 Attributes:
329 - Attribute: DW_AT_producer
330 Form: DW_FORM_strp
331 - Attribute: DW_AT_language
332 Form: DW_FORM_data2
333 - Attribute: DW_AT_name
334 Form: DW_FORM_strp
335 - Attribute: DW_AT_stmt_list
336 Form: DW_FORM_sec_offset
337 - Attribute: DW_AT_comp_dir
338 Form: DW_FORM_strp
339 - Attribute: DW_AT_low_pc
340 Form: DW_FORM_addr
341 - Attribute: DW_AT_high_pc
342 Form: DW_FORM_data4
343 - Code: 0x00000002
344 Tag: DW_TAG_subprogram
345 Children: DW_CHILDREN_yes
346 Attributes:
347 - Attribute: DW_AT_low_pc
348 Form: DW_FORM_addr
349 - Attribute: DW_AT_high_pc
350 Form: DW_FORM_data4
351 - Attribute: DW_AT_frame_base
352 Form: DW_FORM_exprloc
353 - Attribute: DW_AT_name
354 Form: DW_FORM_strp
355 - Attribute: DW_AT_decl_file
356 Form: DW_FORM_data1
357 - Attribute: DW_AT_decl_line
358 Form: DW_FORM_data1
359 - Attribute: DW_AT_prototyped
360 Form: DW_FORM_flag_present
361 - Attribute: DW_AT_type
362 Form: DW_FORM_ref4
363 - Attribute: DW_AT_external
364 Form: DW_FORM_flag_present
365 - Code: 0x00000003
366 Tag: DW_TAG_formal_parameter
367 Children: DW_CHILDREN_no
368 Attributes:
369 - Attribute: DW_AT_location
370 Form: DW_FORM_exprloc
371 - Attribute: DW_AT_name
372 Form: DW_FORM_strp
373 - Attribute: DW_AT_decl_file
374 Form: DW_FORM_data1
375 - Attribute: DW_AT_decl_line
376 Form: DW_FORM_data1
377 - Attribute: DW_AT_type
378 Form: DW_FORM_ref4
379 - Code: 0x00000004
380 Tag: DW_TAG_base_type
381 Children: DW_CHILDREN_no
382 Attributes:
383 - Attribute: DW_AT_name
384 Form: DW_FORM_strp
385 - Attribute: DW_AT_encoding
386 Form: DW_FORM_data1
387 - Attribute: DW_AT_byte_size
388 Form: DW_FORM_data1
389 - Code: 0x00000005
390 Tag: DW_TAG_pointer_type
391 Children: DW_CHILDREN_no
392 Attributes:
393 - Attribute: DW_AT_type
394 Form: DW_FORM_ref4
395 debug_aranges:
396 - Length: 44
397 Version: 2
398 CuOffset: 0
399 AddrSize: 8
400 SegSize: 0
401 Descriptors:
402 - Address: 0x0000000100000F50
403 Length: 52
404 debug_pubnames:
405 Length: 23
406 Version: 2
407 UnitOffset: 0
408 UnitSize: 121
409 Entries:
410 - DieOffset: 0x0000002A
411 Name: main
412 debug_pubtypes:
413 Length: 31
414 Version: 2
415 UnitOffset: 0
416 UnitSize: 121
417 Entries:
418 - DieOffset: 0x00000060
419 Name: int
420 - DieOffset: 0x00000071
421 Name: char
422 debug_info:
423 - Length: 117
424 Version: 4
425 AbbrOffset: 0
426 AddrSize: 8
427 Entries:
428 - AbbrCode: 0x00000001
429 Values:
430 - Value: 0x0000000000000001
431 - Value: 0x000000000000000C
432 - Value: 0x0000000000000038
433 - Value: 0x0000000000000000
434 - Value: 0x0000000000000046
435 - Value: 0x0000000100000F50
436 - Value: 0x0000000000000034
437 - AbbrCode: 0x00000002
438 Values:
439 - Value: 0x0000000100000F50
440 - Value: 0x0000000000000034
441 - Value: 0x0000000000000001
442 BlockData:
443 - 0x56
444 - Value: 0x0000000000000076
445 - Value: 0x0000000000000001
446 - Value: 0x0000000000000003
447 - Value: 0x0000000000000001
448 - Value: 0x0000000000000060
449 - Value: 0x0000000000000001
450 - AbbrCode: 0x00000003
451 Values:
452 - Value: 0x0000000000000002
453 BlockData:
454 - 0x91
455 - 0x78
456 - Value: 0x000000000000007B
457 - Value: 0x0000000000000001
458 - Value: 0x0000000000000003
459 - Value: 0x0000000000000060
460 - AbbrCode: 0x00000003
461 Values:
462 - Value: 0x0000000000000002
463 BlockData:
464 - 0x91
465 - 0x70
466 - Value: 0x0000000000000080
467 - Value: 0x0000000000000001
468 - Value: 0x0000000000000003
469 - Value: 0x0000000000000067
470 - AbbrCode: 0x00000000
471 Values:
472 - AbbrCode: 0x00000004
473 Values:
474 - Value: 0x0000000000000085
475 - Value: 0x0000000000000005
476 - Value: 0x0000000000000004
477 - AbbrCode: 0x00000005
478 Values:
479 - Value: 0x000000000000006C
480 - AbbrCode: 0x00000005
481 Values:
482 - Value: 0x0000000000000071
483 - AbbrCode: 0x00000004
484 Values:
485 - Value: 0x0000000000000089
486 - Value: 0x0000000000000006
487 - Value: 0x0000000000000001
488 - AbbrCode: 0x00000000
489 Values:
490 debug_line:
491 - TotalLength: 65
492 Version: 2
493 PrologueLength: 36
494 MinInstLength: 1
495 MaxOpsPerInst: 0
496 DefaultIsStmt: 1
497 LineBase: 251
498 LineRange: 14
499 OpcodeBase: 13
500 StandardOpcodeLengths:
501 - 0
502 - 1
503 - 1
504 - 1
505 - 1
506 - 0
507 - 0
508 - 0
509 - 1
510 - 0
511 - 0
512 - 1
513 IncludeDirs:
514 Files:
515 - Name: hello_world.c
516 DirIdx: 0
517 ModTime: 0
518 Length: 0
519 Opcodes:
520 - Opcode: DW_LNS_extended_op
521 ExtLen: 9
522 SubOpcode: DW_LNE_set_address
523 Data: 4294971216
524 - Opcode: 0x0014
525 Data: 4294971216
526 - Opcode: DW_LNS_set_column
527 Data: 3
528 - Opcode: DW_LNS_set_prologue_end
529 Data: 3
530 - Opcode: DW_LNS_const_add_pc
531 Data: 3
532 - Opcode: 0x00BB
533 Data: 3
534 - Opcode: 0x00BB
535 Data: 3
536 - Opcode: DW_LNS_advance_pc
537 Data: 11
538 - Opcode: DW_LNS_extended_op
539 ExtLen: 1
540 SubOpcode: DW_LNE_end_sequence
541 Data: 11
542 ...
543
544 #CHECK: debug_line:
545 #CHECK: - TotalLength: 65
546 #CHECK: Version: 2
547 #CHECK: PrologueLength: 36
548 #CHECK: MinInstLength: 1
549 #CHECK: MaxOpsPerInst: 0
550 #CHECK: DefaultIsStmt: 1
551 #CHECK: LineBase: 251
552 #CHECK: LineRange: 14
553 #CHECK: OpcodeBase: 13
554 #CHECK: StandardOpcodeLengths:
555 #CHECK: - 0
556 #CHECK: - 1
557 #CHECK: - 1
558 #CHECK: - 1
559 #CHECK: - 1
560 #CHECK: - 0
561 #CHECK: - 0
562 #CHECK: - 0
563 #CHECK: - 1
564 #CHECK: - 0
565 #CHECK: - 0
566 #CHECK: - 1
567 #CHECK: IncludeDirs:
568 #CHECK: Files:
569 #CHECK: - Name: hello_world.c
570 #CHECK: DirIdx: 0
571 #CHECK: ModTime: 0
572 #CHECK: Length: 0
573 #CHECK: Opcodes:
574 #CHECK: - Opcode: DW_LNS_extended_op
575 #CHECK: ExtLen: 9
576 #CHECK: SubOpcode: DW_LNE_set_address
577 #CHECK: Data: 4294971216
578 #CHECK: - Opcode: 0x0014
579 #CHECK: Data: 4294971216
580 #CHECK: - Opcode: DW_LNS_set_column
581 #CHECK: Data: 3
582 #CHECK: - Opcode: DW_LNS_set_prologue_end
583 #CHECK: Data: 3
584 #CHECK: - Opcode: DW_LNS_const_add_pc
585 #CHECK: Data: 3
586 #CHECK: - Opcode: 0x00BB
587 #CHECK: Data: 3
588 #CHECK: - Opcode: 0x00BB
589 #CHECK: Data: 3
590 #CHECK: - Opcode: DW_LNS_advance_pc
591 #CHECK: Data: 11
592 #CHECK: - Opcode: DW_LNS_extended_op
593 #CHECK: ExtLen: 1
594 #CHECK: SubOpcode: DW_LNE_end_sequence
595 #CHECK: Data: 11
596 #CHECK: ...
126126 NewValue.Value = 0xDEADBEEFDEADBEEF;
127127 DWARFDie DIEWrapper(CU.get(), &DIE);
128128 auto FormValue = DIEWrapper.getAttributeValue(AttrSpec.Attr);
129 if(!FormValue)
129 if (!FormValue)
130130 return;
131131 auto Form = FormValue.getValue().getForm();
132132 bool indirect = false;
210210 }
211211 }
212212
213 bool dumpFileEntry(DataExtractor &Data, uint32_t &Offset,
214 DWARFYAML::File &File) {
215 File.Name = Data.getCStr(&Offset);
216 if (File.Name.empty())
217 return false;
218 File.DirIdx = Data.getULEB128(&Offset);
219 File.ModTime = Data.getULEB128(&Offset);
220 File.Length = Data.getULEB128(&Offset);
221 return true;
222 }
223
224 void dumpDebugLines(DWARFContextInMemory &DCtx, DWARFYAML::Data &Y) {
225 for (const auto &CU : DCtx.compile_units()) {
226 auto CUDIE = CU->getUnitDIE();
227 if (!CUDIE)
228 continue;
229 if (auto StmtOffset =
230 CUDIE.getAttributeValueAsSectionOffset(dwarf::DW_AT_stmt_list)) {
231 DWARFYAML::LineTable DebugLines;
232 DataExtractor LineData(DCtx.getLineSection().Data, DCtx.isLittleEndian(),
233 CU->getAddressByteSize());
234 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 }
243 DebugLines.Version = LineData.getU16(&Offset);
244 DebugLines.PrologueLength =
245 LineData.getUnsigned(&Offset, SizeOfPrologueLength);
246 const uint64_t EndPrologue = DebugLines.PrologueLength + Offset;
247
248 DebugLines.MinInstLength = LineData.getU8(&Offset);
249 if (DebugLines.Version >= 4)
250 DebugLines.MaxOpsPerInst = LineData.getU8(&Offset);
251 DebugLines.DefaultIsStmt = LineData.getU8(&Offset);
252 DebugLines.LineBase = LineData.getU8(&Offset);
253 DebugLines.LineRange = LineData.getU8(&Offset);
254 DebugLines.OpcodeBase = LineData.getU8(&Offset);
255
256 DebugLines.StandardOpcodeLengths.reserve(DebugLines.OpcodeBase - 1);
257 for (uint8_t i = 1; i < DebugLines.OpcodeBase; ++i)
258 DebugLines.StandardOpcodeLengths.push_back(LineData.getU8(&Offset));
259
260 while (Offset < EndPrologue) {
261 StringRef Dir = LineData.getCStr(&Offset);
262 if (!Dir.empty())
263 DebugLines.IncludeDirs.push_back(Dir);
264 else
265 break;
266 }
267
268 while (Offset < EndPrologue) {
269 DWARFYAML::File TmpFile;
270 if (dumpFileEntry(LineData, Offset, TmpFile))
271 DebugLines.Files.push_back(TmpFile);
272 else
273 break;
274 }
275
276 const uint64_t LineEnd =
277 LineTableLength + *StmtOffset + SizeOfPrologueLength;
278 while (Offset < LineEnd) {
279 DWARFYAML::LineTableOpcode NewOp;
280 NewOp.Opcode = (dwarf::LineNumberOps)LineData.getU8(&Offset);
281 if (NewOp.Opcode == 0) {
282 auto StartExt = Offset;
283 NewOp.ExtLen = LineData.getULEB128(&Offset);
284 NewOp.SubOpcode =
285 (dwarf::LineNumberExtendedOps)LineData.getU8(&Offset);
286 switch (NewOp.SubOpcode) {
287 case dwarf::DW_LNE_set_address:
288 case dwarf::DW_LNE_set_discriminator:
289 NewOp.Data = LineData.getAddress(&Offset);
290 break;
291 case dwarf::DW_LNE_define_file:
292 dumpFileEntry(LineData, Offset, NewOp.FileEntry);
293 break;
294 case dwarf::DW_LNE_end_sequence:
295 break;
296 default:
297 while (Offset < StartExt + NewOp.ExtLen)
298 NewOp.UnknownOpcodeData.push_back(LineData.getU8(&Offset));
299 }
300 } else if (NewOp.Opcode < DebugLines.OpcodeBase) {
301 switch (NewOp.Opcode) {
302 case dwarf::DW_LNS_copy:
303 case dwarf::DW_LNS_negate_stmt:
304 case dwarf::DW_LNS_set_basic_block:
305 case dwarf::DW_LNS_const_add_pc:
306 case dwarf::DW_LNS_set_prologue_end:
307 case dwarf::DW_LNS_set_epilogue_begin:
308 break;
309
310 case dwarf::DW_LNS_advance_pc:
311 case dwarf::DW_LNS_set_file:
312 case dwarf::DW_LNS_set_column:
313 case dwarf::DW_LNS_set_isa:
314 NewOp.Data = LineData.getULEB128(&Offset);
315 break;
316
317 case dwarf::DW_LNS_advance_line:
318 NewOp.SData = LineData.getSLEB128(&Offset);
319 break;
320
321 case dwarf::DW_LNS_fixed_advance_pc:
322 NewOp.Data = LineData.getU16(&Offset);
323 break;
324
325 default:
326 for (uint8_t i = 0;
327 i < DebugLines.StandardOpcodeLengths[NewOp.Opcode - 1]; ++i)
328 NewOp.StandardOpcodeData.push_back(LineData.getULEB128(&Offset));
329 }
330 }
331 DebugLines.Opcodes.push_back(NewOp);
332 }
333 Y.DebugLines.push_back(DebugLines);
334 }
335 }
336 }
337
213338 std::error_code dwarf2yaml(DWARFContextInMemory &DCtx, DWARFYAML::Data &Y) {
214339 dumpDebugAbbrev(DCtx, Y);
215340 dumpDebugStrings(DCtx, Y);
216341 dumpDebugARanges(DCtx, Y);
217342 dumpDebugPubSections(DCtx, Y);
218343 dumpDebugInfo(DCtx, Y);
344 dumpDebugLines(DCtx, Y);
219345 return obj2yaml_error::success;
220346 }
232232 }
233233 }
234234 }
235
236 void yaml2FileEntry(raw_ostream &OS, const DWARFYAML::File &File) {
237 OS.write(File.Name.data(), File.Name.size());
238 OS.write('\0');
239 encodeULEB128(File.DirIdx, OS);
240 encodeULEB128(File.ModTime, OS);
241 encodeULEB128(File.Length, OS);
242 }
243
244 void yaml2debug_line(raw_ostream &OS, const DWARFYAML::Data &DI) {
245 for (const auto LineTable : DI.DebugLines) {
246 writeInteger((uint32_t)LineTable.TotalLength, OS, DI.IsLittleEndian);
247 uint64_t SizeOfPrologueLength = 4;
248 if (LineTable.TotalLength == UINT32_MAX) {
249 writeInteger((uint64_t)LineTable.TotalLength64, OS, DI.IsLittleEndian);
250 SizeOfPrologueLength = 8;
251 }
252 writeInteger((uint16_t)LineTable.Version, OS, DI.IsLittleEndian);
253 writeVariableSizedInteger(LineTable.PrologueLength, SizeOfPrologueLength,
254 OS, DI.IsLittleEndian);
255 writeInteger((uint8_t)LineTable.MinInstLength, OS, DI.IsLittleEndian);
256 if (LineTable.Version >= 4)
257 writeInteger((uint8_t)LineTable.MaxOpsPerInst, OS, DI.IsLittleEndian);
258 writeInteger((uint8_t)LineTable.DefaultIsStmt, OS, DI.IsLittleEndian);
259 writeInteger((uint8_t)LineTable.LineBase, OS, DI.IsLittleEndian);
260 writeInteger((uint8_t)LineTable.LineRange, OS, DI.IsLittleEndian);
261 writeInteger((uint8_t)LineTable.OpcodeBase, OS, DI.IsLittleEndian);
262
263 for (auto OpcodeLength : LineTable.StandardOpcodeLengths)
264 writeInteger((uint8_t)OpcodeLength, OS, DI.IsLittleEndian);
265
266 for (auto IncludeDir : LineTable.IncludeDirs) {
267 OS.write(IncludeDir.data(), IncludeDir.size());
268 OS.write('\0');
269 }
270 OS.write('\0');
271
272 for (auto File : LineTable.Files)
273 yaml2FileEntry(OS, File);
274 OS.write('\0');
275
276 for (auto Op : LineTable.Opcodes) {
277 writeInteger((uint8_t)Op.Opcode, OS, DI.IsLittleEndian);
278 if (Op.Opcode == 0) {
279 encodeULEB128(Op.ExtLen, OS);
280 writeInteger((uint8_t)Op.SubOpcode, OS, DI.IsLittleEndian);
281 switch (Op.SubOpcode) {
282 case dwarf::DW_LNE_set_address:
283 case dwarf::DW_LNE_set_discriminator:
284 writeVariableSizedInteger(Op.Data, DI.CompileUnits[0].AddrSize, OS,
285 DI.IsLittleEndian);
286 break;
287 case dwarf::DW_LNE_define_file:
288 yaml2FileEntry(OS, Op.FileEntry);
289 break;
290 case dwarf::DW_LNE_end_sequence:
291 break;
292 default:
293 for (auto OpByte : Op.UnknownOpcodeData)
294 writeInteger((uint8_t)OpByte, OS, DI.IsLittleEndian);
295 }
296 } else if (Op.Opcode < LineTable.OpcodeBase) {
297 switch (Op.Opcode) {
298 case dwarf::DW_LNS_copy:
299 case dwarf::DW_LNS_negate_stmt:
300 case dwarf::DW_LNS_set_basic_block:
301 case dwarf::DW_LNS_const_add_pc:
302 case dwarf::DW_LNS_set_prologue_end:
303 case dwarf::DW_LNS_set_epilogue_begin:
304 break;
305
306 case dwarf::DW_LNS_advance_pc:
307 case dwarf::DW_LNS_set_file:
308 case dwarf::DW_LNS_set_column:
309 case dwarf::DW_LNS_set_isa:
310 encodeULEB128(Op.Data, OS);
311 break;
312
313 case dwarf::DW_LNS_advance_line:
314 encodeSLEB128(Op.SData, OS);
315 break;
316
317 case dwarf::DW_LNS_fixed_advance_pc:
318 writeInteger((uint16_t)Op.Data, OS, DI.IsLittleEndian);
319 break;
320
321 default:
322 for (auto OpData : Op.StandardOpcodeData) {
323 encodeULEB128(OpData, OS);
324 }
325 }
326 }
327 }
328 }
329 }
279279 yaml2pubsection(OS, Obj.DWARF.PubTypes, Obj.IsLittleEndian);
280280 } else if (0 == strncmp(&Sec.sectname[0], "__debug_info", 16)) {
281281 yaml2debug_info(OS, Obj.DWARF);
282 } else if (0 == strncmp(&Sec.sectname[0], "__debug_line", 16)) {
283 yaml2debug_line(OS, Obj.DWARF);
282284 }
283285 } else {
284286 // Fills section data with 0xDEADBEEF
4545 const llvm::DWARFYAML::PubSection &Sect,
4646 bool IsLittleEndian);
4747 void yaml2debug_info(llvm::raw_ostream &OS, const llvm::DWARFYAML::Data &DI);
48 void yaml2debug_line(llvm::raw_ostream &OS, const llvm::DWARFYAML::Data &DI);
4849
4950 #endif