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