/src/llvm-project/llvm/lib/ObjectYAML/DWARFYAML.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | //===- DWARFYAML.cpp - DWARF YAMLIO implementation ------------------------===// |
2 | | // |
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 |
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 | | #include "llvm/BinaryFormat/Dwarf.h" |
16 | | #include "llvm/Support/Errc.h" |
17 | | #include "llvm/Support/Error.h" |
18 | | |
19 | | namespace llvm { |
20 | | |
21 | 0 | bool DWARFYAML::Data::isEmpty() const { |
22 | 0 | return getNonEmptySectionNames().empty(); |
23 | 0 | } |
24 | | |
25 | 0 | SetVector<StringRef> DWARFYAML::Data::getNonEmptySectionNames() const { |
26 | 0 | SetVector<StringRef> SecNames; |
27 | 0 | if (DebugStrings) |
28 | 0 | SecNames.insert("debug_str"); |
29 | 0 | if (DebugAranges) |
30 | 0 | SecNames.insert("debug_aranges"); |
31 | 0 | if (DebugRanges) |
32 | 0 | SecNames.insert("debug_ranges"); |
33 | 0 | if (!DebugLines.empty()) |
34 | 0 | SecNames.insert("debug_line"); |
35 | 0 | if (DebugAddr) |
36 | 0 | SecNames.insert("debug_addr"); |
37 | 0 | if (!DebugAbbrev.empty()) |
38 | 0 | SecNames.insert("debug_abbrev"); |
39 | 0 | if (!CompileUnits.empty()) |
40 | 0 | SecNames.insert("debug_info"); |
41 | 0 | if (PubNames) |
42 | 0 | SecNames.insert("debug_pubnames"); |
43 | 0 | if (PubTypes) |
44 | 0 | SecNames.insert("debug_pubtypes"); |
45 | 0 | if (GNUPubNames) |
46 | 0 | SecNames.insert("debug_gnu_pubnames"); |
47 | 0 | if (GNUPubTypes) |
48 | 0 | SecNames.insert("debug_gnu_pubtypes"); |
49 | 0 | if (DebugStrOffsets) |
50 | 0 | SecNames.insert("debug_str_offsets"); |
51 | 0 | if (DebugRnglists) |
52 | 0 | SecNames.insert("debug_rnglists"); |
53 | 0 | if (DebugLoclists) |
54 | 0 | SecNames.insert("debug_loclists"); |
55 | 0 | return SecNames; |
56 | 0 | } |
57 | | |
58 | | Expected<DWARFYAML::Data::AbbrevTableInfo> |
59 | 0 | DWARFYAML::Data::getAbbrevTableInfoByID(uint64_t ID) const { |
60 | 0 | if (AbbrevTableInfoMap.empty()) { |
61 | 0 | uint64_t AbbrevTableOffset = 0; |
62 | 0 | for (const auto &[Index, AbbrevTable] : enumerate(DebugAbbrev)) { |
63 | | // If the abbrev table's ID isn't specified, we use the index as its ID. |
64 | 0 | uint64_t AbbrevTableID = AbbrevTable.ID.value_or(Index); |
65 | 0 | auto It = AbbrevTableInfoMap.insert( |
66 | 0 | {AbbrevTableID, AbbrevTableInfo{/*Index=*/Index, |
67 | 0 | /*Offset=*/AbbrevTableOffset}}); |
68 | 0 | if (!It.second) |
69 | 0 | return createStringError( |
70 | 0 | errc::invalid_argument, |
71 | 0 | "the ID (%" PRIu64 ") of abbrev table with index %zu has been used " |
72 | 0 | "by abbrev table with index %" PRIu64, |
73 | 0 | AbbrevTableID, Index, It.first->second.Index); |
74 | | |
75 | 0 | AbbrevTableOffset += getAbbrevTableContentByIndex(Index).size(); |
76 | 0 | } |
77 | 0 | } |
78 | | |
79 | 0 | auto It = AbbrevTableInfoMap.find(ID); |
80 | 0 | if (It == AbbrevTableInfoMap.end()) |
81 | 0 | return createStringError(errc::invalid_argument, |
82 | 0 | "cannot find abbrev table whose ID is %" PRIu64, |
83 | 0 | ID); |
84 | 0 | return It->second; |
85 | 0 | } |
86 | | |
87 | | namespace yaml { |
88 | | |
89 | 0 | void MappingTraits<DWARFYAML::Data>::mapping(IO &IO, DWARFYAML::Data &DWARF) { |
90 | 0 | void *OldContext = IO.getContext(); |
91 | 0 | DWARFYAML::DWARFContext DWARFCtx; |
92 | 0 | IO.setContext(&DWARFCtx); |
93 | 0 | IO.mapOptional("debug_str", DWARF.DebugStrings); |
94 | 0 | IO.mapOptional("debug_abbrev", DWARF.DebugAbbrev); |
95 | 0 | IO.mapOptional("debug_aranges", DWARF.DebugAranges); |
96 | 0 | IO.mapOptional("debug_ranges", DWARF.DebugRanges); |
97 | 0 | IO.mapOptional("debug_pubnames", DWARF.PubNames); |
98 | 0 | IO.mapOptional("debug_pubtypes", DWARF.PubTypes); |
99 | 0 | DWARFCtx.IsGNUPubSec = true; |
100 | 0 | IO.mapOptional("debug_gnu_pubnames", DWARF.GNUPubNames); |
101 | 0 | IO.mapOptional("debug_gnu_pubtypes", DWARF.GNUPubTypes); |
102 | 0 | IO.mapOptional("debug_info", DWARF.CompileUnits); |
103 | 0 | IO.mapOptional("debug_line", DWARF.DebugLines); |
104 | 0 | IO.mapOptional("debug_addr", DWARF.DebugAddr); |
105 | 0 | IO.mapOptional("debug_str_offsets", DWARF.DebugStrOffsets); |
106 | 0 | IO.mapOptional("debug_rnglists", DWARF.DebugRnglists); |
107 | 0 | IO.mapOptional("debug_loclists", DWARF.DebugLoclists); |
108 | 0 | IO.setContext(OldContext); |
109 | 0 | } |
110 | | |
111 | | void MappingTraits<DWARFYAML::AbbrevTable>::mapping( |
112 | 0 | IO &IO, DWARFYAML::AbbrevTable &AbbrevTable) { |
113 | 0 | IO.mapOptional("ID", AbbrevTable.ID); |
114 | 0 | IO.mapOptional("Table", AbbrevTable.Table); |
115 | 0 | } |
116 | | |
117 | | void MappingTraits<DWARFYAML::Abbrev>::mapping(IO &IO, |
118 | 0 | DWARFYAML::Abbrev &Abbrev) { |
119 | 0 | IO.mapOptional("Code", Abbrev.Code); |
120 | 0 | IO.mapRequired("Tag", Abbrev.Tag); |
121 | 0 | IO.mapRequired("Children", Abbrev.Children); |
122 | 0 | IO.mapOptional("Attributes", Abbrev.Attributes); |
123 | 0 | } |
124 | | |
125 | | void MappingTraits<DWARFYAML::AttributeAbbrev>::mapping( |
126 | 0 | IO &IO, DWARFYAML::AttributeAbbrev &AttAbbrev) { |
127 | 0 | IO.mapRequired("Attribute", AttAbbrev.Attribute); |
128 | 0 | IO.mapRequired("Form", AttAbbrev.Form); |
129 | 0 | if(AttAbbrev.Form == dwarf::DW_FORM_implicit_const) |
130 | 0 | IO.mapRequired("Value", AttAbbrev.Value); |
131 | 0 | } |
132 | | |
133 | | void MappingTraits<DWARFYAML::ARangeDescriptor>::mapping( |
134 | 0 | IO &IO, DWARFYAML::ARangeDescriptor &Descriptor) { |
135 | 0 | IO.mapRequired("Address", Descriptor.Address); |
136 | 0 | IO.mapRequired("Length", Descriptor.Length); |
137 | 0 | } |
138 | | |
139 | | void MappingTraits<DWARFYAML::ARange>::mapping(IO &IO, |
140 | 0 | DWARFYAML::ARange &ARange) { |
141 | 0 | IO.mapOptional("Format", ARange.Format, dwarf::DWARF32); |
142 | 0 | IO.mapOptional("Length", ARange.Length); |
143 | 0 | IO.mapRequired("Version", ARange.Version); |
144 | 0 | IO.mapRequired("CuOffset", ARange.CuOffset); |
145 | 0 | IO.mapOptional("AddressSize", ARange.AddrSize); |
146 | 0 | IO.mapOptional("SegmentSelectorSize", ARange.SegSize, 0); |
147 | 0 | IO.mapOptional("Descriptors", ARange.Descriptors); |
148 | 0 | } |
149 | | |
150 | | void MappingTraits<DWARFYAML::RangeEntry>::mapping( |
151 | 0 | IO &IO, DWARFYAML::RangeEntry &Descriptor) { |
152 | 0 | IO.mapRequired("LowOffset", Descriptor.LowOffset); |
153 | 0 | IO.mapRequired("HighOffset", Descriptor.HighOffset); |
154 | 0 | } |
155 | | |
156 | | void MappingTraits<DWARFYAML::Ranges>::mapping(IO &IO, |
157 | 0 | DWARFYAML::Ranges &DebugRanges) { |
158 | 0 | IO.mapOptional("Offset", DebugRanges.Offset); |
159 | 0 | IO.mapOptional("AddrSize", DebugRanges.AddrSize); |
160 | 0 | IO.mapRequired("Entries", DebugRanges.Entries); |
161 | 0 | } |
162 | | |
163 | | void MappingTraits<DWARFYAML::PubEntry>::mapping(IO &IO, |
164 | 0 | DWARFYAML::PubEntry &Entry) { |
165 | 0 | IO.mapRequired("DieOffset", Entry.DieOffset); |
166 | 0 | if (static_cast<DWARFYAML::DWARFContext *>(IO.getContext())->IsGNUPubSec) |
167 | 0 | IO.mapRequired("Descriptor", Entry.Descriptor); |
168 | 0 | IO.mapRequired("Name", Entry.Name); |
169 | 0 | } |
170 | | |
171 | | void MappingTraits<DWARFYAML::PubSection>::mapping( |
172 | 0 | IO &IO, DWARFYAML::PubSection &Section) { |
173 | 0 | IO.mapOptional("Format", Section.Format, dwarf::DWARF32); |
174 | 0 | IO.mapRequired("Length", Section.Length); |
175 | 0 | IO.mapRequired("Version", Section.Version); |
176 | 0 | IO.mapRequired("UnitOffset", Section.UnitOffset); |
177 | 0 | IO.mapRequired("UnitSize", Section.UnitSize); |
178 | 0 | IO.mapRequired("Entries", Section.Entries); |
179 | 0 | } |
180 | | |
181 | 0 | void MappingTraits<DWARFYAML::Unit>::mapping(IO &IO, DWARFYAML::Unit &Unit) { |
182 | 0 | IO.mapOptional("Format", Unit.Format, dwarf::DWARF32); |
183 | 0 | IO.mapOptional("Length", Unit.Length); |
184 | 0 | IO.mapRequired("Version", Unit.Version); |
185 | 0 | if (Unit.Version >= 5) |
186 | 0 | IO.mapRequired("UnitType", Unit.Type); |
187 | 0 | IO.mapOptional("AbbrevTableID", Unit.AbbrevTableID); |
188 | 0 | IO.mapOptional("AbbrOffset", Unit.AbbrOffset); |
189 | 0 | IO.mapOptional("AddrSize", Unit.AddrSize); |
190 | 0 | IO.mapOptional("Entries", Unit.Entries); |
191 | 0 | } |
192 | | |
193 | 0 | void MappingTraits<DWARFYAML::Entry>::mapping(IO &IO, DWARFYAML::Entry &Entry) { |
194 | 0 | IO.mapRequired("AbbrCode", Entry.AbbrCode); |
195 | 0 | IO.mapOptional("Values", Entry.Values); |
196 | 0 | } |
197 | | |
198 | | void MappingTraits<DWARFYAML::FormValue>::mapping( |
199 | 0 | IO &IO, DWARFYAML::FormValue &FormValue) { |
200 | 0 | IO.mapOptional("Value", FormValue.Value); |
201 | 0 | if (!FormValue.CStr.empty() || !IO.outputting()) |
202 | 0 | IO.mapOptional("CStr", FormValue.CStr); |
203 | 0 | if (!FormValue.BlockData.empty() || !IO.outputting()) |
204 | 0 | IO.mapOptional("BlockData", FormValue.BlockData); |
205 | 0 | } |
206 | | |
207 | 0 | void MappingTraits<DWARFYAML::File>::mapping(IO &IO, DWARFYAML::File &File) { |
208 | 0 | IO.mapRequired("Name", File.Name); |
209 | 0 | IO.mapRequired("DirIdx", File.DirIdx); |
210 | 0 | IO.mapRequired("ModTime", File.ModTime); |
211 | 0 | IO.mapRequired("Length", File.Length); |
212 | 0 | } |
213 | | |
214 | | void MappingTraits<DWARFYAML::LineTableOpcode>::mapping( |
215 | 0 | IO &IO, DWARFYAML::LineTableOpcode &LineTableOpcode) { |
216 | 0 | IO.mapRequired("Opcode", LineTableOpcode.Opcode); |
217 | 0 | if (LineTableOpcode.Opcode == dwarf::DW_LNS_extended_op) { |
218 | 0 | IO.mapOptional("ExtLen", LineTableOpcode.ExtLen); |
219 | 0 | IO.mapRequired("SubOpcode", LineTableOpcode.SubOpcode); |
220 | 0 | } |
221 | |
|
222 | 0 | if (!LineTableOpcode.UnknownOpcodeData.empty() || !IO.outputting()) |
223 | 0 | IO.mapOptional("UnknownOpcodeData", LineTableOpcode.UnknownOpcodeData); |
224 | 0 | if (!LineTableOpcode.UnknownOpcodeData.empty() || !IO.outputting()) |
225 | 0 | IO.mapOptional("StandardOpcodeData", LineTableOpcode.StandardOpcodeData); |
226 | 0 | if (!LineTableOpcode.FileEntry.Name.empty() || !IO.outputting()) |
227 | 0 | IO.mapOptional("FileEntry", LineTableOpcode.FileEntry); |
228 | 0 | if (LineTableOpcode.Opcode == dwarf::DW_LNS_advance_line || !IO.outputting()) |
229 | 0 | IO.mapOptional("SData", LineTableOpcode.SData); |
230 | 0 | IO.mapOptional("Data", LineTableOpcode.Data); |
231 | 0 | } |
232 | | |
233 | | void MappingTraits<DWARFYAML::LineTable>::mapping( |
234 | 0 | IO &IO, DWARFYAML::LineTable &LineTable) { |
235 | 0 | IO.mapOptional("Format", LineTable.Format, dwarf::DWARF32); |
236 | 0 | IO.mapOptional("Length", LineTable.Length); |
237 | 0 | IO.mapRequired("Version", LineTable.Version); |
238 | 0 | IO.mapOptional("PrologueLength", LineTable.PrologueLength); |
239 | 0 | IO.mapRequired("MinInstLength", LineTable.MinInstLength); |
240 | 0 | if(LineTable.Version >= 4) |
241 | 0 | IO.mapRequired("MaxOpsPerInst", LineTable.MaxOpsPerInst); |
242 | 0 | IO.mapRequired("DefaultIsStmt", LineTable.DefaultIsStmt); |
243 | 0 | IO.mapRequired("LineBase", LineTable.LineBase); |
244 | 0 | IO.mapRequired("LineRange", LineTable.LineRange); |
245 | 0 | IO.mapOptional("OpcodeBase", LineTable.OpcodeBase); |
246 | 0 | IO.mapOptional("StandardOpcodeLengths", LineTable.StandardOpcodeLengths); |
247 | 0 | IO.mapOptional("IncludeDirs", LineTable.IncludeDirs); |
248 | 0 | IO.mapOptional("Files", LineTable.Files); |
249 | 0 | IO.mapOptional("Opcodes", LineTable.Opcodes); |
250 | 0 | } |
251 | | |
252 | | void MappingTraits<DWARFYAML::SegAddrPair>::mapping( |
253 | 0 | IO &IO, DWARFYAML::SegAddrPair &SegAddrPair) { |
254 | 0 | IO.mapOptional("Segment", SegAddrPair.Segment, 0); |
255 | 0 | IO.mapOptional("Address", SegAddrPair.Address, 0); |
256 | 0 | } |
257 | | |
258 | | void MappingTraits<DWARFYAML::AddrTableEntry>::mapping( |
259 | 0 | IO &IO, DWARFYAML::AddrTableEntry &AddrTable) { |
260 | 0 | IO.mapOptional("Format", AddrTable.Format, dwarf::DWARF32); |
261 | 0 | IO.mapOptional("Length", AddrTable.Length); |
262 | 0 | IO.mapRequired("Version", AddrTable.Version); |
263 | 0 | IO.mapOptional("AddressSize", AddrTable.AddrSize); |
264 | 0 | IO.mapOptional("SegmentSelectorSize", AddrTable.SegSelectorSize, 0); |
265 | 0 | IO.mapOptional("Entries", AddrTable.SegAddrPairs); |
266 | 0 | } |
267 | | |
268 | | void MappingTraits<DWARFYAML::StringOffsetsTable>::mapping( |
269 | 0 | IO &IO, DWARFYAML::StringOffsetsTable &StrOffsetsTable) { |
270 | 0 | IO.mapOptional("Format", StrOffsetsTable.Format, dwarf::DWARF32); |
271 | 0 | IO.mapOptional("Length", StrOffsetsTable.Length); |
272 | 0 | IO.mapOptional("Version", StrOffsetsTable.Version, 5); |
273 | 0 | IO.mapOptional("Padding", StrOffsetsTable.Padding, 0); |
274 | 0 | IO.mapOptional("Offsets", StrOffsetsTable.Offsets); |
275 | 0 | } |
276 | | |
277 | | void MappingTraits<DWARFYAML::DWARFOperation>::mapping( |
278 | 0 | IO &IO, DWARFYAML::DWARFOperation &DWARFOperation) { |
279 | 0 | IO.mapRequired("Operator", DWARFOperation.Operator); |
280 | 0 | IO.mapOptional("Values", DWARFOperation.Values); |
281 | 0 | } |
282 | | |
283 | | void MappingTraits<DWARFYAML::RnglistEntry>::mapping( |
284 | 0 | IO &IO, DWARFYAML::RnglistEntry &RnglistEntry) { |
285 | 0 | IO.mapRequired("Operator", RnglistEntry.Operator); |
286 | 0 | IO.mapOptional("Values", RnglistEntry.Values); |
287 | 0 | } |
288 | | |
289 | | void MappingTraits<DWARFYAML::LoclistEntry>::mapping( |
290 | 0 | IO &IO, DWARFYAML::LoclistEntry &LoclistEntry) { |
291 | 0 | IO.mapRequired("Operator", LoclistEntry.Operator); |
292 | 0 | IO.mapOptional("Values", LoclistEntry.Values); |
293 | 0 | IO.mapOptional("DescriptionsLength", LoclistEntry.DescriptionsLength); |
294 | 0 | IO.mapOptional("Descriptions", LoclistEntry.Descriptions); |
295 | 0 | } |
296 | | |
297 | | template <typename EntryType> |
298 | | void MappingTraits<DWARFYAML::ListEntries<EntryType>>::mapping( |
299 | 0 | IO &IO, DWARFYAML::ListEntries<EntryType> &ListEntries) { |
300 | 0 | IO.mapOptional("Entries", ListEntries.Entries); |
301 | 0 | IO.mapOptional("Content", ListEntries.Content); |
302 | 0 | } Unexecuted instantiation: llvm::yaml::MappingTraits<llvm::DWARFYAML::ListEntries<llvm::DWARFYAML::RnglistEntry> >::mapping(llvm::yaml::IO&, llvm::DWARFYAML::ListEntries<llvm::DWARFYAML::RnglistEntry>&) Unexecuted instantiation: llvm::yaml::MappingTraits<llvm::DWARFYAML::ListEntries<llvm::DWARFYAML::LoclistEntry> >::mapping(llvm::yaml::IO&, llvm::DWARFYAML::ListEntries<llvm::DWARFYAML::LoclistEntry>&) |
303 | | |
304 | | template <typename EntryType> |
305 | | std::string MappingTraits<DWARFYAML::ListEntries<EntryType>>::validate( |
306 | 0 | IO &IO, DWARFYAML::ListEntries<EntryType> &ListEntries) { |
307 | 0 | if (ListEntries.Entries && ListEntries.Content) |
308 | 0 | return "Entries and Content can't be used together"; |
309 | 0 | return ""; |
310 | 0 | } Unexecuted instantiation: llvm::yaml::MappingTraits<llvm::DWARFYAML::ListEntries<llvm::DWARFYAML::RnglistEntry> >::validate(llvm::yaml::IO&, llvm::DWARFYAML::ListEntries<llvm::DWARFYAML::RnglistEntry>&) Unexecuted instantiation: llvm::yaml::MappingTraits<llvm::DWARFYAML::ListEntries<llvm::DWARFYAML::LoclistEntry> >::validate(llvm::yaml::IO&, llvm::DWARFYAML::ListEntries<llvm::DWARFYAML::LoclistEntry>&) |
311 | | |
312 | | template <typename EntryType> |
313 | | void MappingTraits<DWARFYAML::ListTable<EntryType>>::mapping( |
314 | 0 | IO &IO, DWARFYAML::ListTable<EntryType> &ListTable) { |
315 | 0 | IO.mapOptional("Format", ListTable.Format, dwarf::DWARF32); |
316 | 0 | IO.mapOptional("Length", ListTable.Length); |
317 | 0 | IO.mapOptional("Version", ListTable.Version, 5); |
318 | 0 | IO.mapOptional("AddressSize", ListTable.AddrSize); |
319 | 0 | IO.mapOptional("SegmentSelectorSize", ListTable.SegSelectorSize, 0); |
320 | 0 | IO.mapOptional("OffsetEntryCount", ListTable.OffsetEntryCount); |
321 | 0 | IO.mapOptional("Offsets", ListTable.Offsets); |
322 | 0 | IO.mapOptional("Lists", ListTable.Lists); |
323 | 0 | } Unexecuted instantiation: llvm::yaml::MappingTraits<llvm::DWARFYAML::ListTable<llvm::DWARFYAML::RnglistEntry> >::mapping(llvm::yaml::IO&, llvm::DWARFYAML::ListTable<llvm::DWARFYAML::RnglistEntry>&) Unexecuted instantiation: llvm::yaml::MappingTraits<llvm::DWARFYAML::ListTable<llvm::DWARFYAML::LoclistEntry> >::mapping(llvm::yaml::IO&, llvm::DWARFYAML::ListTable<llvm::DWARFYAML::LoclistEntry>&) |
324 | | |
325 | | } // end namespace yaml |
326 | | |
327 | | } // end namespace llvm |