LLVM  7.0.0svn
Dwarf.h
Go to the documentation of this file.
1 //===-- llvm/BinaryFormat/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 /// 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_BINARYFORMAT_DWARF_H
21 #define LLVM_BINARYFORMAT_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.5
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/BinaryFormat/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  // Identifiers we use to distinguish vendor extensions.
51  DWARF_VENDOR_DWARF = 0, // Defined in v2 or later of the DWARF standard.
58 };
59 
60 /// Special ID values that distinguish a CIE from a FDE in DWARF CFI.
61 /// Not inside an enum because a 64-bit value is needed.
62 /// @{
63 const uint32_t DW_CIE_ID = UINT32_MAX;
64 const uint64_t DW64_CIE_ID = UINT64_MAX;
65 /// @}
66 
67 /// Identifier of an invalid DIE offset in the .debug_info section.
68 const uint32_t DW_INVALID_OFFSET = UINT32_MAX;
69 
70 enum Tag : uint16_t {
71 #define HANDLE_DW_TAG(ID, NAME, VERSION, VENDOR) DW_TAG_##NAME = ID,
72 #include "llvm/BinaryFormat/Dwarf.def"
73  DW_TAG_lo_user = 0x4080,
74  DW_TAG_hi_user = 0xffff,
75  DW_TAG_user_base = 0x1000 ///< Recommended base for user tags.
76 };
77 
78 inline bool isType(Tag T) {
79  switch (T) {
80  case DW_TAG_array_type:
81  case DW_TAG_class_type:
82  case DW_TAG_interface_type:
83  case DW_TAG_enumeration_type:
84  case DW_TAG_pointer_type:
85  case DW_TAG_reference_type:
86  case DW_TAG_rvalue_reference_type:
87  case DW_TAG_string_type:
88  case DW_TAG_structure_type:
89  case DW_TAG_subroutine_type:
90  case DW_TAG_union_type:
91  case DW_TAG_ptr_to_member_type:
92  case DW_TAG_set_type:
93  case DW_TAG_subrange_type:
94  case DW_TAG_base_type:
95  case DW_TAG_const_type:
96  case DW_TAG_file_type:
97  case DW_TAG_packed_type:
98  case DW_TAG_volatile_type:
99  case DW_TAG_typedef:
100  return true;
101  default:
102  return false;
103  }
104 }
105 
106 /// Attributes.
107 enum Attribute : uint16_t {
108 #define HANDLE_DW_AT(ID, NAME, VERSION, VENDOR) DW_AT_##NAME = ID,
109 #include "llvm/BinaryFormat/Dwarf.def"
110  DW_AT_lo_user = 0x2000,
111  DW_AT_hi_user = 0x3fff,
112 };
113 
114 enum Form : uint16_t {
115 #define HANDLE_DW_FORM(ID, NAME, VERSION, VENDOR) DW_FORM_##NAME = ID,
116 #include "llvm/BinaryFormat/Dwarf.def"
117  DW_FORM_lo_user = 0x1f00, ///< Not specified by DWARF.
118 };
119 
121 #define HANDLE_DW_OP(ID, NAME, VERSION, VENDOR) DW_OP_##NAME = ID,
122 #include "llvm/BinaryFormat/Dwarf.def"
125  DW_OP_LLVM_fragment = 0x1000 ///< Only used in LLVM metadata.
126 };
127 
128 enum TypeKind : uint8_t {
129 #define HANDLE_DW_ATE(ID, NAME, VERSION, VENDOR) DW_ATE_##NAME = ID,
130 #include "llvm/BinaryFormat/Dwarf.def"
133 };
134 
136  // Decimal sign attribute values
142 };
143 
145  // Endianity attribute values
147  DW_END_big = 0x01,
151 };
152 
154  // Accessibility codes
158 };
159 
161  // Visibility codes
162  DW_VIS_local = 0x01,
165 };
166 
168 #define HANDLE_DW_VIRTUALITY(ID, NAME) DW_VIRTUALITY_##NAME = ID,
169 #include "llvm/BinaryFormat/Dwarf.def"
171 };
172 
174 #define HANDLE_DW_DEFAULTED(ID, NAME) DW_DEFAULTED_##NAME = ID,
175 #include "llvm/BinaryFormat/Dwarf.def"
177 };
178 
180 #define HANDLE_DW_LANG(ID, NAME, VERSION, VENDOR) DW_LANG_##NAME = ID,
181 #include "llvm/BinaryFormat/Dwarf.def"
182  DW_LANG_lo_user = 0x8000,
184 };
185 
187  // Identifier case codes
192 };
193 
195 // Calling convention codes
196 #define HANDLE_DW_CC(ID, NAME) DW_CC_##NAME = ID,
197 #include "llvm/BinaryFormat/Dwarf.def"
200 };
201 
203  // Inline codes
208 };
209 
211  // Array ordering
214 };
215 
217  // Discriminant descriptor values
218  DW_DSC_label = 0x00,
220 };
221 
222 /// Line Number Standard Opcode Encodings.
223 enum LineNumberOps : uint8_t {
224 #define HANDLE_DW_LNS(ID, NAME) DW_LNS_##NAME = ID,
225 #include "llvm/BinaryFormat/Dwarf.def"
226 };
227 
228 /// Line Number Extended Opcode Encodings.
230 #define HANDLE_DW_LNE(ID, NAME) DW_LNE_##NAME = ID,
231 #include "llvm/BinaryFormat/Dwarf.def"
234 };
235 
237 #define HANDLE_DW_LNCT(ID, NAME) DW_LNCT_##NAME = ID,
238 #include "llvm/BinaryFormat/Dwarf.def"
239  DW_LNCT_lo_user = 0x2000,
240  DW_LNCT_hi_user = 0x3fff,
241 };
242 
244  // Macinfo Type Encodings
250 };
251 
252 /// DWARF v5 macro information entry type encodings.
254 #define HANDLE_DW_MACRO(ID, NAME) DW_MACRO_##NAME = ID,
255 #include "llvm/BinaryFormat/Dwarf.def"
258 };
259 
260 /// DWARF v5 range list entry encoding values.
262 #define HANDLE_DW_RLE(ID, NAME) DW_RLE_##NAME = ID,
263 #include "llvm/BinaryFormat/Dwarf.def"
264 };
265 
266 /// Call frame instruction encodings.
268 #define HANDLE_DW_CFA(ID, NAME) DW_CFA_##NAME = ID,
269 #include "llvm/BinaryFormat/Dwarf.def"
271 
274 };
275 
276 enum Constants {
277  // Children flag
280 
298 };
299 
300 /// Constants for location lists in DWARF v5.
301 enum LocationListEntry : unsigned char {
311 };
312 
313 /// Constants for the DW_APPLE_PROPERTY_attributes attribute.
314 /// Keep this list in sync with clang's DeclSpec.h ObjCPropertyAttributeKind!
316 #define HANDLE_DW_APPLE_PROPERTY(ID, NAME) DW_APPLE_PROPERTY_##NAME = ID,
317 #include "llvm/BinaryFormat/Dwarf.def"
318 };
319 
320 /// Constants for unit types in DWARF v5.
321 enum UnitType : unsigned char {
322 #define HANDLE_DW_UT(ID, NAME) DW_UT_##NAME = ID,
323 #include "llvm/BinaryFormat/Dwarf.def"
326 };
327 
328 enum Index {
329 #define HANDLE_DW_IDX(ID, NAME) DW_IDX_##NAME = ID,
330 #include "llvm/BinaryFormat/Dwarf.def"
331  DW_IDX_lo_user = 0x2000,
332  DW_IDX_hi_user = 0x3fff
333 };
334 
335 inline bool isUnitType(uint8_t UnitType) {
336  switch (UnitType) {
337  case DW_UT_compile:
338  case DW_UT_type:
339  case DW_UT_partial:
340  case DW_UT_skeleton:
341  case DW_UT_split_compile:
342  case DW_UT_split_type:
343  return true;
344  default:
345  return false;
346  }
347 }
348 
349 inline bool isUnitType(dwarf::Tag T) {
350  switch (T) {
351  case DW_TAG_compile_unit:
352  case DW_TAG_type_unit:
353  case DW_TAG_partial_unit:
354  case DW_TAG_skeleton_unit:
355  return true;
356  default:
357  return false;
358  }
359 }
360 
361 // Constants for the DWARF v5 Accelerator Table Proposal
363  // Data layout descriptors.
364  DW_ATOM_null = 0u, /// Marker as the end of a list of atoms.
365  DW_ATOM_die_offset = 1u, // DIE offset in the debug_info section.
366  DW_ATOM_cu_offset = 2u, // Offset of the compile unit header that contains the
367  // item in question.
368  DW_ATOM_die_tag = 3u, // A tag entry.
369  DW_ATOM_type_flags = 4u, // Set of flags for a type.
370 
371  DW_ATOM_type_type_flags = 5u, // Dsymutil type extension.
372  DW_ATOM_qual_name_hash = 6u, // Dsymutil qualified hash extension.
373 
374  // DW_ATOM_type_flags values.
375 
376  // Always set for C++, only set for ObjC if this is the @implementation for a
377  // class.
379 
380  // Hash functions.
381 
382  // Daniel J. Bernstein hash.
384 };
385 
386 // Constants for the GNU pubnames/pubtypes extensions supporting gdb index.
396 };
397 
399 
400 /// \defgroup DwarfConstantsDumping Dwarf constants dumping functions
401 ///
402 /// All these functions map their argument's value back to the
403 /// corresponding enumerator name or return nullptr if the value isn't
404 /// known.
405 ///
406 /// @{
407 StringRef TagString(unsigned Tag);
408 StringRef ChildrenString(unsigned Children);
410 StringRef FormEncodingString(unsigned Encoding);
411 StringRef OperationEncodingString(unsigned Encoding);
412 StringRef AttributeEncodingString(unsigned Encoding);
413 StringRef DecimalSignString(unsigned Sign);
414 StringRef EndianityString(unsigned Endian);
415 StringRef AccessibilityString(unsigned Access);
417 StringRef VirtualityString(unsigned Virtuality);
419 StringRef CaseString(unsigned Case);
420 StringRef ConventionString(unsigned Convention);
421 StringRef InlineCodeString(unsigned Code);
422 StringRef ArrayOrderString(unsigned Order);
423 StringRef LNStandardString(unsigned Standard);
424 StringRef LNExtendedString(unsigned Encoding);
425 StringRef MacinfoString(unsigned Encoding);
426 StringRef CallFrameString(unsigned Encoding);
428 StringRef UnitTypeString(unsigned);
429 StringRef AtomTypeString(unsigned Atom);
432 StringRef IndexString(unsigned Idx);
433 /// @}
434 
435 /// \defgroup DwarfConstantsParsing Dwarf constants parsing functions
436 ///
437 /// These functions map their strings back to the corresponding enumeration
438 /// value or return 0 if there is none, except for these exceptions:
439 ///
440 /// \li \a getTag() returns \a DW_TAG_invalid on invalid input.
441 /// \li \a getVirtuality() returns \a DW_VIRTUALITY_invalid on invalid input.
442 /// \li \a getMacinfo() returns \a DW_MACINFO_invalid on invalid input.
443 ///
444 /// @{
445 unsigned getTag(StringRef TagString);
446 unsigned getOperationEncoding(StringRef OperationEncodingString);
447 unsigned getVirtuality(StringRef VirtualityString);
448 unsigned getLanguage(StringRef LanguageString);
449 unsigned getCallingConvention(StringRef LanguageString);
450 unsigned getAttributeEncoding(StringRef EncodingString);
451 unsigned getMacinfo(StringRef MacinfoString);
452 /// @}
453 
454 /// \defgroup DwarfConstantsVersioning Dwarf version for constants
455 ///
456 /// For constants defined by DWARF, returns the DWARF version when the constant
457 /// was first defined. For vendor extensions, if there is a version-related
458 /// policy for when to emit it, returns a version number for that policy.
459 /// Otherwise returns 0.
460 ///
461 /// @{
462 unsigned TagVersion(Tag T);
463 unsigned AttributeVersion(Attribute A);
464 unsigned FormVersion(Form F);
467 unsigned LanguageVersion(SourceLanguage L);
468 /// @}
469 
470 /// \defgroup DwarfConstantsVendor Dwarf "vendor" for constants
471 ///
472 /// These functions return an identifier describing "who" defined the constant,
473 /// either the DWARF standard itself or the vendor who defined the extension.
474 ///
475 /// @{
476 unsigned TagVendor(Tag T);
477 unsigned AttributeVendor(Attribute A);
478 unsigned FormVendor(Form F);
479 unsigned OperationVendor(LocationAtom O);
481 unsigned LanguageVendor(SourceLanguage L);
482 /// @}
483 
484 /// Tells whether the specified form is defined in the specified version,
485 /// or is an extension if extensions are allowed.
486 bool isValidFormForVersion(Form F, unsigned Version, bool ExtensionsOk = true);
487 
488 /// Returns the symbolic string representing Val when used as a value
489 /// for attribute Attr.
490 StringRef AttributeValueString(uint16_t Attr, unsigned Val);
491 
492 /// Describes an entry of the various gnu_pub* debug sections.
493 ///
494 /// The gnu_pub* kind looks like:
495 ///
496 /// 0-3 reserved
497 /// 4-6 symbol kind
498 /// 7 0 == global, 1 == static
499 ///
500 /// A gdb_index descriptor includes the above kind, shifted 24 bits up with the
501 /// offset of the cu within the debug_info section stored in those 24 bits.
506  : Kind(Kind), Linkage(Linkage) {}
508  : Kind(Kind), Linkage(GIEL_EXTERNAL) {}
509  explicit PubIndexEntryDescriptor(uint8_t Value)
510  : Kind(
511  static_cast<GDBIndexEntryKind>((Value & KIND_MASK) >> KIND_OFFSET)),
512  Linkage(static_cast<GDBIndexEntryLinkage>((Value & LINKAGE_MASK) >>
513  LINKAGE_OFFSET)) {}
514  uint8_t toBits() const {
515  return Kind << KIND_OFFSET | Linkage << LINKAGE_OFFSET;
516  }
517 
518 private:
519  enum {
520  KIND_OFFSET = 4,
521  KIND_MASK = 7 << KIND_OFFSET,
522  LINKAGE_OFFSET = 7,
523  LINKAGE_MASK = 1 << LINKAGE_OFFSET
524  };
525 };
526 
527 /// Constants that define the DWARF format as 32 or 64 bit.
528 enum DwarfFormat : uint8_t { DWARF32, DWARF64 };
529 
530 } // End of namespace dwarf
531 
532 } // End of namespace llvm
533 
534 #endif
DecimalSignEncoding
Definition: Dwarf.h:135
MacinfoRecordType
Definition: Dwarf.h:243
LocationAtom
Definition: Dwarf.h:120
unsigned FormVersion(Form F)
Definition: Dwarf.cpp:116
StringRef ApplePropertyString(unsigned)
Definition: Dwarf.cpp:458
PubIndexEntryDescriptor(GDBIndexEntryKind Kind)
Definition: Dwarf.h:507
StringRef IndexString(unsigned Idx)
Definition: Dwarf.cpp:561
LineNumberOps
Line Number Standard Opcode Encodings.
Definition: Dwarf.h:223
Not specified by DWARF.
Definition: Dwarf.h:117
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
StringRef AtomTypeString(unsigned Atom)
Definition: Dwarf.cpp:480
unsigned FormVendor(Form F)
Definition: Dwarf.cpp:127
bool isUnitType(uint8_t UnitType)
Definition: Dwarf.h:335
Attribute
Attributes.
Definition: Dwarf.h:107
StringRef LNExtendedString(unsigned Encoding)
Definition: Dwarf.cpp:407
StringRef LNStandardString(unsigned Standard)
Definition: Dwarf.cpp:396
unsigned TagVendor(Tag T)
Definition: Dwarf.cpp:51
GDBIndexEntryKind
Definition: Dwarf.h:387
F(f)
ArrayDimensionOrdering
Definition: Dwarf.h:210
ELFYAML::ELF_STV Visibility
Definition: ELFYAML.cpp:765
unsigned getVirtuality(StringRef VirtualityString)
Definition: Dwarf.cpp:291
constexpr char Language[]
Key for Kernel::Metadata::mLanguage.
InlineAttribute
Definition: Dwarf.h:202
CallFrameInfo
Call frame instruction encodings.
Definition: Dwarf.h:267
EndianityEncoding
Definition: Dwarf.h:144
DwarfFormat
Constants that define the DWARF format as 32 or 64 bit.
Definition: Dwarf.h:528
LLVMConstants
Definition: Dwarf.h:39
unsigned TagVersion(Tag T)
Definition: Dwarf.cpp:40
unsigned AttributeVendor(Attribute A)
Definition: Dwarf.cpp:94
StringRef FormEncodingString(unsigned Encoding)
Definition: Dwarf.cpp:105
Only used in LLVM metadata.
Definition: Dwarf.h:125
PubIndexEntryDescriptor(uint8_t Value)
Definition: Dwarf.h:509
unsigned LanguageVendor(SourceLanguage L)
Definition: Dwarf.cpp:329
Describes an entry of the various gnu_pub* debug sections.
Definition: Dwarf.h:502
MacroEntryType
DWARF v5 macro information entry type encodings.
Definition: Dwarf.h:253
StringRef AttributeString(unsigned Attribute)
Definition: Dwarf.cpp:72
StringRef LanguageString(unsigned Language)
Definition: Dwarf.cpp:299
AccessAttribute
Definition: Dwarf.h:153
StringRef DecimalSignString(unsigned Sign)
Definition: Dwarf.cpp:223
StringRef AttributeValueString(uint16_t Attr, unsigned Val)
Returns the symbolic string representing Val when used as a value for attribute Attr.
Definition: Dwarf.cpp:532
unsigned LanguageVersion(SourceLanguage L)
Definition: Dwarf.cpp:318
StringRef GDBIndexEntryKindString(GDBIndexEntryKind Kind)
Definition: Dwarf.cpp:499
StringRef AccessibilityString(unsigned Access)
Definition: Dwarf.cpp:255
const uint32_t DW_INVALID_OFFSET
Identifier of an invalid DIE offset in the .debug_info section.
Definition: Dwarf.h:68
StringRef EndianityString(unsigned Endian)
Definition: Dwarf.cpp:239
StringRef AttributeEncodingString(unsigned Encoding)
Definition: Dwarf.cpp:182
StringRef CallFrameString(unsigned Encoding)
Definition: Dwarf.cpp:447
unsigned OperationVendor(LocationAtom O)
Definition: Dwarf.cpp:171
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
unsigned getCallingConvention(StringRef LanguageString)
Definition: Dwarf.cpp:365
SourceLanguage
Definition: Dwarf.h:179
unsigned getOperationEncoding(StringRef OperationEncodingString)
Definition: Dwarf.cpp:151
StringRef ArrayOrderString(unsigned Order)
Definition: Dwarf.cpp:386
Recommended base for user tags.
Definition: Dwarf.h:75
unsigned OperationVersion(LocationAtom O)
Definition: Dwarf.cpp:160
StringRef GDBIndexEntryLinkageString(GDBIndexEntryLinkage Linkage)
Definition: Dwarf.cpp:522
GDBIndexEntryLinkage Linkage
Definition: Dwarf.h:504
unsigned getLanguage(StringRef LanguageString)
Definition: Dwarf.cpp:310
VisibilityAttribute
Definition: Dwarf.h:160
LineNumberExtendedOps
Line Number Extended Opcode Encodings.
Definition: Dwarf.h:229
StringRef VirtualityString(unsigned Virtuality)
Definition: Dwarf.cpp:280
StringRef OperationEncodingString(unsigned Encoding)
Definition: Dwarf.cpp:138
const uint32_t DW_CIE_ID
Special ID values that distinguish a CIE from a FDE in DWARF CFI.
Definition: Dwarf.h:63
unsigned getTag(StringRef TagString)
Definition: Dwarf.cpp:32
UnitType
Constants for unit types in DWARF v5.
Definition: Dwarf.h:321
StringRef CaseString(unsigned Case)
Definition: Dwarf.cpp:340
ApplePropertyAttributes
Constants for the DW_APPLE_PROPERTY_attributes attribute.
Definition: Dwarf.h:315
unsigned AttributeVersion(Attribute A)
Definition: Dwarf.cpp:83
AcceleratorTable
Definition: Dwarf.h:362
LocationListEntry
Constants for location lists in DWARF v5.
Definition: Dwarf.h:301
bool isType(Tag T)
Definition: Dwarf.h:78
PubIndexEntryDescriptor(GDBIndexEntryKind Kind, GDBIndexEntryLinkage Linkage)
Definition: Dwarf.h:505
unsigned AttributeEncodingVersion(TypeKind E)
Definition: Dwarf.cpp:201
StringRef VisibilityString(unsigned Visibility)
Definition: Dwarf.cpp:268
RangeListEntries
DWARF v5 range list entry encoding values.
Definition: Dwarf.h:261
StringRef UnitTypeString(unsigned)
Definition: Dwarf.cpp:469
StringRef TagString(unsigned Tag)
Definition: Dwarf.cpp:21
unsigned AttributeEncodingVendor(TypeKind E)
Definition: Dwarf.cpp:212
StringRef InlineCodeString(unsigned Code)
Definition: Dwarf.cpp:372
StringRef ConventionString(unsigned Convention)
Definition: Dwarf.cpp:354
unsigned getMacinfo(StringRef MacinfoString)
Definition: Dwarf.cpp:437
StringRef ChildrenString(unsigned Children)
Definition: Dwarf.cpp:62
bool isValidFormForVersion(Form F, unsigned Version, bool ExtensionsOk=true)
Tells whether the specified form is defined in the specified version, or is an extension if extension...
Definition: Dwarf.cpp:572
const unsigned Kind
CallingConvention
Definition: Dwarf.h:194
VirtualityAttribute
Definition: Dwarf.h:167
LLVM Value Representation.
Definition: Value.h:73
unsigned getAttributeEncoding(StringRef EncodingString)
Definition: Dwarf.cpp:193
GDBIndexEntryLinkage
Definition: Dwarf.h:398
DiscriminantList
Definition: Dwarf.h:216
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
StringRef MacinfoString(unsigned Encoding)
Definition: Dwarf.cpp:418
Marker as the end of a list of atoms.
Definition: Dwarf.h:365
LineNumberEntryFormat
Definition: Dwarf.h:236
CaseSensitivity
Definition: Dwarf.h:186
const uint64_t Version
Definition: InstrProf.h:867
DefaultedMemberAttribute
Definition: Dwarf.h:173
const uint64_t DW64_CIE_ID
Definition: Dwarf.h:64