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 // \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_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 const uint32_t DW_CIE_ID = UINT32_MAX;
63 const uint64_t DW64_CIE_ID = UINT64_MAX;
64 
65 // Identifier of an invalid DIE offset in the .debug_info section.
66 const uint32_t DW_INVALID_OFFSET = UINT32_MAX;
67 
68 enum Tag : uint16_t {
69 #define HANDLE_DW_TAG(ID, NAME, VERSION, VENDOR) DW_TAG_##NAME = ID,
70 #include "llvm/BinaryFormat/Dwarf.def"
71  DW_TAG_lo_user = 0x4080,
72  DW_TAG_hi_user = 0xffff,
73  DW_TAG_user_base = 0x1000 // Recommended base for user tags.
74 };
75 
76 inline bool isType(Tag T) {
77  switch (T) {
78  case DW_TAG_array_type:
79  case DW_TAG_class_type:
80  case DW_TAG_interface_type:
81  case DW_TAG_enumeration_type:
82  case DW_TAG_pointer_type:
83  case DW_TAG_reference_type:
84  case DW_TAG_rvalue_reference_type:
85  case DW_TAG_string_type:
86  case DW_TAG_structure_type:
87  case DW_TAG_subroutine_type:
88  case DW_TAG_union_type:
89  case DW_TAG_ptr_to_member_type:
90  case DW_TAG_set_type:
91  case DW_TAG_subrange_type:
92  case DW_TAG_base_type:
93  case DW_TAG_const_type:
94  case DW_TAG_file_type:
95  case DW_TAG_packed_type:
96  case DW_TAG_volatile_type:
97  case DW_TAG_typedef:
98  return true;
99  default:
100  return false;
101  }
102 }
103 
104 /// Attributes.
105 enum Attribute : uint16_t {
106 #define HANDLE_DW_AT(ID, NAME, VERSION, VENDOR) DW_AT_##NAME = ID,
107 #include "llvm/BinaryFormat/Dwarf.def"
108  DW_AT_lo_user = 0x2000,
109  DW_AT_hi_user = 0x3fff,
110 };
111 
112 enum Form : uint16_t {
113 #define HANDLE_DW_FORM(ID, NAME, VERSION, VENDOR) DW_FORM_##NAME = ID,
114 #include "llvm/BinaryFormat/Dwarf.def"
115  DW_FORM_lo_user = 0x1f00, ///< Not specified by DWARF.
116 };
117 
119 #define HANDLE_DW_OP(ID, NAME, VERSION, VENDOR) DW_OP_##NAME = ID,
120 #include "llvm/BinaryFormat/Dwarf.def"
123  DW_OP_LLVM_fragment = 0x1000 ///< Only used in LLVM metadata.
124 };
125 
126 enum TypeKind {
127 #define HANDLE_DW_ATE(ID, NAME, VERSION, VENDOR) DW_ATE_##NAME = ID,
128 #include "llvm/BinaryFormat/Dwarf.def"
131 };
132 
134  // Decimal sign attribute values
140 };
141 
143  // Endianity attribute values
145  DW_END_big = 0x01,
149 };
150 
152  // Accessibility codes
156 };
157 
159  // Visibility codes
160  DW_VIS_local = 0x01,
163 };
164 
166 #define HANDLE_DW_VIRTUALITY(ID, NAME) DW_VIRTUALITY_##NAME = ID,
167 #include "llvm/BinaryFormat/Dwarf.def"
169 };
170 
172 #define HANDLE_DW_DEFAULTED(ID, NAME) DW_DEFAULTED_##NAME = ID,
173 #include "llvm/BinaryFormat/Dwarf.def"
175 };
176 
178 #define HANDLE_DW_LANG(ID, NAME, VERSION, VENDOR) DW_LANG_##NAME = ID,
179 #include "llvm/BinaryFormat/Dwarf.def"
180  DW_LANG_lo_user = 0x8000,
182 };
183 
185  // Identifier case codes
190 };
191 
193 // Calling convention codes
194 #define HANDLE_DW_CC(ID, NAME) DW_CC_##NAME = ID,
195 #include "llvm/BinaryFormat/Dwarf.def"
198 };
199 
201  // Inline codes
206 };
207 
209  // Array ordering
212 };
213 
215  // Discriminant descriptor values
216  DW_DSC_label = 0x00,
218 };
219 
220 /// Line Number Standard Opcode Encodings.
221 enum LineNumberOps : uint8_t {
222 #define HANDLE_DW_LNS(ID, NAME) DW_LNS_##NAME = ID,
223 #include "llvm/BinaryFormat/Dwarf.def"
224 };
225 
226 /// Line Number Extended Opcode Encodings.
228 #define HANDLE_DW_LNE(ID, NAME) DW_LNE_##NAME = ID,
229 #include "llvm/BinaryFormat/Dwarf.def"
232 };
233 
235 #define HANDLE_DW_LNCT(ID, NAME) DW_LNCT_##NAME = ID,
236 #include "llvm/BinaryFormat/Dwarf.def"
237  DW_LNCT_lo_user = 0x2000,
238  DW_LNCT_hi_user = 0x3fff,
239 };
240 
242  // Macinfo Type Encodings
248 };
249 
250 /// DWARF v5 macro information entry type encodings.
252 #define HANDLE_DW_MACRO(ID, NAME) DW_MACRO_##NAME = ID,
253 #include "llvm/BinaryFormat/Dwarf.def"
256 };
257 
258 /// DWARF v5 range list entry encoding values.
260 #define HANDLE_DW_RLE(ID, NAME) DW_RLE_##NAME = ID,
261 #include "llvm/BinaryFormat/Dwarf.def"
262 };
263 
264 /// Call frame instruction encodings.
266 #define HANDLE_DW_CFA(ID, NAME) DW_CFA_##NAME = ID,
267 #include "llvm/BinaryFormat/Dwarf.def"
269 
272 };
273 
274 enum Constants {
275  // Children flag
278 
296 };
297 
298 /// Constants for location lists in DWARF v5.
299 enum LocationListEntry : unsigned char {
309 };
310 
311 /// Constants for the DW_APPLE_PROPERTY_attributes attribute.
312 /// Keep this list in sync with clang's DeclSpec.h ObjCPropertyAttributeKind!
314 #define HANDLE_DW_APPLE_PROPERTY(ID, NAME) DW_APPLE_PROPERTY_##NAME = ID,
315 #include "llvm/BinaryFormat/Dwarf.def"
316 };
317 
318 /// Constants for unit types in DWARF v5.
319 enum UnitType : unsigned char {
320 #define HANDLE_DW_UT(ID, NAME) DW_UT_##NAME = ID,
321 #include "llvm/BinaryFormat/Dwarf.def"
324 };
325 
326 // Constants for the DWARF v5 Accelerator Table Proposal
328  // Data layout descriptors.
329  DW_ATOM_null = 0u, // Marker as the end of a list of atoms.
330  DW_ATOM_die_offset = 1u, // DIE offset in the debug_info section.
331  DW_ATOM_cu_offset = 2u, // Offset of the compile unit header that contains the
332  // item in question.
333  DW_ATOM_die_tag = 3u, // A tag entry.
334  DW_ATOM_type_flags = 4u, // Set of flags for a type.
335 
336  // DW_ATOM_type_flags values.
337 
338  // Always set for C++, only set for ObjC if this is the @implementation for a
339  // class.
341 
342  // Hash functions.
343 
344  // Daniel J. Bernstein hash.
346 };
347 
348 // Constants for the GNU pubnames/pubtypes extensions supporting gdb index.
358 };
359 
361 
362 /// \defgroup DwarfConstantsDumping Dwarf constants dumping functions
363 ///
364 /// All these functions map their argument's value back to the
365 /// corresponding enumerator name or return nullptr if the value isn't
366 /// known.
367 ///
368 /// @{
369 StringRef TagString(unsigned Tag);
370 StringRef ChildrenString(unsigned Children);
372 StringRef FormEncodingString(unsigned Encoding);
373 StringRef OperationEncodingString(unsigned Encoding);
374 StringRef AttributeEncodingString(unsigned Encoding);
375 StringRef DecimalSignString(unsigned Sign);
376 StringRef EndianityString(unsigned Endian);
377 StringRef AccessibilityString(unsigned Access);
379 StringRef VirtualityString(unsigned Virtuality);
381 StringRef CaseString(unsigned Case);
382 StringRef ConventionString(unsigned Convention);
383 StringRef InlineCodeString(unsigned Code);
384 StringRef ArrayOrderString(unsigned Order);
385 StringRef DiscriminantString(unsigned Discriminant);
386 StringRef LNStandardString(unsigned Standard);
387 StringRef LNExtendedString(unsigned Encoding);
388 StringRef MacinfoString(unsigned Encoding);
389 StringRef CallFrameString(unsigned Encoding);
391 StringRef UnitTypeString(unsigned);
392 StringRef AtomTypeString(unsigned Atom);
395 /// @}
396 
397 /// \defgroup DwarfConstantsParsing Dwarf constants parsing functions
398 ///
399 /// These functions map their strings back to the corresponding enumeration
400 /// value or return 0 if there is none, except for these exceptions:
401 ///
402 /// \li \a getTag() returns \a DW_TAG_invalid on invalid input.
403 /// \li \a getVirtuality() returns \a DW_VIRTUALITY_invalid on invalid input.
404 /// \li \a getMacinfo() returns \a DW_MACINFO_invalid on invalid input.
405 ///
406 /// @{
407 unsigned getTag(StringRef TagString);
408 unsigned getOperationEncoding(StringRef OperationEncodingString);
409 unsigned getVirtuality(StringRef VirtualityString);
410 unsigned getLanguage(StringRef LanguageString);
411 unsigned getCallingConvention(StringRef LanguageString);
412 unsigned getAttributeEncoding(StringRef EncodingString);
413 unsigned getMacinfo(StringRef MacinfoString);
414 /// @}
415 
416 /// \defgroup DwarfConstantsVersioning Dwarf version for constants
417 ///
418 /// For constants defined by DWARF, returns the DWARF version when the constant
419 /// was first defined. For vendor extensions, if there is a version-related
420 /// policy for when to emit it, returns a version number for that policy.
421 /// Otherwise returns 0.
422 ///
423 /// @{
424 unsigned TagVersion(Tag T);
425 unsigned AttributeVersion(Attribute A);
426 unsigned FormVersion(Form F);
427 unsigned OperationVersion(LocationAtom O);
429 unsigned LanguageVersion(SourceLanguage L);
430 /// @}
431 
432 /// \defgroup DwarfConstantsVendor Dwarf "vendor" for constants
433 ///
434 /// These functions return an identifier describing "who" defined the constant,
435 /// either the DWARF standard itself or the vendor who defined the extension.
436 ///
437 /// @{
438 unsigned TagVendor(Tag T);
439 unsigned AttributeVendor(Attribute A);
440 unsigned FormVendor(Form F);
441 unsigned OperationVendor(LocationAtom O);
443 unsigned LanguageVendor(SourceLanguage L);
444 /// @}
445 
446 /// Tells whether the specified form is defined in the specified version,
447 /// or is an extension if extensions are allowed.
448 bool isValidFormForVersion(Form F, unsigned Version, bool ExtensionsOk = true);
449 
450 /// \brief Returns the symbolic string representing Val when used as a value
451 /// for attribute Attr.
452 StringRef AttributeValueString(uint16_t Attr, unsigned Val);
453 
454 /// \brief Decsribes an entry of the various gnu_pub* debug sections.
455 ///
456 /// The gnu_pub* kind looks like:
457 ///
458 /// 0-3 reserved
459 /// 4-6 symbol kind
460 /// 7 0 == global, 1 == static
461 ///
462 /// A gdb_index descriptor includes the above kind, shifted 24 bits up with the
463 /// offset of the cu within the debug_info section stored in those 24 bits.
468  : Kind(Kind), Linkage(Linkage) {}
470  : Kind(Kind), Linkage(GIEL_EXTERNAL) {}
471  explicit PubIndexEntryDescriptor(uint8_t Value)
472  : Kind(
473  static_cast<GDBIndexEntryKind>((Value & KIND_MASK) >> KIND_OFFSET)),
474  Linkage(static_cast<GDBIndexEntryLinkage>((Value & LINKAGE_MASK) >>
475  LINKAGE_OFFSET)) {}
476  uint8_t toBits() const {
477  return Kind << KIND_OFFSET | Linkage << LINKAGE_OFFSET;
478  }
479 
480 private:
481  enum {
482  KIND_OFFSET = 4,
483  KIND_MASK = 7 << KIND_OFFSET,
484  LINKAGE_OFFSET = 7,
485  LINKAGE_MASK = 1 << LINKAGE_OFFSET
486  };
487 };
488 
489 /// Constants that define the DWARF format as 32 or 64 bit.
490 enum DwarfFormat : uint8_t { DWARF32, DWARF64 };
491 
492 } // End of namespace dwarf
493 
494 } // End of namespace llvm
495 
496 #endif
DecimalSignEncoding
Definition: Dwarf.h:133
MacinfoRecordType
Definition: Dwarf.h:241
LocationAtom
Definition: Dwarf.h:118
unsigned FormVersion(Form F)
Definition: Dwarf.cpp:116
StringRef ApplePropertyString(unsigned)
Definition: Dwarf.cpp:468
PubIndexEntryDescriptor(GDBIndexEntryKind Kind)
Definition: Dwarf.h:469
LineNumberOps
Line Number Standard Opcode Encodings.
Definition: Dwarf.h:221
Not specified by DWARF.
Definition: Dwarf.h:115
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
Attribute
Attributes.
Definition: Dwarf.h:105
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:349
ArrayDimensionOrdering
Definition: Dwarf.h:208
ELFYAML::ELF_STV Visibility
Definition: ELFYAML.cpp:694
unsigned getVirtuality(StringRef VirtualityString)
Definition: Dwarf.cpp:291
InlineAttribute
Definition: Dwarf.h:200
CallFrameInfo
Call frame instruction encodings.
Definition: Dwarf.h:265
EndianityEncoding
Definition: Dwarf.h:142
DwarfFormat
Constants that define the DWARF format as 32 or 64 bit.
Definition: Dwarf.h:490
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:123
PubIndexEntryDescriptor(uint8_t Value)
Definition: Dwarf.h:471
unsigned LanguageVendor(SourceLanguage L)
Definition: Dwarf.cpp:329
Decsribes an entry of the various gnu_pub* debug sections.
Definition: Dwarf.h:464
MacroEntryType
DWARF v5 macro information entry type encodings.
Definition: Dwarf.h:251
#define F(x, y, z)
Definition: MD5.cpp:55
StringRef AttributeString(unsigned Attribute)
Definition: Dwarf.cpp:72
StringRef LanguageString(unsigned Language)
Definition: Dwarf.cpp:299
AccessAttribute
Definition: Dwarf.h:151
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
Definition: Dwarf.h:66
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
unsigned getCallingConvention(StringRef LanguageString)
Definition: Dwarf.cpp:365
SourceLanguage
Definition: Dwarf.h:177
unsigned getOperationEncoding(StringRef OperationEncodingString)
Definition: Dwarf.cpp:151
#define A
Definition: LargeTest.cpp:12
StringRef DiscriminantString(unsigned Discriminant)
Definition: Dwarf.cpp:396
StringRef ArrayOrderString(unsigned Order)
Definition: Dwarf.cpp:386
unsigned OperationVersion(LocationAtom O)
Definition: Dwarf.cpp:160
StringRef GDBIndexEntryLinkageString(GDBIndexEntryLinkage Linkage)
Definition: Dwarf.cpp:529
GDBIndexEntryLinkage Linkage
Definition: Dwarf.h:466
unsigned getLanguage(StringRef LanguageString)
Definition: Dwarf.cpp:310
VisibilityAttribute
Definition: Dwarf.h:158
LineNumberExtendedOps
Line Number Extended Opcode Encodings.
Definition: Dwarf.h:227
StringRef VirtualityString(unsigned Virtuality)
Definition: Dwarf.cpp:280
StringRef OperationEncodingString(unsigned Encoding)
Definition: Dwarf.cpp:138
const uint32_t DW_CIE_ID
Definition: Dwarf.h:62
unsigned getTag(StringRef TagString)
Definition: Dwarf.cpp:32
UnitType
Constants for unit types in DWARF v5.
Definition: Dwarf.h:319
StringRef CaseString(unsigned Case)
Definition: Dwarf.cpp:340
constexpr char Language[]
Key for Kernel::Metadata::mLanguage.
ApplePropertyAttributes
Constants for the DW_APPLE_PROPERTY_attributes attribute.
Definition: Dwarf.h:313
#define E
Definition: LargeTest.cpp:27
unsigned AttributeVersion(Attribute A)
Definition: Dwarf.cpp:83
AcceleratorTable
Definition: Dwarf.h:327
LocationListEntry
Constants for location lists in DWARF v5.
Definition: Dwarf.h:299
bool isType(Tag T)
Definition: Dwarf.h:76
PubIndexEntryDescriptor(GDBIndexEntryKind Kind, GDBIndexEntryLinkage Linkage)
Definition: Dwarf.h:467
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:259
StringRef UnitTypeString(unsigned)
Definition: Dwarf.cpp:479
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:192
VirtualityAttribute
Definition: Dwarf.h:165
LLVM Value Representation.
Definition: Value.h:73
unsigned getAttributeEncoding(StringRef EncodingString)
Definition: Dwarf.cpp:193
GDBIndexEntryLinkage
Definition: Dwarf.h:360
DiscriminantList
Definition: Dwarf.h:214
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:234
CaseSensitivity
Definition: Dwarf.h:184
const uint64_t Version
Definition: InstrProf.h:865
DefaultedMemberAttribute
Definition: Dwarf.h:171
const uint64_t DW64_CIE_ID
Definition: Dwarf.h:63