1 //===- DWARFYAML.cpp - DWARF YAMLIO implementation ------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines classes for handling the YAML representation of DWARF Debug
13 //===----------------------------------------------------------------------===//
15 #include "llvm/ObjectYAML/DWARFYAML.h"
19 bool DWARFYAML::Data::isEmpty() const {
20 return 0 == DebugStrings
.size() + AbbrevDecls
.size();
25 void MappingTraits
<DWARFYAML::Data
>::mapping(IO
&IO
, DWARFYAML::Data
&DWARF
) {
26 auto oldContext
= IO
.getContext();
27 IO
.setContext(&DWARF
);
28 IO
.mapOptional("debug_str", DWARF
.DebugStrings
);
29 IO
.mapOptional("debug_abbrev", DWARF
.AbbrevDecls
);
30 if (!DWARF
.ARanges
.empty() || !IO
.outputting())
31 IO
.mapOptional("debug_aranges", DWARF
.ARanges
);
32 if (!DWARF
.PubNames
.Entries
.empty() || !IO
.outputting())
33 IO
.mapOptional("debug_pubnames", DWARF
.PubNames
);
34 if (!DWARF
.PubTypes
.Entries
.empty() || !IO
.outputting())
35 IO
.mapOptional("debug_pubtypes", DWARF
.PubTypes
);
36 if (!DWARF
.GNUPubNames
.Entries
.empty() || !IO
.outputting())
37 IO
.mapOptional("debug_gnu_pubnames", DWARF
.GNUPubNames
);
38 if (!DWARF
.GNUPubTypes
.Entries
.empty() || !IO
.outputting())
39 IO
.mapOptional("debug_gnu_pubtypes", DWARF
.GNUPubTypes
);
40 IO
.mapOptional("debug_info", DWARF
.CompileUnits
);
41 IO
.mapOptional("debug_line", DWARF
.DebugLines
);
42 IO
.setContext(&oldContext
);
45 void MappingTraits
<DWARFYAML::Abbrev
>::mapping(IO
&IO
,
46 DWARFYAML::Abbrev
&Abbrev
) {
47 IO
.mapRequired("Code", Abbrev
.Code
);
48 IO
.mapRequired("Tag", Abbrev
.Tag
);
49 IO
.mapRequired("Children", Abbrev
.Children
);
50 IO
.mapRequired("Attributes", Abbrev
.Attributes
);
53 void MappingTraits
<DWARFYAML::AttributeAbbrev
>::mapping(
54 IO
&IO
, DWARFYAML::AttributeAbbrev
&AttAbbrev
) {
55 IO
.mapRequired("Attribute", AttAbbrev
.Attribute
);
56 IO
.mapRequired("Form", AttAbbrev
.Form
);
57 if(AttAbbrev
.Form
== dwarf::DW_FORM_implicit_const
)
58 IO
.mapRequired("Value", AttAbbrev
.Value
);
61 void MappingTraits
<DWARFYAML::ARangeDescriptor
>::mapping(
62 IO
&IO
, DWARFYAML::ARangeDescriptor
&Descriptor
) {
63 IO
.mapRequired("Address", Descriptor
.Address
);
64 IO
.mapRequired("Length", Descriptor
.Length
);
67 void MappingTraits
<DWARFYAML::ARange
>::mapping(IO
&IO
,
68 DWARFYAML::ARange
&Range
) {
69 IO
.mapRequired("Length", Range
.Length
);
70 IO
.mapRequired("Version", Range
.Version
);
71 IO
.mapRequired("CuOffset", Range
.CuOffset
);
72 IO
.mapRequired("AddrSize", Range
.AddrSize
);
73 IO
.mapRequired("SegSize", Range
.SegSize
);
74 IO
.mapRequired("Descriptors", Range
.Descriptors
);
77 void MappingTraits
<DWARFYAML::PubEntry
>::mapping(IO
&IO
,
78 DWARFYAML::PubEntry
&Entry
) {
79 IO
.mapRequired("DieOffset", Entry
.DieOffset
);
80 if (reinterpret_cast<DWARFYAML::PubSection
*>(IO
.getContext())->IsGNUStyle
)
81 IO
.mapRequired("Descriptor", Entry
.Descriptor
);
82 IO
.mapRequired("Name", Entry
.Name
);
85 void MappingTraits
<DWARFYAML::PubSection
>::mapping(
86 IO
&IO
, DWARFYAML::PubSection
&Section
) {
87 auto OldContext
= IO
.getContext();
88 IO
.setContext(&Section
);
90 IO
.mapRequired("Length", Section
.Length
);
91 IO
.mapRequired("Version", Section
.Version
);
92 IO
.mapRequired("UnitOffset", Section
.UnitOffset
);
93 IO
.mapRequired("UnitSize", Section
.UnitSize
);
94 IO
.mapRequired("Entries", Section
.Entries
);
96 IO
.setContext(OldContext
);
99 void MappingTraits
<DWARFYAML::Unit
>::mapping(IO
&IO
, DWARFYAML::Unit
&Unit
) {
100 IO
.mapRequired("Length", Unit
.Length
);
101 IO
.mapRequired("Version", Unit
.Version
);
102 if (Unit
.Version
>= 5)
103 IO
.mapRequired("UnitType", Unit
.Type
);
104 IO
.mapRequired("AbbrOffset", Unit
.AbbrOffset
);
105 IO
.mapRequired("AddrSize", Unit
.AddrSize
);
106 IO
.mapOptional("Entries", Unit
.Entries
);
109 void MappingTraits
<DWARFYAML::Entry
>::mapping(IO
&IO
, DWARFYAML::Entry
&Entry
) {
110 IO
.mapRequired("AbbrCode", Entry
.AbbrCode
);
111 IO
.mapRequired("Values", Entry
.Values
);
114 void MappingTraits
<DWARFYAML::FormValue
>::mapping(
115 IO
&IO
, DWARFYAML::FormValue
&FormValue
) {
116 IO
.mapOptional("Value", FormValue
.Value
);
117 if (!FormValue
.CStr
.empty() || !IO
.outputting())
118 IO
.mapOptional("CStr", FormValue
.CStr
);
119 if (!FormValue
.BlockData
.empty() || !IO
.outputting())
120 IO
.mapOptional("BlockData", FormValue
.BlockData
);
123 void MappingTraits
<DWARFYAML::File
>::mapping(IO
&IO
, DWARFYAML::File
&File
) {
124 IO
.mapRequired("Name", File
.Name
);
125 IO
.mapRequired("DirIdx", File
.DirIdx
);
126 IO
.mapRequired("ModTime", File
.ModTime
);
127 IO
.mapRequired("Length", File
.Length
);
130 void MappingTraits
<DWARFYAML::LineTableOpcode
>::mapping(
131 IO
&IO
, DWARFYAML::LineTableOpcode
&LineTableOpcode
) {
132 IO
.mapRequired("Opcode", LineTableOpcode
.Opcode
);
133 if (LineTableOpcode
.Opcode
== dwarf::DW_LNS_extended_op
) {
134 IO
.mapRequired("ExtLen", LineTableOpcode
.ExtLen
);
135 IO
.mapRequired("SubOpcode", LineTableOpcode
.SubOpcode
);
138 if (!LineTableOpcode
.UnknownOpcodeData
.empty() || !IO
.outputting())
139 IO
.mapOptional("UnknownOpcodeData", LineTableOpcode
.UnknownOpcodeData
);
140 if (!LineTableOpcode
.UnknownOpcodeData
.empty() || !IO
.outputting())
141 IO
.mapOptional("StandardOpcodeData", LineTableOpcode
.StandardOpcodeData
);
142 if (!LineTableOpcode
.FileEntry
.Name
.empty() || !IO
.outputting())
143 IO
.mapOptional("FileEntry", LineTableOpcode
.FileEntry
);
144 if (LineTableOpcode
.Opcode
== dwarf::DW_LNS_advance_line
|| !IO
.outputting())
145 IO
.mapOptional("SData", LineTableOpcode
.SData
);
146 IO
.mapOptional("Data", LineTableOpcode
.Data
);
149 void MappingTraits
<DWARFYAML::LineTable
>::mapping(
150 IO
&IO
, DWARFYAML::LineTable
&LineTable
) {
151 IO
.mapRequired("Length", LineTable
.Length
);
152 IO
.mapRequired("Version", LineTable
.Version
);
153 IO
.mapRequired("PrologueLength", LineTable
.PrologueLength
);
154 IO
.mapRequired("MinInstLength", LineTable
.MinInstLength
);
155 if(LineTable
.Version
>= 4)
156 IO
.mapRequired("MaxOpsPerInst", LineTable
.MaxOpsPerInst
);
157 IO
.mapRequired("DefaultIsStmt", LineTable
.DefaultIsStmt
);
158 IO
.mapRequired("LineBase", LineTable
.LineBase
);
159 IO
.mapRequired("LineRange", LineTable
.LineRange
);
160 IO
.mapRequired("OpcodeBase", LineTable
.OpcodeBase
);
161 IO
.mapRequired("StandardOpcodeLengths", LineTable
.StandardOpcodeLengths
);
162 IO
.mapRequired("IncludeDirs", LineTable
.IncludeDirs
);
163 IO
.mapRequired("Files", LineTable
.Files
);
164 IO
.mapRequired("Opcodes", LineTable
.Opcodes
);
167 void MappingTraits
<DWARFYAML::InitialLength
>::mapping(
168 IO
&IO
, DWARFYAML::InitialLength
&InitialLength
) {
169 IO
.mapRequired("TotalLength", InitialLength
.TotalLength
);
170 if (InitialLength
.isDWARF64())
171 IO
.mapRequired("TotalLength64", InitialLength
.TotalLength64
);
174 } // end namespace yaml
176 } // end namespace llvm