1 //===- DWARFYAML.h - DWARF YAMLIO implementation ----------------*- C++ -*-===//
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 //===----------------------------------------------------------------------===//
10 /// This file declares classes for handling the YAML representation
11 /// of DWARF Debug Info.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_OBJECTYAML_DWARFYAML_H
16 #define LLVM_OBJECTYAML_DWARFYAML_H
18 #include "llvm/ADT/StringRef.h"
19 #include "llvm/BinaryFormat/Dwarf.h"
20 #include "llvm/Support/YAMLTraits.h"
27 struct InitialLength {
29 uint64_t TotalLength64;
31 bool isDWARF64() const { return TotalLength == UINT32_MAX; }
33 uint64_t getLength() const {
34 return isDWARF64() ? TotalLength64 : TotalLength;
37 void setLength(uint64_t Len) {
38 if (Len >= (uint64_t)UINT32_MAX) {
40 TotalLength = UINT32_MAX;
47 struct AttributeAbbrev {
48 llvm::dwarf::Attribute Attribute;
49 llvm::dwarf::Form Form;
50 llvm::yaml::Hex64 Value; // Some DWARF5 attributes have values
54 llvm::yaml::Hex32 Code;
56 llvm::dwarf::Constants Children;
57 std::vector<AttributeAbbrev> Attributes;
60 struct ARangeDescriptor {
61 llvm::yaml::Hex64 Address;
71 std::vector<ARangeDescriptor> Descriptors;
75 llvm::yaml::Hex32 DieOffset;
76 llvm::yaml::Hex8 Descriptor;
85 bool IsGNUStyle = false;
86 std::vector<PubEntry> Entries;
90 llvm::yaml::Hex64 Value;
92 std::vector<llvm::yaml::Hex8> BlockData;
96 llvm::yaml::Hex32 AbbrCode;
97 std::vector<FormValue> Values;
101 InitialLength Length;
103 llvm::dwarf::UnitType Type; // Added in DWARF 5
106 std::vector<Entry> Entries;
116 struct LineTableOpcode {
117 dwarf::LineNumberOps Opcode;
119 dwarf::LineNumberExtendedOps SubOpcode;
123 std::vector<llvm::yaml::Hex8> UnknownOpcodeData;
124 std::vector<llvm::yaml::Hex64> StandardOpcodeData;
128 InitialLength Length;
130 uint64_t PrologueLength;
131 uint8_t MinInstLength;
132 uint8_t MaxOpsPerInst;
133 uint8_t DefaultIsStmt;
137 std::vector<uint8_t> StandardOpcodeLengths;
138 std::vector<StringRef> IncludeDirs;
139 std::vector<File> Files;
140 std::vector<LineTableOpcode> Opcodes;
145 std::vector<Abbrev> AbbrevDecls;
146 std::vector<StringRef> DebugStrings;
147 std::vector<ARange> ARanges;
151 PubSection GNUPubNames;
152 PubSection GNUPubTypes;
154 std::vector<Unit> CompileUnits;
156 std::vector<LineTable> DebugLines;
158 bool isEmpty() const;
161 } // end namespace DWARFYAML
162 } // end namespace llvm
164 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::yaml::Hex64)
165 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::yaml::Hex8)
166 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::AttributeAbbrev)
167 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::Abbrev)
168 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::ARangeDescriptor)
169 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::ARange)
170 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::PubEntry)
171 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::Unit)
172 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::FormValue)
173 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::Entry)
174 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::File)
175 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::LineTable)
176 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::LineTableOpcode)
181 template <> struct MappingTraits<DWARFYAML::Data> {
182 static void mapping(IO &IO, DWARFYAML::Data &DWARF);
185 template <> struct MappingTraits<DWARFYAML::Abbrev> {
186 static void mapping(IO &IO, DWARFYAML::Abbrev &Abbrev);
189 template <> struct MappingTraits<DWARFYAML::AttributeAbbrev> {
190 static void mapping(IO &IO, DWARFYAML::AttributeAbbrev &AttAbbrev);
193 template <> struct MappingTraits<DWARFYAML::ARangeDescriptor> {
194 static void mapping(IO &IO, DWARFYAML::ARangeDescriptor &Descriptor);
197 template <> struct MappingTraits<DWARFYAML::ARange> {
198 static void mapping(IO &IO, DWARFYAML::ARange &Range);
201 template <> struct MappingTraits<DWARFYAML::PubEntry> {
202 static void mapping(IO &IO, DWARFYAML::PubEntry &Entry);
205 template <> struct MappingTraits<DWARFYAML::PubSection> {
206 static void mapping(IO &IO, DWARFYAML::PubSection &Section);
209 template <> struct MappingTraits<DWARFYAML::Unit> {
210 static void mapping(IO &IO, DWARFYAML::Unit &Unit);
213 template <> struct MappingTraits<DWARFYAML::Entry> {
214 static void mapping(IO &IO, DWARFYAML::Entry &Entry);
217 template <> struct MappingTraits<DWARFYAML::FormValue> {
218 static void mapping(IO &IO, DWARFYAML::FormValue &FormValue);
221 template <> struct MappingTraits<DWARFYAML::File> {
222 static void mapping(IO &IO, DWARFYAML::File &File);
225 template <> struct MappingTraits<DWARFYAML::LineTableOpcode> {
226 static void mapping(IO &IO, DWARFYAML::LineTableOpcode &LineTableOpcode);
229 template <> struct MappingTraits<DWARFYAML::LineTable> {
230 static void mapping(IO &IO, DWARFYAML::LineTable &LineTable);
233 template <> struct MappingTraits<DWARFYAML::InitialLength> {
234 static void mapping(IO &IO, DWARFYAML::InitialLength &DWARF);
237 #define HANDLE_DW_TAG(unused, name, unused2, unused3) \
238 io.enumCase(value, "DW_TAG_" #name, dwarf::DW_TAG_##name);
240 template <> struct ScalarEnumerationTraits<dwarf::Tag> {
241 static void enumeration(IO &io, dwarf::Tag &value) {
242 #include "llvm/BinaryFormat/Dwarf.def"
243 io.enumFallback<Hex16>(value);
247 #define HANDLE_DW_LNS(unused, name) \
248 io.enumCase(value, "DW_LNS_" #name, dwarf::DW_LNS_##name);
250 template <> struct ScalarEnumerationTraits<dwarf::LineNumberOps> {
251 static void enumeration(IO &io, dwarf::LineNumberOps &value) {
252 #include "llvm/BinaryFormat/Dwarf.def"
253 io.enumFallback<Hex8>(value);
257 #define HANDLE_DW_LNE(unused, name) \
258 io.enumCase(value, "DW_LNE_" #name, dwarf::DW_LNE_##name);
260 template <> struct ScalarEnumerationTraits<dwarf::LineNumberExtendedOps> {
261 static void enumeration(IO &io, dwarf::LineNumberExtendedOps &value) {
262 #include "llvm/BinaryFormat/Dwarf.def"
263 io.enumFallback<Hex16>(value);
267 #define HANDLE_DW_AT(unused, name, unused2, unused3) \
268 io.enumCase(value, "DW_AT_" #name, dwarf::DW_AT_##name);
270 template <> struct ScalarEnumerationTraits<dwarf::Attribute> {
271 static void enumeration(IO &io, dwarf::Attribute &value) {
272 #include "llvm/BinaryFormat/Dwarf.def"
273 io.enumFallback<Hex16>(value);
277 #define HANDLE_DW_FORM(unused, name, unused2, unused3) \
278 io.enumCase(value, "DW_FORM_" #name, dwarf::DW_FORM_##name);
280 template <> struct ScalarEnumerationTraits<dwarf::Form> {
281 static void enumeration(IO &io, dwarf::Form &value) {
282 #include "llvm/BinaryFormat/Dwarf.def"
283 io.enumFallback<Hex16>(value);
287 #define HANDLE_DW_UT(unused, name) \
288 io.enumCase(value, "DW_UT_" #name, dwarf::DW_UT_##name);
290 template <> struct ScalarEnumerationTraits<dwarf::UnitType> {
291 static void enumeration(IO &io, dwarf::UnitType &value) {
292 #include "llvm/BinaryFormat/Dwarf.def"
293 io.enumFallback<Hex8>(value);
297 template <> struct ScalarEnumerationTraits<dwarf::Constants> {
298 static void enumeration(IO &io, dwarf::Constants &value) {
299 io.enumCase(value, "DW_CHILDREN_no", dwarf::DW_CHILDREN_no);
300 io.enumCase(value, "DW_CHILDREN_yes", dwarf::DW_CHILDREN_yes);
301 io.enumFallback<Hex16>(value);
305 } // end namespace yaml
306 } // end namespace llvm
308 #endif // LLVM_OBJECTYAML_DWARFYAML_H