LLVM  10.0.0svn
DWARFYAML.h
Go to the documentation of this file.
1 //===- DWARFYAML.h - DWARF YAMLIO implementation ----------------*- C++ -*-===//
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 /// \file
10 /// This file declares classes for handling the YAML representation
11 /// of DWARF Debug Info.
12 ///
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_OBJECTYAML_DWARFYAML_H
16 #define LLVM_OBJECTYAML_DWARFYAML_H
17 
18 #include "llvm/ADT/StringRef.h"
21 #include <cstdint>
22 #include <vector>
23 
24 namespace llvm {
25 namespace DWARFYAML {
26 
27 struct InitialLength {
29  uint64_t TotalLength64;
30 
31  bool isDWARF64() const { return TotalLength == UINT32_MAX; }
32 
33  uint64_t getLength() const {
34  return isDWARF64() ? TotalLength64 : TotalLength;
35  }
36 
37  void setLength(uint64_t Len) {
38  if (Len >= (uint64_t)UINT32_MAX) {
39  TotalLength64 = Len;
40  TotalLength = UINT32_MAX;
41  } else {
42  TotalLength = Len;
43  }
44  }
45 };
46 
50  llvm::yaml::Hex64 Value; // Some DWARF5 attributes have values
51 };
52 
53 struct Abbrev {
54  llvm::yaml::Hex32 Code;
57  std::vector<AttributeAbbrev> Attributes;
58 };
59 
61  llvm::yaml::Hex64 Address;
62  uint64_t Length;
63 };
64 
65 struct ARange {
67  uint16_t Version;
69  uint8_t AddrSize;
70  uint8_t SegSize;
71  std::vector<ARangeDescriptor> Descriptors;
72 };
73 
74 struct PubEntry {
75  llvm::yaml::Hex32 DieOffset;
76  llvm::yaml::Hex8 Descriptor;
78 };
79 
80 struct PubSection {
82  uint16_t Version;
85  bool IsGNUStyle = false;
86  std::vector<PubEntry> Entries;
87 };
88 
89 struct FormValue {
90  llvm::yaml::Hex64 Value;
92  std::vector<llvm::yaml::Hex8> BlockData;
93 };
94 
95 struct Entry {
96  llvm::yaml::Hex32 AbbrCode;
97  std::vector<FormValue> Values;
98 };
99 
100 struct Unit {
102  uint16_t Version;
103  llvm::dwarf::UnitType Type; // Added in DWARF 5
105  uint8_t AddrSize;
106  std::vector<Entry> Entries;
107 };
108 
109 struct File {
111  uint64_t DirIdx;
112  uint64_t ModTime;
113  uint64_t Length;
114 };
115 
118  uint64_t ExtLen;
120  uint64_t Data;
121  int64_t SData;
123  std::vector<llvm::yaml::Hex8> UnknownOpcodeData;
124  std::vector<llvm::yaml::Hex64> StandardOpcodeData;
125 };
126 
127 struct LineTable {
129  uint16_t Version;
130  uint64_t PrologueLength;
131  uint8_t MinInstLength;
132  uint8_t MaxOpsPerInst;
133  uint8_t DefaultIsStmt;
134  uint8_t LineBase;
135  uint8_t LineRange;
136  uint8_t OpcodeBase;
137  std::vector<uint8_t> StandardOpcodeLengths;
138  std::vector<StringRef> IncludeDirs;
139  std::vector<File> Files;
140  std::vector<LineTableOpcode> Opcodes;
141 };
142 
143 struct Data {
145  std::vector<Abbrev> AbbrevDecls;
146  std::vector<StringRef> DebugStrings;
147  std::vector<ARange> ARanges;
150 
153 
154  std::vector<Unit> CompileUnits;
155 
156  std::vector<LineTable> DebugLines;
157 
158  bool isEmpty() const;
159 };
160 
161 } // end namespace DWARFYAML
162 } // end namespace llvm
163 
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)
177 
178 namespace llvm {
179 namespace yaml {
180 
181 template <> struct MappingTraits<DWARFYAML::Data> {
182  static void mapping(IO &IO, DWARFYAML::Data &DWARF);
183 };
184 
185 template <> struct MappingTraits<DWARFYAML::Abbrev> {
186  static void mapping(IO &IO, DWARFYAML::Abbrev &Abbrev);
187 };
188 
189 template <> struct MappingTraits<DWARFYAML::AttributeAbbrev> {
190  static void mapping(IO &IO, DWARFYAML::AttributeAbbrev &AttAbbrev);
191 };
192 
193 template <> struct MappingTraits<DWARFYAML::ARangeDescriptor> {
194  static void mapping(IO &IO, DWARFYAML::ARangeDescriptor &Descriptor);
195 };
196 
197 template <> struct MappingTraits<DWARFYAML::ARange> {
198  static void mapping(IO &IO, DWARFYAML::ARange &Range);
199 };
200 
201 template <> struct MappingTraits<DWARFYAML::PubEntry> {
202  static void mapping(IO &IO, DWARFYAML::PubEntry &Entry);
203 };
204 
205 template <> struct MappingTraits<DWARFYAML::PubSection> {
206  static void mapping(IO &IO, DWARFYAML::PubSection &Section);
207 };
208 
209 template <> struct MappingTraits<DWARFYAML::Unit> {
210  static void mapping(IO &IO, DWARFYAML::Unit &Unit);
211 };
212 
213 template <> struct MappingTraits<DWARFYAML::Entry> {
214  static void mapping(IO &IO, DWARFYAML::Entry &Entry);
215 };
216 
217 template <> struct MappingTraits<DWARFYAML::FormValue> {
218  static void mapping(IO &IO, DWARFYAML::FormValue &FormValue);
219 };
220 
221 template <> struct MappingTraits<DWARFYAML::File> {
222  static void mapping(IO &IO, DWARFYAML::File &File);
223 };
224 
225 template <> struct MappingTraits<DWARFYAML::LineTableOpcode> {
226  static void mapping(IO &IO, DWARFYAML::LineTableOpcode &LineTableOpcode);
227 };
228 
229 template <> struct MappingTraits<DWARFYAML::LineTable> {
230  static void mapping(IO &IO, DWARFYAML::LineTable &LineTable);
231 };
232 
233 template <> struct MappingTraits<DWARFYAML::InitialLength> {
234  static void mapping(IO &IO, DWARFYAML::InitialLength &DWARF);
235 };
236 
237 #define HANDLE_DW_TAG(unused, name, unused2, unused3, unused4) \
238  io.enumCase(value, "DW_TAG_" #name, dwarf::DW_TAG_##name);
239 
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);
244  }
245 };
246 
247 #define HANDLE_DW_LNS(unused, name) \
248  io.enumCase(value, "DW_LNS_" #name, dwarf::DW_LNS_##name);
249 
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);
254  }
255 };
256 
257 #define HANDLE_DW_LNE(unused, name) \
258  io.enumCase(value, "DW_LNE_" #name, dwarf::DW_LNE_##name);
259 
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);
264  }
265 };
266 
267 #define HANDLE_DW_AT(unused, name, unused2, unused3) \
268  io.enumCase(value, "DW_AT_" #name, dwarf::DW_AT_##name);
269 
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);
274  }
275 };
276 
277 #define HANDLE_DW_FORM(unused, name, unused2, unused3) \
278  io.enumCase(value, "DW_FORM_" #name, dwarf::DW_FORM_##name);
279 
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);
284  }
285 };
286 
287 #define HANDLE_DW_UT(unused, name) \
288  io.enumCase(value, "DW_UT_" #name, dwarf::DW_UT_##name);
289 
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);
294  }
295 };
296 
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);
302  }
303 };
304 
305 } // end namespace yaml
306 } // end namespace llvm
307 
308 #endif // LLVM_OBJECTYAML_DWARFYAML_H
llvm::dwarf::Constants Children
Definition: DWARFYAML.h:56
PubSection PubNames
Definition: DWARFYAML.h:148
std::vector< AttributeAbbrev > Attributes
Definition: DWARFYAML.h:57
LineNumberOps
Line Number Standard Opcode Encodings.
Definition: Dwarf.h:274
This class represents lattice values for constants.
Definition: AllocatorList.h:23
llvm::dwarf::UnitType Type
Definition: DWARFYAML.h:103
dwarf::LineNumberExtendedOps SubOpcode
Definition: DWARFYAML.h:119
dwarf::LineNumberOps Opcode
Definition: DWARFYAML.h:117
Attribute
Attributes.
Definition: Dwarf.h:102
static void enumeration(IO &io, dwarf::LineNumberOps &value)
Definition: DWARFYAML.h:251
std::vector< Abbrev > AbbrevDecls
Definition: DWARFYAML.h:145
InitialLength Length
Definition: DWARFYAML.h:66
static void enumeration(IO &io, dwarf::LineNumberExtendedOps &value)
Definition: DWARFYAML.h:261
std::vector< uint8_t > StandardOpcodeLengths
Definition: DWARFYAML.h:137
std::vector< PubEntry > Entries
Definition: DWARFYAML.h:86
std::vector< ARangeDescriptor > Descriptors
Definition: DWARFYAML.h:71
static void enumeration(IO &io, dwarf::Form &value)
Definition: DWARFYAML.h:281
uint64_t getLength() const
Definition: DWARFYAML.h:33
PubSection GNUPubNames
Definition: DWARFYAML.h:151
std::vector< ARange > ARanges
Definition: DWARFYAML.h:147
std::vector< Unit > CompileUnits
Definition: DWARFYAML.h:154
std::vector< llvm::yaml::Hex8 > BlockData
Definition: DWARFYAML.h:92
static void enumeration(IO &io, dwarf::UnitType &value)
Definition: DWARFYAML.h:291
llvm::yaml::Hex32 Code
Definition: DWARFYAML.h:54
InitialLength Length
Definition: DWARFYAML.h:101
std::vector< File > Files
Definition: DWARFYAML.h:139
llvm::yaml::Hex32 DieOffset
Definition: DWARFYAML.h:75
std::vector< LineTable > DebugLines
Definition: DWARFYAML.h:156
Instrumentation for Order File
static void enumeration(IO &io, dwarf::Tag &value)
Definition: DWARFYAML.h:241
std::vector< StringRef > IncludeDirs
Definition: DWARFYAML.h:138
std::vector< Entry > Entries
Definition: DWARFYAML.h:106
llvm::yaml::Hex64 Value
Definition: DWARFYAML.h:90
std::vector< FormValue > Values
Definition: DWARFYAML.h:97
llvm::yaml::Hex8 Descriptor
Definition: DWARFYAML.h:76
LineNumberExtendedOps
Line Number Extended Opcode Encodings.
Definition: Dwarf.h:280
UnitType
Constants for unit types in DWARF v5.
Definition: Dwarf.h:366
llvm::dwarf::Attribute Attribute
Definition: DWARFYAML.h:48
PubSection PubTypes
Definition: DWARFYAML.h:149
std::vector< StringRef > DebugStrings
Definition: DWARFYAML.h:146
llvm::yaml::Hex32 AbbrCode
Definition: DWARFYAML.h:96
PubSection GNUPubTypes
Definition: DWARFYAML.h:152
This file contains constants used for implementing Dwarf debug support.
std::vector< llvm::yaml::Hex8 > UnknownOpcodeData
Definition: DWARFYAML.h:123
static void enumeration(IO &io, dwarf::Attribute &value)
Definition: DWARFYAML.h:271
std::vector< llvm::yaml::Hex64 > StandardOpcodeData
Definition: DWARFYAML.h:124
std::vector< LineTableOpcode > Opcodes
Definition: DWARFYAML.h:140
void setLength(uint64_t Len)
Definition: DWARFYAML.h:37
llvm::dwarf::Tag Tag
Definition: DWARFYAML.h:55
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:48
static void enumeration(IO &io, dwarf::Constants &value)
Definition: DWARFYAML.h:298