LLVM  6.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 {
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 inline bool isUnitType(uint8_t UnitType) {
329  switch (UnitType) {
330  case DW_UT_compile:
331  case DW_UT_type:
332  case DW_UT_partial:
333  case DW_UT_skeleton:
334  case DW_UT_split_compile:
335  case DW_UT_split_type:
336  return true;
337  default:
338  return false;
339  }
340 }
341 
342 inline bool isUnitType(dwarf::Tag T) {
343  switch (T) {
344  case DW_TAG_compile_unit:
345  case DW_TAG_type_unit:
346  case DW_TAG_partial_unit:
347  case DW_TAG_skeleton_unit:
348  return true;
349  default:
350  return false;
351  }
352 }
353 
354 // Constants for the DWARF v5 Accelerator Table Proposal
356  // Data layout descriptors.
357  DW_ATOM_null = 0u, // Marker as the end of a list of atoms.
358  DW_ATOM_die_offset = 1u, // DIE offset in the debug_info section.
359  DW_ATOM_cu_offset = 2u, // Offset of the compile unit header that contains the
360  // item in question.
361  DW_ATOM_die_tag = 3u, // A tag entry.
362  DW_ATOM_type_flags = 4u, // Set of flags for a type.
363 
364  // DW_ATOM_type_flags values.
365 
366  // Always set for C++, only set for ObjC if this is the @implementation for a
367  // class.
369 
370  // Hash functions.
371 
372  // Daniel J. Bernstein hash.
374 };
375 
376 // Constants for the GNU pubnames/pubtypes extensions supporting gdb index.
386 };
387 
389 
390 /// \defgroup DwarfConstantsDumping Dwarf constants dumping functions
391 ///
392 /// All these functions map their argument's value back to the
393 /// corresponding enumerator name or return nullptr if the value isn't
394 /// known.
395 ///
396 /// @{
397 StringRef TagString(unsigned Tag);
398 StringRef ChildrenString(unsigned Children);
400 StringRef FormEncodingString(unsigned Encoding);
401 StringRef OperationEncodingString(unsigned Encoding);
402 StringRef AttributeEncodingString(unsigned Encoding);
403 StringRef DecimalSignString(unsigned Sign);
404 StringRef EndianityString(unsigned Endian);
405 StringRef AccessibilityString(unsigned Access);
407 StringRef VirtualityString(unsigned Virtuality);
409 StringRef CaseString(unsigned Case);
410 StringRef ConventionString(unsigned Convention);
411 StringRef InlineCodeString(unsigned Code);
412 StringRef ArrayOrderString(unsigned Order);
413 StringRef DiscriminantString(unsigned Discriminant);
414 StringRef LNStandardString(unsigned Standard);
415 StringRef LNExtendedString(unsigned Encoding);
416 StringRef MacinfoString(unsigned Encoding);
417 StringRef CallFrameString(unsigned Encoding);
419 StringRef UnitTypeString(unsigned);
420 StringRef AtomTypeString(unsigned Atom);
423 /// @}
424 
425 /// \defgroup DwarfConstantsParsing Dwarf constants parsing functions
426 ///
427 /// These functions map their strings back to the corresponding enumeration
428 /// value or return 0 if there is none, except for these exceptions:
429 ///
430 /// \li \a getTag() returns \a DW_TAG_invalid on invalid input.
431 /// \li \a getVirtuality() returns \a DW_VIRTUALITY_invalid on invalid input.
432 /// \li \a getMacinfo() returns \a DW_MACINFO_invalid on invalid input.
433 ///
434 /// @{
435 unsigned getTag(StringRef TagString);
436 unsigned getOperationEncoding(StringRef OperationEncodingString);
437 unsigned getVirtuality(StringRef VirtualityString);
438 unsigned getLanguage(StringRef LanguageString);
439 unsigned getCallingConvention(StringRef LanguageString);
440 unsigned getAttributeEncoding(StringRef EncodingString);
441 unsigned getMacinfo(StringRef MacinfoString);
442 /// @}
443 
444 /// \defgroup DwarfConstantsVersioning Dwarf version for constants
445 ///
446 /// For constants defined by DWARF, returns the DWARF version when the constant
447 /// was first defined. For vendor extensions, if there is a version-related
448 /// policy for when to emit it, returns a version number for that policy.
449 /// Otherwise returns 0.
450 ///
451 /// @{
452 unsigned TagVersion(Tag T);
453 unsigned AttributeVersion(Attribute A);
454 unsigned FormVersion(Form F);
457 unsigned LanguageVersion(SourceLanguage L);
458 /// @}
459 
460 /// \defgroup DwarfConstantsVendor Dwarf "vendor" for constants
461 ///
462 /// These functions return an identifier describing "who" defined the constant,
463 /// either the DWARF standard itself or the vendor who defined the extension.
464 ///
465 /// @{
466 unsigned TagVendor(Tag T);
467 unsigned AttributeVendor(Attribute A);
468 unsigned FormVendor(Form F);
469 unsigned OperationVendor(LocationAtom O);
471 unsigned LanguageVendor(SourceLanguage L);
472 /// @}
473 
474 /// Tells whether the specified form is defined in the specified version,
475 /// or is an extension if extensions are allowed.
476 bool isValidFormForVersion(Form F, unsigned Version, bool ExtensionsOk = true);
477 
478 /// Returns the symbolic string representing Val when used as a value
479 /// for attribute Attr.
480 StringRef AttributeValueString(uint16_t Attr, unsigned Val);
481 
482 /// Describes an entry of the various gnu_pub* debug sections.
483 ///
484 /// The gnu_pub* kind looks like:
485 ///
486 /// 0-3 reserved
487 /// 4-6 symbol kind
488 /// 7 0 == global, 1 == static
489 ///
490 /// A gdb_index descriptor includes the above kind, shifted 24 bits up with the
491 /// offset of the cu within the debug_info section stored in those 24 bits.
496  : Kind(Kind), Linkage(Linkage) {}
498  : Kind(Kind), Linkage(GIEL_EXTERNAL) {}
499  explicit PubIndexEntryDescriptor(uint8_t Value)
500  : Kind(
501  static_cast<GDBIndexEntryKind>((Value & KIND_MASK) >> KIND_OFFSET)),
502  Linkage(static_cast<GDBIndexEntryLinkage>((Value & LINKAGE_MASK) >>
503  LINKAGE_OFFSET)) {}
504  uint8_t toBits() const {
505  return Kind << KIND_OFFSET | Linkage << LINKAGE_OFFSET;
506  }
507 
508 private:
509  enum {
510  KIND_OFFSET = 4,
511  KIND_MASK = 7 << KIND_OFFSET,
512  LINKAGE_OFFSET = 7,
513  LINKAGE_MASK = 1 << LINKAGE_OFFSET
514  };
515 };
516 
517 /// Constants that define the DWARF format as 32 or 64 bit.
518 enum DwarfFormat : uint8_t { DWARF32, DWARF64 };
519 
520 /// The Bernstein hash function used by the accelerator tables.
521 uint32_t djbHash(StringRef Buffer);
522 
523 } // End of namespace dwarf
524 
525 } // End of namespace llvm
526 
527 #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:468
PubIndexEntryDescriptor(GDBIndexEntryKind Kind)
Definition: Dwarf.h:497
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:490
unsigned FormVendor(Form F)
Definition: Dwarf.cpp:127
bool isUnitType(uint8_t UnitType)
Definition: Dwarf.h:328
Attribute
Attributes.
Definition: Dwarf.h:107
StringRef LNExtendedString(unsigned Encoding)
Definition: Dwarf.cpp:417
StringRef LNStandardString(unsigned Standard)
Definition: Dwarf.cpp:406
unsigned TagVendor(Tag T)
Definition: Dwarf.cpp:51
GDBIndexEntryKind
Definition: Dwarf.h:377
F(f)
ArrayDimensionOrdering
Definition: Dwarf.h:210
ELFYAML::ELF_STV Visibility
Definition: ELFYAML.cpp:735
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:518
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:499
unsigned LanguageVendor(SourceLanguage L)
Definition: Dwarf.cpp:329
Describes an entry of the various gnu_pub* debug sections.
Definition: Dwarf.h:492
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:539
unsigned LanguageVersion(SourceLanguage L)
Definition: Dwarf.cpp:318
StringRef GDBIndexEntryKindString(GDBIndexEntryKind Kind)
Definition: Dwarf.cpp:506
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:457
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 DiscriminantString(unsigned Discriminant)
Definition: Dwarf.cpp:396
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:529
GDBIndexEntryLinkage Linkage
Definition: Dwarf.h:494
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:355
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:495
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:479
uint32_t djbHash(StringRef Buffer)
The Bernstein hash function used by the accelerator tables.
Definition: Dwarf.cpp:579
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:447
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:570
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:388
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:428
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