LLVM  3.7.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/ADT/StringRef.h"
24 #include "llvm/Support/Compiler.h"
25 #include "llvm/Support/DataTypes.h"
26 
27 namespace llvm {
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 
39 enum LLVMConstants : uint32_t {
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 
44  // Other constants.
45  DWARF_VERSION = 4, // Default dwarf version we output.
46  DW_PUBTYPES_VERSION = 2, // Section version number for .debug_pubtypes.
47  DW_PUBNAMES_VERSION = 2, // Section version number for .debug_pubnames.
48  DW_ARANGES_VERSION = 2 // Section version number for .debug_aranges.
49 };
50 
51 // Special ID values that distinguish a CIE from a FDE in DWARF CFI.
52 // Not inside an enum because a 64-bit value is needed.
53 const uint32_t DW_CIE_ID = UINT32_MAX;
54 const uint64_t DW64_CIE_ID = UINT64_MAX;
55 
56 enum Tag : uint16_t {
57 #define HANDLE_DW_TAG(ID, NAME) DW_TAG_##NAME = ID,
58 #include "llvm/Support/Dwarf.def"
59  DW_TAG_lo_user = 0x4080,
60  DW_TAG_hi_user = 0xffff,
61  DW_TAG_user_base = 0x1000 // Recommended base for user tags.
62 };
63 
64 inline bool isType(Tag T) {
65  switch (T) {
66  case DW_TAG_array_type:
67  case DW_TAG_class_type:
68  case DW_TAG_interface_type:
69  case DW_TAG_enumeration_type:
70  case DW_TAG_pointer_type:
71  case DW_TAG_reference_type:
72  case DW_TAG_rvalue_reference_type:
73  case DW_TAG_string_type:
74  case DW_TAG_structure_type:
75  case DW_TAG_subroutine_type:
76  case DW_TAG_union_type:
77  case DW_TAG_ptr_to_member_type:
78  case DW_TAG_set_type:
79  case DW_TAG_subrange_type:
80  case DW_TAG_base_type:
81  case DW_TAG_const_type:
82  case DW_TAG_file_type:
83  case DW_TAG_packed_type:
84  case DW_TAG_volatile_type:
85  case DW_TAG_typedef:
86  return true;
87  default:
88  return false;
89  }
90 }
91 
92 enum Attribute : uint16_t {
93  // Attributes
94  DW_AT_sibling = 0x01,
96  DW_AT_name = 0x03,
102  DW_AT_low_pc = 0x11,
105  DW_AT_discr = 0x15,
108  DW_AT_import = 0x18,
115  DW_AT_inline = 0x20,
130  DW_AT_count = 0x37,
140  DW_AT_friend = 0x41,
148  DW_AT_type = 0x49,
160  DW_AT_ranges = 0x55,
168  DW_AT_small = 0x5d,
178  DW_AT_pure = 0x67,
186 
187  // New in DWARF 5:
190  DW_AT_rank = 0x71,
194  DW_AT_dwo_id = 0x75,
198 
199  DW_AT_lo_user = 0x2000,
200  DW_AT_hi_user = 0x3fff,
201 
217 
218  // This one appears to have only been implemented by Open64 for
219  // fortran and may conflict with other extensions.
221 
222  // GNU extensions
223  DW_AT_sf_names = 0x2101,
224  DW_AT_src_info = 0x2102,
225  DW_AT_mac_info = 0x2103,
228  DW_AT_body_end = 0x2106,
231 
233 
234  // Extensions for Fission proposal.
241 
242  // LLVM project extensions.
246 
247  // Apple extensions.
250  DW_AT_APPLE_isa = 0x3fe3,
261 };
262 
263 enum Form : uint16_t {
264  // Attribute form encodings
265  DW_FORM_addr = 0x01,
275  DW_FORM_flag = 0x0c,
277  DW_FORM_strp = 0x0e,
280  DW_FORM_ref1 = 0x11,
281  DW_FORM_ref2 = 0x12,
282  DW_FORM_ref4 = 0x13,
283  DW_FORM_ref8 = 0x14,
290 
291  // Extensions for Fission proposal
294 
295  // Alternate debug sections proposal (output of "dwz" tool).
298 };
299 
301 #define HANDLE_DW_OP(ID, NAME) DW_OP_##NAME = ID,
302 #include "llvm/Support/Dwarf.def"
305 };
306 
307 enum TypeKind {
308 #define HANDLE_DW_ATE(ID, NAME) DW_ATE_##NAME = ID,
309 #include "llvm/Support/Dwarf.def"
312 };
313 
315  // Decimal sign attribute values
321 };
322 
324  // Endianity attribute values
326  DW_END_big = 0x01,
330 };
331 
333  // Accessibility codes
337 };
338 
340  // Visibility codes
341  DW_VIS_local = 0x01,
344 };
345 
347 #define HANDLE_DW_VIRTUALITY(ID, NAME) DW_VIRTUALITY_##NAME = ID,
348 #include "llvm/Support/Dwarf.def"
350 };
351 
353 #define HANDLE_DW_LANG(ID, NAME) DW_LANG_##NAME = ID,
354 #include "llvm/Support/Dwarf.def"
355  DW_LANG_lo_user = 0x8000,
357 };
358 
360  // Identifier case codes
365 };
366 
368  // Calling convention codes
369  DW_CC_normal = 0x01,
371  DW_CC_nocall = 0x03,
374 };
375 
377  // Inline codes
382 };
383 
385  // Array ordering
388 };
389 
391  // Discriminant descriptor values
392  DW_DSC_label = 0x00,
394 };
395 
397  // Line Number Standard Opcode Encodings
399  DW_LNS_copy = 0x01,
411 };
412 
414  // Line Number Extended Opcode Encodings
421 };
422 
424  // Macinfo Type Encodings
430 };
431 
433  // Call frame instruction encodings
435  DW_CFA_nop = 0x00,
466 };
467 
468 enum Constants {
469  // Children flag
472 
490 };
491 
492 // Constants for debug_loc.dwo in the DWARF5 Split Debug Info Proposal
493 enum LocationListEntry : unsigned char {
499 };
500 
501 /// Contstants for the DW_APPLE_PROPERTY_attributes attribute.
502 /// Keep this list in sync with clang's DeclSpec.h ObjCPropertyAttributeKind.
504  // Apple Objective-C Property Attributes
517 };
518 
519 // Constants for the DWARF5 Accelerator Table Proposal
521  // Data layout descriptors.
522  DW_ATOM_null = 0u, // Marker as the end of a list of atoms.
523  DW_ATOM_die_offset = 1u, // DIE offset in the debug_info section.
524  DW_ATOM_cu_offset = 2u, // Offset of the compile unit header that contains the
525  // item in question.
526  DW_ATOM_die_tag = 3u, // A tag entry.
527  DW_ATOM_type_flags = 4u, // Set of flags for a type.
528 
529  // DW_ATOM_type_flags values.
530 
531  // Always set for C++, only set for ObjC if this is the @implementation for a
532  // class.
534 
535  // Hash functions.
536 
537  // Daniel J. Bernstein hash.
539 };
540 
541 // Constants for the GNU pubnames/pubtypes extensions supporting gdb index.
551 };
552 
556 };
557 
558 /// \defgroup DwarfConstantsDumping Dwarf constants dumping functions
559 ///
560 /// All these functions map their argument's value back to the
561 /// corresponding enumerator name or return nullptr if the value isn't
562 /// known.
563 ///
564 /// @{
565 const char *TagString(unsigned Tag);
566 const char *ChildrenString(unsigned Children);
567 const char *AttributeString(unsigned Attribute);
568 const char *FormEncodingString(unsigned Encoding);
569 const char *OperationEncodingString(unsigned Encoding);
570 const char *AttributeEncodingString(unsigned Encoding);
571 const char *DecimalSignString(unsigned Sign);
572 const char *EndianityString(unsigned Endian);
573 const char *AccessibilityString(unsigned Access);
574 const char *VisibilityString(unsigned Visibility);
575 const char *VirtualityString(unsigned Virtuality);
576 const char *LanguageString(unsigned Language);
577 const char *CaseString(unsigned Case);
578 const char *ConventionString(unsigned Convention);
579 const char *InlineCodeString(unsigned Code);
580 const char *ArrayOrderString(unsigned Order);
581 const char *DiscriminantString(unsigned Discriminant);
582 const char *LNStandardString(unsigned Standard);
583 const char *LNExtendedString(unsigned Encoding);
584 const char *MacinfoString(unsigned Encoding);
585 const char *CallFrameString(unsigned Encoding);
586 const char *ApplePropertyString(unsigned);
587 const char *AtomTypeString(unsigned Atom);
590 /// @}
591 
592 /// \defgroup DwarfConstantsParsing Dwarf constants parsing functions
593 ///
594 /// These functions map their strings back to the corresponding enumeration
595 /// value or return 0 if there is none, except for these exceptions:
596 ///
597 /// \li \a getTag() returns \a DW_TAG_invalid on invalid input.
598 /// \li \a getVirtuality() returns \a DW_VIRTUALITY_invalid on invalid input.
599 ///
600 /// @{
601 unsigned getTag(StringRef TagString);
605 unsigned getAttributeEncoding(StringRef EncodingString);
606 /// @}
607 
608 /// \brief Returns the symbolic string representing Val when used as a value
609 /// for attribute Attr.
610 const char *AttributeValueString(uint16_t Attr, unsigned Val);
611 
612 /// \brief Decsribes an entry of the various gnu_pub* debug sections.
613 ///
614 /// The gnu_pub* kind looks like:
615 ///
616 /// 0-3 reserved
617 /// 4-6 symbol kind
618 /// 7 0 == global, 1 == static
619 ///
620 /// A gdb_index descriptor includes the above kind, shifted 24 bits up with the
621 /// offset of the cu within the debug_info section stored in those 24 bits.
626  : Kind(Kind), Linkage(Linkage) {}
628  : Kind(Kind), Linkage(GIEL_EXTERNAL) {}
629  explicit PubIndexEntryDescriptor(uint8_t Value)
630  : Kind(static_cast<GDBIndexEntryKind>((Value & KIND_MASK) >>
631  KIND_OFFSET)),
632  Linkage(static_cast<GDBIndexEntryLinkage>((Value & LINKAGE_MASK) >>
633  LINKAGE_OFFSET)) {}
634  uint8_t toBits() { return Kind << KIND_OFFSET | Linkage << LINKAGE_OFFSET; }
635 
636 private:
637  enum {
638  KIND_OFFSET = 4,
639  KIND_MASK = 7 << KIND_OFFSET,
640  LINKAGE_OFFSET = 7,
641  LINKAGE_MASK = 1 << LINKAGE_OFFSET
642  };
643 };
644 
645 
646 } // End of namespace dwarf
647 
648 } // End of namespace llvm
649 
650 #endif
DecimalSignEncoding
Definition: Dwarf.h:314
const char * LanguageString(unsigned Language)
Definition: Dwarf.cpp:341
MacinfoRecordType
Definition: Dwarf.h:423
LocationAtom
Definition: Dwarf.h:300
PubIndexEntryDescriptor(GDBIndexEntryKind Kind)
Definition: Dwarf.h:627
const char * AttributeString(unsigned Attribute)
Definition: Dwarf.cpp:46
GDBIndexEntryKind
Definition: Dwarf.h:542
const char * ConventionString(unsigned Convention)
Definition: Dwarf.cpp:369
ArrayDimensionOrdering
Definition: Dwarf.h:384
ELFYAML::ELF_STV Visibility
Definition: ELFYAML.cpp:590
unsigned getVirtuality(StringRef VirtualityString)
Definition: Dwarf.cpp:333
InlineAttribute
Definition: Dwarf.h:376
CallFrameInfo
Definition: Dwarf.h:432
const char * GDBIndexEntryLinkageString(GDBIndexEntryLinkage Linkage)
Definition: Dwarf.cpp:554
EndianityEncoding
Definition: Dwarf.h:323
const char * OperationEncodingString(unsigned Encoding)
Definition: Dwarf.cpp:247
LLVMConstants
Definition: Dwarf.h:39
const char * TagString(unsigned Tag)
Definition: Dwarf.cpp:21
PubIndexEntryDescriptor(uint8_t Value)
Definition: Dwarf.h:629
Decsribes an entry of the various gnu_pub* debug sections.
Definition: Dwarf.h:622
const char * InlineCodeString(unsigned Code)
Definition: Dwarf.cpp:380
const char * DiscriminantString(unsigned Discriminant)
Definition: Dwarf.cpp:398
const char * LNExtendedString(unsigned Encoding)
Definition: Dwarf.cpp:424
AccessAttribute
Definition: Dwarf.h:332
const char * EndianityString(unsigned Endian)
Definition: Dwarf.cpp:292
const char * VirtualityString(unsigned Virtuality)
Definition: Dwarf.cpp:322
const char * AtomTypeString(unsigned Atom)
Definition: Dwarf.cpp:516
const char * DecimalSignString(unsigned Sign)
Definition: Dwarf.cpp:281
SourceLanguage
Definition: Dwarf.h:352
unsigned getOperationEncoding(StringRef OperationEncodingString)
Definition: Dwarf.cpp:257
LineNumberOps
Definition: Dwarf.h:396
GDBIndexEntryLinkage Linkage
Definition: Dwarf.h:624
unsigned getLanguage(StringRef LanguageString)
Definition: Dwarf.cpp:352
const char * AttributeEncodingString(unsigned Encoding)
Definition: Dwarf.cpp:264
VisibilityAttribute
Definition: Dwarf.h:339
LineNumberExtendedOps
Definition: Dwarf.h:413
const uint32_t DW_CIE_ID
Definition: Dwarf.h:53
unsigned getTag(StringRef TagString)
Definition: Dwarf.cpp:31
ApplePropertyAttributes
Contstants for the DW_APPLE_PROPERTY_attributes attribute.
Definition: Dwarf.h:503
const char * CaseString(unsigned Case)
Definition: Dwarf.cpp:359
const char * LNStandardString(unsigned Standard)
Definition: Dwarf.cpp:406
AcceleratorTable
Definition: Dwarf.h:520
LocationListEntry
Definition: Dwarf.h:493
bool isType(Tag T)
Definition: Dwarf.h:64
PubIndexEntryDescriptor(GDBIndexEntryKind Kind, GDBIndexEntryLinkage Linkage)
Definition: Dwarf.h:625
const char * MacinfoString(unsigned Encoding)
Definition: Dwarf.cpp:437
const char * CallFrameString(unsigned Encoding)
Definition: Dwarf.cpp:449
const char * GDBIndexEntryKindString(GDBIndexEntryKind Kind)
Definition: Dwarf.cpp:532
const char * AttributeValueString(uint16_t Attr, unsigned Val)
Returns the symbolic string representing Val when used as a value for attribute Attr.
Definition: Dwarf.cpp:564
const char * ApplePropertyString(unsigned)
Definition: Dwarf.cpp:486
const char * ArrayOrderString(unsigned Order)
Definition: Dwarf.cpp:390
const char * FormEncodingString(unsigned Encoding)
Definition: Dwarf.cpp:208
const char * AccessibilityString(unsigned Access)
Definition: Dwarf.cpp:303
CallingConvention
Definition: Dwarf.h:367
VirtualityAttribute
Definition: Dwarf.h:346
const ARM::ArchExtKind Kind
const char * ChildrenString(unsigned Children)
Definition: Dwarf.cpp:38
LLVM Value Representation.
Definition: Value.h:69
unsigned getAttributeEncoding(StringRef EncodingString)
Definition: Dwarf.cpp:274
GDBIndexEntryLinkage
Definition: Dwarf.h:553
DiscriminantList
Definition: Dwarf.h:390
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:40
CaseSensitivity
Definition: Dwarf.h:359
const char * VisibilityString(unsigned Visibility)
Definition: Dwarf.cpp:313
const uint64_t DW64_CIE_ID
Definition: Dwarf.h:54