LLVM  4.0.0
Dwarf.h
Go to the documentation of this file.
1 //===-- llvm/Support/Dwarf.h ---Dwarf Constants------------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // \file
11 // \brief This file contains constants used for implementing Dwarf
12 // debug support.
13 //
14 // For details on the Dwarf specfication see the latest DWARF Debugging
15 // Information Format standard document on http://www.dwarfstd.org. This
16 // file often includes support for non-released standard features.
17 //
18 //===----------------------------------------------------------------------===//
19 
20 #ifndef LLVM_SUPPORT_DWARF_H
21 #define LLVM_SUPPORT_DWARF_H
22 
23 #include "llvm/Support/Compiler.h"
24 #include "llvm/Support/DataTypes.h"
25 
26 namespace llvm {
27 class StringRef;
28 
29 namespace dwarf {
30 
31 //===----------------------------------------------------------------------===//
32 // Dwarf constants as gleaned from the DWARF Debugging Information Format V.4
33 // reference manual http://www.dwarfstd.org/.
34 //
35 
36 // Do not mix the following two enumerations sets. DW_TAG_invalid changes the
37 // enumeration base type.
38 
40  // LLVM mock tags (see also llvm/Support/Dwarf.def).
41  DW_TAG_invalid = ~0U, // Tag for invalid results.
42  DW_VIRTUALITY_invalid = ~0U, // Virtuality for invalid results.
43  DW_MACINFO_invalid = ~0U, // Macinfo type for invalid results.
44 
45  // Other constants.
46  DWARF_VERSION = 4, // Default dwarf version we output.
47  DW_PUBTYPES_VERSION = 2, // Section version number for .debug_pubtypes.
48  DW_PUBNAMES_VERSION = 2, // Section version number for .debug_pubnames.
49  DW_ARANGES_VERSION = 2 // Section version number for .debug_aranges.
50 };
51 
52 // Special ID values that distinguish a CIE from a FDE in DWARF CFI.
53 // Not inside an enum because a 64-bit value is needed.
54 const uint32_t DW_CIE_ID = UINT32_MAX;
55 const uint64_t DW64_CIE_ID = UINT64_MAX;
56 
57 enum Tag : uint16_t {
58 #define HANDLE_DW_TAG(ID, NAME) DW_TAG_##NAME = ID,
59 #include "llvm/Support/Dwarf.def"
60  DW_TAG_lo_user = 0x4080,
61  DW_TAG_hi_user = 0xffff,
62  DW_TAG_user_base = 0x1000 // Recommended base for user tags.
63 };
64 
65 inline bool isType(Tag T) {
66  switch (T) {
67  case DW_TAG_array_type:
68  case DW_TAG_class_type:
69  case DW_TAG_interface_type:
70  case DW_TAG_enumeration_type:
71  case DW_TAG_pointer_type:
72  case DW_TAG_reference_type:
73  case DW_TAG_rvalue_reference_type:
74  case DW_TAG_string_type:
75  case DW_TAG_structure_type:
76  case DW_TAG_subroutine_type:
77  case DW_TAG_union_type:
78  case DW_TAG_ptr_to_member_type:
79  case DW_TAG_set_type:
80  case DW_TAG_subrange_type:
81  case DW_TAG_base_type:
82  case DW_TAG_const_type:
83  case DW_TAG_file_type:
84  case DW_TAG_packed_type:
85  case DW_TAG_volatile_type:
86  case DW_TAG_typedef:
87  return true;
88  default:
89  return false;
90  }
91 }
92 
93 /// Attributes.
94 enum Attribute : uint16_t {
95 #define HANDLE_DW_AT(ID, NAME) DW_AT_##NAME = ID,
96 #include "llvm/Support/Dwarf.def"
97  DW_AT_lo_user = 0x2000,
98  DW_AT_hi_user = 0x3fff,
99 };
100 
101 enum Form : uint16_t {
102 #define HANDLE_DW_FORM(ID, NAME) DW_FORM_##NAME = ID,
103 #include "llvm/Support/Dwarf.def"
104  DW_FORM_lo_user = 0x1f00, ///< Not specified by DWARF.
105 };
106 
108 #define HANDLE_DW_OP(ID, NAME) DW_OP_##NAME = ID,
109 #include "llvm/Support/Dwarf.def"
112  DW_OP_LLVM_fragment = 0x1000 ///< Only used in LLVM metadata.
113 };
114 
115 enum TypeKind {
116 #define HANDLE_DW_ATE(ID, NAME) DW_ATE_##NAME = ID,
117 #include "llvm/Support/Dwarf.def"
120 };
121 
123  // Decimal sign attribute values
129 };
130 
132  // Endianity attribute values
134  DW_END_big = 0x01,
138 };
139 
141  // Accessibility codes
145 };
146 
148  // Visibility codes
149  DW_VIS_local = 0x01,
152 };
153 
155 #define HANDLE_DW_VIRTUALITY(ID, NAME) DW_VIRTUALITY_##NAME = ID,
156 #include "llvm/Support/Dwarf.def"
158 };
159 
161 #define HANDLE_DW_DEFAULTED(ID, NAME) DW_DEFAULTED_##NAME = ID,
162 #include "llvm/Support/Dwarf.def"
164 };
165 
167 #define HANDLE_DW_LANG(ID, NAME) DW_LANG_##NAME = ID,
168 #include "llvm/Support/Dwarf.def"
169  DW_LANG_lo_user = 0x8000,
171 };
172 
174  // Identifier case codes
179 };
180 
182  // Calling convention codes
183 #define HANDLE_DW_CC(ID, NAME) DW_CC_##NAME = ID,
184 #include "llvm/Support/Dwarf.def"
187 };
188 
190  // Inline codes
195 };
196 
198  // Array ordering
201 };
202 
204  // Discriminant descriptor values
205  DW_DSC_label = 0x00,
207 };
208 
209 /// Line Number Standard Opcode Encodings.
210 enum LineNumberOps : uint8_t {
211 #define HANDLE_DW_LNS(ID, NAME) DW_LNS_##NAME = ID,
212 #include "llvm/Support/Dwarf.def"
213 };
214 
215 /// Line Number Extended Opcode Encodings.
217 #define HANDLE_DW_LNE(ID, NAME) DW_LNE_##NAME = ID,
218 #include "llvm/Support/Dwarf.def"
221 };
222 
224 #define HANDLE_DW_LNCT(ID, NAME) DW_DEFAULTED_##NAME = ID,
225 #include "llvm/Support/Dwarf.def"
226  DW_LNCT_lo_user = 0x2000,
227  DW_LNCT_hi_user = 0x3fff,
228 };
229 
231  // Macinfo Type Encodings
237 };
238 
239 /// DWARF v5 macro information entry type encodings.
241 #define HANDLE_DW_MACRO(ID, NAME) DW_MACRO_##NAME = ID,
242 #include "llvm/Support/Dwarf.def"
245 };
246 
247 /// DWARF v5 range list entry encoding values.
249 #define HANDLE_DW_RLE(ID, NAME) DW_RLE_##NAME = ID,
250 #include "llvm/Support/Dwarf.def"
251 };
252 
253 
254 /// Call frame instruction encodings.
256 #define HANDLE_DW_CFA(ID, NAME) DW_CFA_##NAME = ID,
257 #include "llvm/Support/Dwarf.def"
259 
262 };
263 
264 enum Constants {
265  // Children flag
268 
286 };
287 
288 /// Constants for location lists in DWARF v5.
289 enum LocationListEntry : unsigned char {
299 };
300 
301 /// Constants for the DW_APPLE_PROPERTY_attributes attribute.
302 /// Keep this list in sync with clang's DeclSpec.h ObjCPropertyAttributeKind!
304 #define HANDLE_DW_APPLE_PROPERTY(ID, NAME) DW_APPLE_PROPERTY_##NAME = ID,
305 #include "llvm/Support/Dwarf.def"
306 };
307 
308 // Constants for the DWARF5 Accelerator Table Proposal
310  // Data layout descriptors.
311  DW_ATOM_null = 0u, // Marker as the end of a list of atoms.
312  DW_ATOM_die_offset = 1u, // DIE offset in the debug_info section.
313  DW_ATOM_cu_offset = 2u, // Offset of the compile unit header that contains the
314  // item in question.
315  DW_ATOM_die_tag = 3u, // A tag entry.
316  DW_ATOM_type_flags = 4u, // Set of flags for a type.
317 
318  // DW_ATOM_type_flags values.
319 
320  // Always set for C++, only set for ObjC if this is the @implementation for a
321  // class.
323 
324  // Hash functions.
325 
326  // Daniel J. Bernstein hash.
328 };
329 
330 // Constants for the GNU pubnames/pubtypes extensions supporting gdb index.
340 };
341 
345 };
346 
347 /// \defgroup DwarfConstantsDumping Dwarf constants dumping functions
348 ///
349 /// All these functions map their argument's value back to the
350 /// corresponding enumerator name or return nullptr if the value isn't
351 /// known.
352 ///
353 /// @{
354 StringRef TagString(unsigned Tag);
355 StringRef ChildrenString(unsigned Children);
357 StringRef FormEncodingString(unsigned Encoding);
358 StringRef OperationEncodingString(unsigned Encoding);
359 StringRef AttributeEncodingString(unsigned Encoding);
360 StringRef DecimalSignString(unsigned Sign);
361 StringRef EndianityString(unsigned Endian);
362 StringRef AccessibilityString(unsigned Access);
364 StringRef VirtualityString(unsigned Virtuality);
366 StringRef CaseString(unsigned Case);
367 StringRef ConventionString(unsigned Convention);
368 StringRef InlineCodeString(unsigned Code);
369 StringRef ArrayOrderString(unsigned Order);
370 StringRef DiscriminantString(unsigned Discriminant);
371 StringRef LNStandardString(unsigned Standard);
372 StringRef LNExtendedString(unsigned Encoding);
373 StringRef MacinfoString(unsigned Encoding);
374 StringRef CallFrameString(unsigned Encoding);
376 StringRef AtomTypeString(unsigned Atom);
379 /// @}
380 
381 /// \defgroup DwarfConstantsParsing Dwarf constants parsing functions
382 ///
383 /// These functions map their strings back to the corresponding enumeration
384 /// value or return 0 if there is none, except for these exceptions:
385 ///
386 /// \li \a getTag() returns \a DW_TAG_invalid on invalid input.
387 /// \li \a getVirtuality() returns \a DW_VIRTUALITY_invalid on invalid input.
388 /// \li \a getMacinfo() returns \a DW_MACINFO_invalid on invalid input.
389 ///
390 /// @{
391 unsigned getTag(StringRef TagString);
396 unsigned getAttributeEncoding(StringRef EncodingString);
398 /// @}
399 
400 /// \brief Returns the symbolic string representing Val when used as a value
401 /// for attribute Attr.
402 StringRef AttributeValueString(uint16_t Attr, unsigned Val);
403 
404 /// \brief Decsribes an entry of the various gnu_pub* debug sections.
405 ///
406 /// The gnu_pub* kind looks like:
407 ///
408 /// 0-3 reserved
409 /// 4-6 symbol kind
410 /// 7 0 == global, 1 == static
411 ///
412 /// A gdb_index descriptor includes the above kind, shifted 24 bits up with the
413 /// offset of the cu within the debug_info section stored in those 24 bits.
418  : Kind(Kind), Linkage(Linkage) {}
420  : Kind(Kind), Linkage(GIEL_EXTERNAL) {}
421  explicit PubIndexEntryDescriptor(uint8_t Value)
422  : Kind(static_cast<GDBIndexEntryKind>((Value & KIND_MASK) >>
423  KIND_OFFSET)),
424  Linkage(static_cast<GDBIndexEntryLinkage>((Value & LINKAGE_MASK) >>
425  LINKAGE_OFFSET)) {}
426  uint8_t toBits() const {
427  return Kind << KIND_OFFSET | Linkage << LINKAGE_OFFSET;
428  }
429 
430 private:
431  enum {
432  KIND_OFFSET = 4,
433  KIND_MASK = 7 << KIND_OFFSET,
434  LINKAGE_OFFSET = 7,
435  LINKAGE_MASK = 1 << LINKAGE_OFFSET
436  };
437 };
438 
439 /// Constants that define the DWARF format as 32 or 64 bit.
441 
442 } // End of namespace dwarf
443 
444 } // End of namespace llvm
445 
446 #endif
DecimalSignEncoding
Definition: Dwarf.h:122
MacinfoRecordType
Definition: Dwarf.h:230
LocationAtom
Definition: Dwarf.h:107
StringRef ApplePropertyString(unsigned)
Definition: Dwarf.cpp:296
PubIndexEntryDescriptor(GDBIndexEntryKind Kind)
Definition: Dwarf.h:419
LineNumberOps
Line Number Standard Opcode Encodings.
Definition: Dwarf.h:210
Not specified by DWARF.
Definition: Dwarf.h:104
StringRef AtomTypeString(unsigned Atom)
Definition: Dwarf.cpp:307
Attribute
Attributes.
Definition: Dwarf.h:94
StringRef LNExtendedString(unsigned Encoding)
Definition: Dwarf.cpp:251
StringRef LNStandardString(unsigned Standard)
Definition: Dwarf.cpp:240
GDBIndexEntryKind
Definition: Dwarf.h:331
ArrayDimensionOrdering
Definition: Dwarf.h:197
ELFYAML::ELF_STV Visibility
Definition: ELFYAML.cpp:661
unsigned getVirtuality(StringRef VirtualityString)
Definition: Dwarf.cpp:160
InlineAttribute
Definition: Dwarf.h:189
CallFrameInfo
Call frame instruction encodings.
Definition: Dwarf.h:255
EndianityEncoding
Definition: Dwarf.h:131
LLVMConstants
Definition: Dwarf.h:39
StringRef FormEncodingString(unsigned Encoding)
Definition: Dwarf.cpp:58
Only used in LLVM metadata.
Definition: Dwarf.h:112
PubIndexEntryDescriptor(uint8_t Value)
Definition: Dwarf.h:421
Decsribes an entry of the various gnu_pub* debug sections.
Definition: Dwarf.h:414
MacroEntryType
DWARF v5 macro information entry type encodings.
Definition: Dwarf.h:240
StringRef AttributeString(unsigned Attribute)
Definition: Dwarf.cpp:47
StringRef LanguageString(unsigned Language)
Definition: Dwarf.cpp:168
AccessAttribute
Definition: Dwarf.h:140
StringRef DecimalSignString(unsigned Sign)
Definition: Dwarf.cpp:108
StringRef AttributeValueString(uint16_t Attr, unsigned Val)
Returns the symbolic string representing Val when used as a value for attribute Attr.
Definition: Dwarf.cpp:356
StringRef GDBIndexEntryKindString(GDBIndexEntryKind Kind)
Definition: Dwarf.cpp:323
StringRef AccessibilityString(unsigned Access)
Definition: Dwarf.cpp:130
StringRef EndianityString(unsigned Endian)
Definition: Dwarf.cpp:119
StringRef AttributeEncodingString(unsigned Encoding)
Definition: Dwarf.cpp:90
StringRef CallFrameString(unsigned Encoding)
Definition: Dwarf.cpp:285
unsigned getCallingConvention(StringRef LanguageString)
Definition: Dwarf.cpp:207
DwarfFormat
Constants that define the DWARF format as 32 or 64 bit.
Definition: Dwarf.h:440
SourceLanguage
Definition: Dwarf.h:166
unsigned getOperationEncoding(StringRef OperationEncodingString)
Definition: Dwarf.cpp:82
StringRef DiscriminantString(unsigned Discriminant)
Definition: Dwarf.cpp:232
StringRef ArrayOrderString(unsigned Order)
Definition: Dwarf.cpp:224
StringRef GDBIndexEntryLinkageString(GDBIndexEntryLinkage Linkage)
Definition: Dwarf.cpp:346
GDBIndexEntryLinkage Linkage
Definition: Dwarf.h:416
unsigned getLanguage(StringRef LanguageString)
Definition: Dwarf.cpp:179
VisibilityAttribute
Definition: Dwarf.h:147
LineNumberExtendedOps
Line Number Extended Opcode Encodings.
Definition: Dwarf.h:216
StringRef VirtualityString(unsigned Virtuality)
Definition: Dwarf.cpp:149
StringRef OperationEncodingString(unsigned Encoding)
Definition: Dwarf.cpp:69
const uint32_t DW_CIE_ID
Definition: Dwarf.h:54
unsigned getTag(StringRef TagString)
Definition: Dwarf.cpp:32
StringRef CaseString(unsigned Case)
Definition: Dwarf.cpp:186
ApplePropertyAttributes
Constants for the DW_APPLE_PROPERTY_attributes attribute.
Definition: Dwarf.h:303
AcceleratorTable
Definition: Dwarf.h:309
LocationListEntry
Constants for location lists in DWARF v5.
Definition: Dwarf.h:289
bool isType(Tag T)
Definition: Dwarf.h:65
PubIndexEntryDescriptor(GDBIndexEntryKind Kind, GDBIndexEntryLinkage Linkage)
Definition: Dwarf.h:417
StringRef VisibilityString(unsigned Visibility)
Definition: Dwarf.cpp:140
RangeListEntries
DWARF v5 range list entry encoding values.
Definition: Dwarf.h:248
StringRef TagString(unsigned Tag)
Definition: Dwarf.cpp:21
StringRef InlineCodeString(unsigned Code)
Definition: Dwarf.cpp:214
StringRef ConventionString(unsigned Convention)
Definition: Dwarf.cpp:196
unsigned getMacinfo(StringRef MacinfoString)
Definition: Dwarf.cpp:275
StringRef ChildrenString(unsigned Children)
Definition: Dwarf.cpp:39
const unsigned Kind
LinerNumberEntryFormat
Definition: Dwarf.h:223
CallingConvention
Definition: Dwarf.h:181
VirtualityAttribute
Definition: Dwarf.h:154
LLVM Value Representation.
Definition: Value.h:71
unsigned getAttributeEncoding(StringRef EncodingString)
Definition: Dwarf.cpp:101
GDBIndexEntryLinkage
Definition: Dwarf.h:342
DiscriminantList
Definition: Dwarf.h:203
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:47
StringRef MacinfoString(unsigned Encoding)
Definition: Dwarf.cpp:262
CaseSensitivity
Definition: Dwarf.h:173
DefaultedMemberAttribute
Definition: Dwarf.h:160
const uint64_t DW64_CIE_ID
Definition: Dwarf.h:55