llvm.org GIT mirror llvm / 18245f6
[ObjectYAML] Support for DWARF debug_aranges This patch adds support for round tripping DWARF debug_aranges in and out of YAML. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@289161 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Bieneman 2 years ago
8 changed file(s) with 436 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
5858
5959 uint32_t getCompileUnitDIEOffset() const { return HeaderData.CuOffset; }
6060
61 const Header &getHeader() const { return HeaderData; }
62
6163 desc_iterator_range descriptors() const {
6264 return desc_iterator_range(ArangeDescriptors.begin(),
6365 ArangeDescriptors.end());
3434 std::vector Attributes;
3535 };
3636
37 struct ARangeDescriptor {
38 llvm::yaml::Hex64 Address;
39 uint64_t Length;
40 };
41
42 struct ARange {
43 uint32_t Length;
44 uint16_t Version;
45 uint32_t CuOffset;
46 uint8_t AddrSize;
47 uint8_t SegSize;
48 std::vector Descriptors;
49 };
50
3751 struct Data {
3852 std::vector AbbrevDecls;
3953 std::vector DebugStrings;
54 std::vector ARanges;
4055
4156 bool isEmpty() const;
4257 };
4762 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::StringRef)
4863 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::AttributeAbbrev)
4964 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::Abbrev)
65 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::ARangeDescriptor)
66 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::ARange)
5067
5168 namespace llvm {
5269 namespace yaml {
6178
6279 template <> struct MappingTraits {
6380 static void mapping(IO &IO, DWARFYAML::AttributeAbbrev &AttAbbrev);
81 };
82
83 template <> struct MappingTraits {
84 static void mapping(IO &IO, DWARFYAML::ARangeDescriptor &Descriptor);
85 };
86
87 template <> struct MappingTraits {
88 static void mapping(IO &IO, DWARFYAML::ARange &Range);
6489 };
6590
6691 #define HANDLE_DW_TAG(unused, name) \
2525 IO &IO, DWARFYAML::Data &DWARF) {
2626 IO.mapOptional("debug_str", DWARF.DebugStrings);
2727 IO.mapOptional("debug_abbrev", DWARF.AbbrevDecls);
28 if(!DWARF.ARanges.empty() || !IO.outputting())
29 IO.mapOptional("debug_aranges", DWARF.ARanges);
2830 }
2931
3032 void MappingTraits::mapping(
4143 IO.mapRequired("Form", AttAbbrev.Form);
4244 }
4345
46 void MappingTraits::mapping(
47 IO &IO, DWARFYAML::ARangeDescriptor &Descriptor) {
48 IO.mapRequired("Address", Descriptor.Address);
49 IO.mapRequired("Length", Descriptor.Length);
50 }
51
52 void MappingTraits::mapping(IO &IO,
53 DWARFYAML::ARange &Range) {
54 IO.mapRequired("Length", Range.Length);
55 IO.mapRequired("Version", Range.Version);
56 IO.mapRequired("CuOffset", Range.CuOffset);
57 IO.mapRequired("AddrSize", Range.AddrSize);
58 IO.mapRequired("SegSize", Range.SegSize);
59 IO.mapRequired("Descriptors", Range.Descriptors);
60 }
61
4462 } // namespace llvm::yaml
4563
4664 } // 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: 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_aranges:
315 - Length: 44
316 Version: 2
317 CuOffset: 0
318 AddrSize: 8
319 SegSize: 0
320 Descriptors:
321 - Address: 0x0000000100000F50
322 Length: 52
323 ...
324
325 #CHECK: DWARF:
326 #CHECK: debug_aranges:
327 #CHECK: - Length: 44
328 #CHECK: Version: 2
329 #CHECK: CuOffset: 0
330 #CHECK: AddrSize: 8
331 #CHECK: SegSize: 0
332 #CHECK: Descriptors:
333 #CHECK: - Address: 0x0000000100000F50
334 #CHECK: Length: 52
88
99 #include "Error.h"
1010 #include "llvm/DebugInfo/DWARF/DWARFContext.h"
11 #include "llvm/DebugInfo/DWARF/DWARFDebugArangeSet.h"
1112 #include "llvm/ObjectYAML/DWARFYAML.h"
1213
1314 using namespace llvm;
4344 }
4445 }
4546
47 void dumpDebugARanges(DWARFContextInMemory &DCtx, DWARFYAML::Data &Y) {
48 DataExtractor ArangesData(DCtx.getARangeSection(), DCtx.isLittleEndian(), 0);
49 uint32_t Offset = 0;
50 DWARFDebugArangeSet Set;
51
52 while (Set.extract(ArangesData, &Offset)) {
53 DWARFYAML::ARange Range;
54 Range.Length = Set.getHeader().Length;
55 Range.Version = Set.getHeader().Version;
56 Range.CuOffset = Set.getHeader().CuOffset;
57 Range.AddrSize = Set.getHeader().AddrSize;
58 Range.SegSize = Set.getHeader().SegSize;
59 for (auto Descriptor : Set.descriptors()) {
60 DWARFYAML::ARangeDescriptor Desc;
61 Desc.Address = Descriptor.Address;
62 Desc.Length = Descriptor.Length;
63 Range.Descriptors.push_back(Desc);
64 }
65 Y.ARanges.push_back(Range);
66 }
67 }
68
4669 std::error_code dwarf2yaml(DWARFContextInMemory &DCtx,
4770 DWARFYAML::Data &Y) {
4871 dumpDebugAbbrev(DCtx, Y);
4972 dumpDebugStrings(DCtx, Y);
73 dumpDebugARanges(DCtx, Y);
5074
5175 return obj2yaml_error::success;
5276 }
1818
1919 using namespace llvm;
2020
21 void ZeroFillBytes(raw_ostream &OS, size_t Size) {
22 std::vector FillData;
23 FillData.insert(FillData.begin(), Size, 0);
24 OS.write(reinterpret_cast(FillData.data()), Size);
25 }
26
2127 void yaml2debug_str(raw_ostream &OS, const DWARFYAML::Data &DI) {
2228 for (auto Str : DI.DebugStrings) {
2329 OS.write(Str.data(), Str.size());
3844 encodeULEB128(0, OS);
3945 }
4046 }
47
48 void yaml2debug_aranges(raw_ostream &OS, const DWARFYAML::Data &DI) {
49 for (auto Range : DI.ARanges) {
50 auto HeaderStart = OS.tell();
51 OS.write(reinterpret_cast(&Range.Length), 4);
52 OS.write(reinterpret_cast(&Range.Version), 2);
53 OS.write(reinterpret_cast(&Range.CuOffset), 4);
54 OS.write(reinterpret_cast(&Range.AddrSize), 1);
55 OS.write(reinterpret_cast(&Range.SegSize), 1);
56
57 auto HeaderSize = OS.tell() - HeaderStart;
58 auto FirstDescriptor = alignTo(HeaderSize, Range.AddrSize * 2);
59 ZeroFillBytes(OS, FirstDescriptor - HeaderSize);
60
61 for (auto Descriptor : Range.Descriptors) {
62 OS.write(reinterpret_cast(&Descriptor.Address), Range.AddrSize);
63 OS.write(reinterpret_cast(&Descriptor.Length), Range.AddrSize);
64 }
65 ZeroFillBytes(OS, Range.AddrSize * 2);
66 }
67 }
392392 } else if (0 == strncmp(&Section.sectname[0], "__debug_abbrev", 16)) {
393393 yaml2debug_abbrev(OS, Obj.DWARF);
394394 }
395 else if (0 == strncmp(&Section.sectname[0], "__debug_aranges", 16)) {
396 yaml2debug_aranges(OS, Obj.DWARF);
397 }
395398 }
396399 return Error::success();
397400 }
4141 void yaml2debug_str(llvm::raw_ostream &OS,
4242 const llvm::DWARFYAML::Data &DI);
4343
44 void yaml2debug_aranges(llvm::raw_ostream &OS, const llvm::DWARFYAML::Data &DI);
45
4446 #endif