1 //===- DWARFYAML.cpp - DWARF YAMLIO implementation ------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file defines classes for handling the YAML representation of DWARF Debug
12 //===----------------------------------------------------------------------===//
14 #include "llvm/ObjectYAML/DWARFYAML.h"
18 bool DWARFYAML::Data::isEmpty() const {
19 return 0 == DebugStrings
.size() + AbbrevDecls
.size();
24 void MappingTraits
<DWARFYAML::Data
>::mapping(IO
&IO
, DWARFYAML::Data
&DWARF
) {
25 auto oldContext
= IO
.getContext();
26 IO
.setContext(&DWARF
);
27 IO
.mapOptional("debug_str", DWARF
.DebugStrings
);
28 IO
.mapOptional("debug_abbrev", DWARF
.AbbrevDecls
);
29 if (!DWARF
.ARanges
.empty() || !IO
.outputting())
30 IO
.mapOptional("debug_aranges", DWARF
.ARanges
);
31 if (!DWARF
.PubNames
.Entries
.empty() || !IO
.outputting())
32 IO
.mapOptional("debug_pubnames", DWARF
.PubNames
);
33 if (!DWARF
.PubTypes
.Entries
.empty() || !IO
.outputting())
34 IO
.mapOptional("debug_pubtypes", DWARF
.PubTypes
);
35 if (!DWARF
.GNUPubNames
.Entries
.empty() || !IO
.outputting())
36 IO
.mapOptional("debug_gnu_pubnames", DWARF
.GNUPubNames
);
37 if (!DWARF
.GNUPubTypes
.Entries
.empty() || !IO
.outputting())
38 IO
.mapOptional("debug_gnu_pubtypes", DWARF
.GNUPubTypes
);
39 IO
.mapOptional("debug_info", DWARF
.CompileUnits
);
40 IO
.mapOptional("debug_line", DWARF
.DebugLines
);
41 IO
.setContext(&oldContext
);
44 void MappingTraits
<DWARFYAML::Abbrev
>::mapping(IO
&IO
,
45 DWARFYAML::Abbrev
&Abbrev
) {
46 IO
.mapRequired("Code", Abbrev
.Code
);
47 IO
.mapRequired("Tag", Abbrev
.Tag
);
48 IO
.mapRequired("Children", Abbrev
.Children
);
49 IO
.mapRequired("Attributes", Abbrev
.Attributes
);
52 void MappingTraits
<DWARFYAML::AttributeAbbrev
>::mapping(
53 IO
&IO
, DWARFYAML::AttributeAbbrev
&AttAbbrev
) {
54 IO
.mapRequired("Attribute", AttAbbrev
.Attribute
);
55 IO
.mapRequired("Form", AttAbbrev
.Form
);
56 if(AttAbbrev
.Form
== dwarf::DW_FORM_implicit_const
)
57 IO
.mapRequired("Value", AttAbbrev
.Value
);
60 void MappingTraits
<DWARFYAML::ARangeDescriptor
>::mapping(
61 IO
&IO
, DWARFYAML::ARangeDescriptor
&Descriptor
) {
62 IO
.mapRequired("Address", Descriptor
.Address
);
63 IO
.mapRequired("Length", Descriptor
.Length
);
66 void MappingTraits
<DWARFYAML::ARange
>::mapping(IO
&IO
,
67 DWARFYAML::ARange
&Range
) {
68 IO
.mapRequired("Length", Range
.Length
);
69 IO
.mapRequired("Version", Range
.Version
);
70 IO
.mapRequired("CuOffset", Range
.CuOffset
);
71 IO
.mapRequired("AddrSize", Range
.AddrSize
);
72 IO
.mapRequired("SegSize", Range
.SegSize
);
73 IO
.mapRequired("Descriptors", Range
.Descriptors
);
76 void MappingTraits
<DWARFYAML::PubEntry
>::mapping(IO
&IO
,
77 DWARFYAML::PubEntry
&Entry
) {
78 IO
.mapRequired("DieOffset", Entry
.DieOffset
);
79 if (reinterpret_cast<DWARFYAML::PubSection
*>(IO
.getContext())->IsGNUStyle
)
80 IO
.mapRequired("Descriptor", Entry
.Descriptor
);
81 IO
.mapRequired("Name", Entry
.Name
);
84 void MappingTraits
<DWARFYAML::PubSection
>::mapping(
85 IO
&IO
, DWARFYAML::PubSection
&Section
) {
86 auto OldContext
= IO
.getContext();
87 IO
.setContext(&Section
);
89 IO
.mapRequired("Length", Section
.Length
);
90 IO
.mapRequired("Version", Section
.Version
);
91 IO
.mapRequired("UnitOffset", Section
.UnitOffset
);
92 IO
.mapRequired("UnitSize", Section
.UnitSize
);
93 IO
.mapRequired("Entries", Section
.Entries
);
95 IO
.setContext(OldContext
);
98 void MappingTraits
<DWARFYAML::Unit
>::mapping(IO
&IO
, DWARFYAML::Unit
&Unit
) {
99 IO
.mapRequired("Length", Unit
.Length
);
100 IO
.mapRequired("Version", Unit
.Version
);
101 if (Unit
.Version
>= 5)
102 IO
.mapRequired("UnitType", Unit
.Type
);
103 IO
.mapRequired("AbbrOffset", Unit
.AbbrOffset
);
104 IO
.mapRequired("AddrSize", Unit
.AddrSize
);
105 IO
.mapOptional("Entries", Unit
.Entries
);
108 void MappingTraits
<DWARFYAML::Entry
>::mapping(IO
&IO
, DWARFYAML::Entry
&Entry
) {
109 IO
.mapRequired("AbbrCode", Entry
.AbbrCode
);
110 IO
.mapRequired("Values", Entry
.Values
);
113 void MappingTraits
<DWARFYAML::FormValue
>::mapping(
114 IO
&IO
, DWARFYAML::FormValue
&FormValue
) {
115 IO
.mapOptional("Value", FormValue
.Value
);
116 if (!FormValue
.CStr
.empty() || !IO
.outputting())
117 IO
.mapOptional("CStr", FormValue
.CStr
);
118 if (!FormValue
.BlockData
.empty() || !IO
.outputting())
119 IO
.mapOptional("BlockData", FormValue
.BlockData
);
122 void MappingTraits
<DWARFYAML::File
>::mapping(IO
&IO
, DWARFYAML::File
&File
) {
123 IO
.mapRequired("Name", File
.Name
);
124 IO
.mapRequired("DirIdx", File
.DirIdx
);
125 IO
.mapRequired("ModTime", File
.ModTime
);
126 IO
.mapRequired("Length", File
.Length
);
129 void MappingTraits
<DWARFYAML::LineTableOpcode
>::mapping(
130 IO
&IO
, DWARFYAML::LineTableOpcode
&LineTableOpcode
) {
131 IO
.mapRequired("Opcode", LineTableOpcode
.Opcode
);
132 if (LineTableOpcode
.Opcode
== dwarf::DW_LNS_extended_op
) {
133 IO
.mapRequired("ExtLen", LineTableOpcode
.ExtLen
);
134 IO
.mapRequired("SubOpcode", LineTableOpcode
.SubOpcode
);
137 if (!LineTableOpcode
.UnknownOpcodeData
.empty() || !IO
.outputting())
138 IO
.mapOptional("UnknownOpcodeData", LineTableOpcode
.UnknownOpcodeData
);
139 if (!LineTableOpcode
.UnknownOpcodeData
.empty() || !IO
.outputting())
140 IO
.mapOptional("StandardOpcodeData", LineTableOpcode
.StandardOpcodeData
);
141 if (!LineTableOpcode
.FileEntry
.Name
.empty() || !IO
.outputting())
142 IO
.mapOptional("FileEntry", LineTableOpcode
.FileEntry
);
143 if (LineTableOpcode
.Opcode
== dwarf::DW_LNS_advance_line
|| !IO
.outputting())
144 IO
.mapOptional("SData", LineTableOpcode
.SData
);
145 IO
.mapOptional("Data", LineTableOpcode
.Data
);
148 void MappingTraits
<DWARFYAML::LineTable
>::mapping(
149 IO
&IO
, DWARFYAML::LineTable
&LineTable
) {
150 IO
.mapRequired("Length", LineTable
.Length
);
151 IO
.mapRequired("Version", LineTable
.Version
);
152 IO
.mapRequired("PrologueLength", LineTable
.PrologueLength
);
153 IO
.mapRequired("MinInstLength", LineTable
.MinInstLength
);
154 if(LineTable
.Version
>= 4)
155 IO
.mapRequired("MaxOpsPerInst", LineTable
.MaxOpsPerInst
);
156 IO
.mapRequired("DefaultIsStmt", LineTable
.DefaultIsStmt
);
157 IO
.mapRequired("LineBase", LineTable
.LineBase
);
158 IO
.mapRequired("LineRange", LineTable
.LineRange
);
159 IO
.mapRequired("OpcodeBase", LineTable
.OpcodeBase
);
160 IO
.mapRequired("StandardOpcodeLengths", LineTable
.StandardOpcodeLengths
);
161 IO
.mapRequired("IncludeDirs", LineTable
.IncludeDirs
);
162 IO
.mapRequired("Files", LineTable
.Files
);
163 IO
.mapRequired("Opcodes", LineTable
.Opcodes
);
166 void MappingTraits
<DWARFYAML::InitialLength
>::mapping(
167 IO
&IO
, DWARFYAML::InitialLength
&InitialLength
) {
168 IO
.mapRequired("TotalLength", InitialLength
.TotalLength
);
169 if (InitialLength
.isDWARF64())
170 IO
.mapRequired("TotalLength64", InitialLength
.TotalLength64
);
173 } // end namespace yaml
175 } // end namespace llvm