llvm.org GIT mirror llvm / 31adbb6
[ObjectYAML] Pull DWARF support into DWARFYAML namespace Since DWARF formatting is agnostic to the object file it is stored in, it doesn't make sense for this to be in the MachOYAML implementation. Pulling it into its own namespace means we could modify the ELF and COFF YAML tools to emit DWARF as well. In a follow-up patch I will better abstract this in obj2yaml and yaml2obj so that the DWARF bits in the tools can be re-used too. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@288984 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Bieneman 2 years ago
6 changed file(s) with 160 addition(s) and 100 deletion(s). Raw diff Collapse all Expand all
0 //===- DWARFYAML.h - DWARF YAMLIO implementation ----------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 ///
9 /// \file
10 /// \brief This file declares classes for handling the YAML representation
11 /// of DWARF Debug Info.
12 ///
13 //===----------------------------------------------------------------------===//
14
15
16 #ifndef LLVM_OBJECTYAML_DWARFYAML_H
17 #define LLVM_OBJECTYAML_DWARFYAML_H
18
19 #include "llvm/ObjectYAML/YAML.h"
20 #include "llvm/Support/Dwarf.h"
21
22 namespace llvm {
23 namespace DWARFYAML {
24
25 struct DWARFAttributeAbbrev {
26 llvm::dwarf::Attribute Attribute;
27 llvm::dwarf::Form Form;
28 };
29
30 struct DWARFAbbrev {
31 llvm::yaml::Hex32 Code;
32 llvm::dwarf::Tag Tag;
33 llvm::dwarf::Constants Children;
34 std::vector Attributes;
35 };
36
37 struct DWARFData {
38 std::vector AbbrevDecls;
39 std::vector DebugStrings;
40
41 bool isEmpty() const;
42 };
43
44 } // namespace llvm::DWARFYAML
45 } // namespace llvm
46
47 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::StringRef)
48 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::DWARFAttributeAbbrev)
49 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::DWARFAbbrev)
50
51 namespace llvm {
52 namespace yaml {
53
54 template <> struct MappingTraits {
55 static void mapping(IO &IO, DWARFYAML::DWARFData &DWARF);
56 };
57
58 template <> struct MappingTraits {
59 static void mapping(IO &IO, DWARFYAML::DWARFAbbrev &Abbrev);
60 };
61
62 template <> struct MappingTraits {
63 static void mapping(IO &IO, DWARFYAML::DWARFAttributeAbbrev &AttAbbrev);
64 };
65
66 #define HANDLE_DW_TAG(unused, name) \
67 io.enumCase(value, "DW_TAG_" #name, dwarf::DW_TAG_##name);
68
69 template <> struct ScalarEnumerationTraits {
70 static void enumeration(IO &io, dwarf::Tag &value) {
71 #include "llvm/Support/Dwarf.def"
72 io.enumFallback(value);
73 }
74 };
75
76 #define HANDLE_DW_AT(unused, name) \
77 io.enumCase(value, "DW_AT_" #name, dwarf::DW_AT_##name);
78
79 template <> struct ScalarEnumerationTraits {
80 static void enumeration(IO &io, dwarf::Attribute &value) {
81 #include "llvm/Support/Dwarf.def"
82 io.enumFallback(value);
83 }
84 };
85
86 #define HANDLE_DW_FORM(unused, name) \
87 io.enumCase(value, "DW_FORM_" #name, dwarf::DW_FORM_##name);
88
89 template <> struct ScalarEnumerationTraits {
90 static void enumeration(IO &io, dwarf::Form &value) {
91 #include "llvm/Support/Dwarf.def"
92 io.enumFallback(value);
93 }
94 };
95
96 template <> struct ScalarEnumerationTraits {
97 static void enumeration(IO &io, dwarf::Constants &value) {
98 io.enumCase(value, "DW_CHILDREN_no", dwarf::DW_CHILDREN_no);
99 io.enumCase(value, "DW_CHILDREN_yes", dwarf::DW_CHILDREN_yes);
100 io.enumFallback(value);
101 }
102 };
103
104 } // namespace llvm::yaml
105 } // namespace llvm
106
107 #endif
1616 #define LLVM_OBJECTYAML_MACHOYAML_H
1717
1818 #include "llvm/ObjectYAML/YAML.h"
19 #include "llvm/ObjectYAML/DWARFYAML.h"
1920 #include "llvm/Support/MachO.h"
20 #include "llvm/Support/Dwarf.h"
2121
2222 namespace llvm {
2323 namespace MachOYAML {
104104 bool isEmpty() const;
105105 };
106106
107 struct DWARFAttributeAbbrev {
108 llvm::dwarf::Attribute Attribute;
109 llvm::dwarf::Form Form;
110 };
111
112 struct DWARFAbbrev {
113 llvm::yaml::Hex32 Code;
114 llvm::dwarf::Tag Tag;
115 llvm::dwarf::Constants Children;
116 std::vector Attributes;
117 };
118
119 struct DWARFData {
120 std::vector AbbrevDecls;
121 std::vector DebugStrings;
122
123 bool isEmpty() const;
124 };
125
126107 struct Object {
127108 FileHeader Header;
128109 std::vector LoadCommands;
129110 std::vector
Sections;
130111 LinkEditData LinkEdit;
131 DWARFData DWARF;
112 DWARFYAML::DWARFData DWARF;
132113 };
133114
134115 struct FatHeader {
163144 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::MachOYAML::BindOpcode)
164145 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::MachOYAML::ExportEntry)
165146 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::MachOYAML::NListEntry)
166 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::StringRef)
167147 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::MachOYAML::Object)
168148 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::MachOYAML::FatArch)
169 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::MachOYAML::DWARFAttributeAbbrev)
170 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::MachOYAML::DWARFAbbrev)
171149
172150 namespace llvm {
173151 namespace yaml {
218196
219197 template <> struct MappingTraits {
220198 static void mapping(IO &IO, MachOYAML::NListEntry &NListEntry);
221 };
222
223 template <> struct MappingTraits {
224 static void mapping(IO &IO, MachOYAML::DWARFData &DWARF);
225 };
226
227 template <> struct MappingTraits {
228 static void mapping(IO &IO, MachOYAML::DWARFAbbrev &Abbrev);
229 };
230
231 template <> struct MappingTraits {
232 static void mapping(IO &IO, MachOYAML::DWARFAttributeAbbrev &AttAbbrev);
233199 };
234200
235201 #define HANDLE_LOAD_COMMAND(LCName, LCValue, LCStruct) \
278244 }
279245 };
280246
281 #define HANDLE_DW_TAG(unused, name) \
282 io.enumCase(value, "DW_TAG_" #name, dwarf::DW_TAG_##name);
283
284 template <> struct ScalarEnumerationTraits {
285 static void enumeration(IO &io, dwarf::Tag &value) {
286 #include "llvm/Support/Dwarf.def"
287 io.enumFallback(value);
288 }
289 };
290
291 #define HANDLE_DW_AT(unused, name) \
292 io.enumCase(value, "DW_AT_" #name, dwarf::DW_AT_##name);
293
294 template <> struct ScalarEnumerationTraits {
295 static void enumeration(IO &io, dwarf::Attribute &value) {
296 #include "llvm/Support/Dwarf.def"
297 io.enumFallback(value);
298 }
299 };
300
301 #define HANDLE_DW_FORM(unused, name) \
302 io.enumCase(value, "DW_FORM_" #name, dwarf::DW_FORM_##name);
303
304 template <> struct ScalarEnumerationTraits {
305 static void enumeration(IO &io, dwarf::Form &value) {
306 #include "llvm/Support/Dwarf.def"
307 io.enumFallback(value);
308 }
309 };
310
311 template <> struct ScalarEnumerationTraits {
312 static void enumeration(IO &io, dwarf::Constants &value) {
313 io.enumCase(value, "DW_CHILDREN_no", dwarf::DW_CHILDREN_no);
314 io.enumCase(value, "DW_CHILDREN_yes", dwarf::DW_CHILDREN_yes);
315 io.enumFallback(value);
316 }
317 };
318
319247 // This trait is used for 16-byte chars in Mach structures used for strings
320248 typedef char char_16[16];
321249
33 ELFYAML.cpp
44 MachOYAML.cpp
55 ObjectYAML.cpp
6 DWARFYAML.cpp
67 )
0 //===- DWARFYAML.cpp - DWARF YAMLIO implementation ------------------------===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines classes for handling the YAML representation of DWARF Debug
10 // Info.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "llvm/ObjectYAML/DWARFYAML.h"
15
16 namespace llvm {
17
18 bool DWARFYAML::DWARFData::isEmpty() const {
19 return 0 == DebugStrings.size() + AbbrevDecls.size();
20 }
21
22 namespace yaml {
23
24 void MappingTraits::mapping(
25 IO &IO, DWARFYAML::DWARFData &DWARF) {
26 IO.mapOptional("debug_str", DWARF.DebugStrings);
27 IO.mapOptional("debug_abbrev", DWARF.AbbrevDecls);
28 }
29
30 void MappingTraits::mapping(
31 IO &IO, DWARFYAML::DWARFAbbrev &Abbrev) {
32 IO.mapRequired("Code", Abbrev.Code);
33 IO.mapRequired("Tag", Abbrev.Tag);
34 IO.mapRequired("Children", Abbrev.Children);
35 IO.mapRequired("Attributes", Abbrev.Attributes);
36 }
37
38 void MappingTraits::mapping(
39 IO &IO, DWARFYAML::DWARFAttributeAbbrev &AttAbbrev) {
40 IO.mapRequired("Attribute", AttAbbrev.Attribute);
41 IO.mapRequired("Form", AttAbbrev.Form);
42 }
43
44 } // namespace llvm::yaml
45
46 } // namespace llvm
2626 RebaseOpcodes.size() + BindOpcodes.size() + WeakBindOpcodes.size() +
2727 LazyBindOpcodes.size() + ExportTrie.Children.size() +
2828 NameList.size() + StringTable.size();
29 }
30
31 bool MachOYAML::DWARFData::isEmpty() const {
32 return 0 == DebugStrings.size() + AbbrevDecls.size();
3329 }
3430
3531 namespace yaml {
556552 IO.mapRequired("sdk", LoadCommand.sdk);
557553 }
558554
559 void MappingTraits::mapping(
560 IO &IO, MachOYAML::DWARFData &DWARF) {
561 IO.mapOptional("debug_str", DWARF.DebugStrings);
562 IO.mapOptional("debug_abbrev", DWARF.AbbrevDecls);
563 }
564
565 void MappingTraits::mapping(
566 IO &IO, MachOYAML::DWARFAbbrev &Abbrev) {
567 IO.mapRequired("Code", Abbrev.Code);
568 IO.mapRequired("Tag", Abbrev.Tag);
569 IO.mapRequired("Children", Abbrev.Children);
570 IO.mapRequired("Attributes", Abbrev.Attributes);
571 }
572
573 void MappingTraits::mapping(
574 IO &IO, MachOYAML::DWARFAttributeAbbrev &AttAbbrev) {
575 IO.mapRequired("Attribute", AttAbbrev.Attribute);
576 IO.mapRequired("Form", AttAbbrev.Form);
577 }
578
579555 } // namespace llvm::yaml
580556
581557 } // namespace llvm
487487 if(AbbrevSetPtr) {
488488 for(auto AbbrvDeclSet : *AbbrevSetPtr) {
489489 for(auto AbbrvDecl : AbbrvDeclSet.second) {
490 MachOYAML::DWARFAbbrev Abbrv;
490 DWARFYAML::DWARFAbbrev Abbrv;
491491 Abbrv.Code = AbbrvDecl.getCode();
492492 Abbrv.Tag = AbbrvDecl.getTag();
493493 Abbrv.Children = AbbrvDecl.hasChildren() ? dwarf::DW_CHILDREN_yes
494494 : dwarf::DW_CHILDREN_no;
495495 for(auto Attribute : AbbrvDecl.attributes()) {
496 MachOYAML::DWARFAttributeAbbrev AttAbrv;
496 DWARFYAML::DWARFAttributeAbbrev AttAbrv;
497497 AttAbrv.Attribute = Attribute.Attr;
498498 AttAbrv.Form = Attribute.Form;
499499 Abbrv.Attributes.push_back(AttAbrv);