Home | History | Annotate | Download | only in Support
      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.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 
     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   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 
    107 enum LocationAtom {
    108 #define HANDLE_DW_OP(ID, NAME) DW_OP_##NAME = ID,
    109 #include "llvm/Support/Dwarf.def"
    110   DW_OP_lo_user = 0xe0,
    111   DW_OP_hi_user = 0xff,
    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"
    118   DW_ATE_lo_user = 0x80,
    119   DW_ATE_hi_user = 0xff
    120 };
    121 
    122 enum DecimalSignEncoding {
    123   // Decimal sign attribute values
    124   DW_DS_unsigned = 0x01,
    125   DW_DS_leading_overpunch = 0x02,
    126   DW_DS_trailing_overpunch = 0x03,
    127   DW_DS_leading_separate = 0x04,
    128   DW_DS_trailing_separate = 0x05
    129 };
    130 
    131 enum EndianityEncoding {
    132   // Endianity attribute values
    133   DW_END_default = 0x00,
    134   DW_END_big = 0x01,
    135   DW_END_little = 0x02,
    136   DW_END_lo_user = 0x40,
    137   DW_END_hi_user = 0xff
    138 };
    139 
    140 enum AccessAttribute {
    141   // Accessibility codes
    142   DW_ACCESS_public = 0x01,
    143   DW_ACCESS_protected = 0x02,
    144   DW_ACCESS_private = 0x03
    145 };
    146 
    147 enum VisibilityAttribute {
    148   // Visibility codes
    149   DW_VIS_local = 0x01,
    150   DW_VIS_exported = 0x02,
    151   DW_VIS_qualified = 0x03
    152 };
    153 
    154 enum VirtualityAttribute {
    155 #define HANDLE_DW_VIRTUALITY(ID, NAME) DW_VIRTUALITY_##NAME = ID,
    156 #include "llvm/Support/Dwarf.def"
    157   DW_VIRTUALITY_max = 0x02
    158 };
    159 
    160 enum DefaultedMemberAttribute {
    161 #define HANDLE_DW_DEFAULTED(ID, NAME) DW_DEFAULTED_##NAME = ID,
    162 #include "llvm/Support/Dwarf.def"
    163   DW_DEFAULTED_max = 0x02
    164 };
    165 
    166 enum SourceLanguage {
    167 #define HANDLE_DW_LANG(ID, NAME) DW_LANG_##NAME = ID,
    168 #include "llvm/Support/Dwarf.def"
    169   DW_LANG_lo_user = 0x8000,
    170   DW_LANG_hi_user = 0xffff
    171 };
    172 
    173 enum CaseSensitivity {
    174   // Identifier case codes
    175   DW_ID_case_sensitive = 0x00,
    176   DW_ID_up_case = 0x01,
    177   DW_ID_down_case = 0x02,
    178   DW_ID_case_insensitive = 0x03
    179 };
    180 
    181 enum CallingConvention {
    182   // Calling convention codes
    183 #define HANDLE_DW_CC(ID, NAME) DW_CC_##NAME = ID,
    184 #include "llvm/Support/Dwarf.def"
    185   DW_CC_lo_user = 0x40,
    186   DW_CC_hi_user = 0xff
    187 };
    188 
    189 enum InlineAttribute {
    190   // Inline codes
    191   DW_INL_not_inlined = 0x00,
    192   DW_INL_inlined = 0x01,
    193   DW_INL_declared_not_inlined = 0x02,
    194   DW_INL_declared_inlined = 0x03
    195 };
    196 
    197 enum ArrayDimensionOrdering {
    198   // Array ordering
    199   DW_ORD_row_major = 0x00,
    200   DW_ORD_col_major = 0x01
    201 };
    202 
    203 enum DiscriminantList {
    204   // Discriminant descriptor values
    205   DW_DSC_label = 0x00,
    206   DW_DSC_range = 0x01
    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.
    216 enum LineNumberExtendedOps {
    217 #define HANDLE_DW_LNE(ID, NAME) DW_LNE_##NAME = ID,
    218 #include "llvm/Support/Dwarf.def"
    219   DW_LNE_lo_user = 0x80,
    220   DW_LNE_hi_user = 0xff
    221 };
    222 
    223 enum LinerNumberEntryFormat {
    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 
    230 enum MacinfoRecordType {
    231   // Macinfo Type Encodings
    232   DW_MACINFO_define = 0x01,
    233   DW_MACINFO_undef = 0x02,
    234   DW_MACINFO_start_file = 0x03,
    235   DW_MACINFO_end_file = 0x04,
    236   DW_MACINFO_vendor_ext = 0xff
    237 };
    238 
    239 /// DWARF v5 macro information entry type encodings.
    240 enum MacroEntryType {
    241 #define HANDLE_DW_MACRO(ID, NAME) DW_MACRO_##NAME = ID,
    242 #include "llvm/Support/Dwarf.def"
    243   DW_MACRO_lo_user = 0xe0,
    244   DW_MACRO_hi_user = 0xff
    245 };
    246 
    247 /// DWARF v5 range list entry encoding values.
    248 enum RangeListEntries {
    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.
    255 enum CallFrameInfo {
    256 #define HANDLE_DW_CFA(ID, NAME) DW_CFA_##NAME = ID,
    257 #include "llvm/Support/Dwarf.def"
    258   DW_CFA_extended = 0x00,
    259 
    260   DW_CFA_lo_user = 0x1c,
    261   DW_CFA_hi_user = 0x3f
    262 };
    263 
    264 enum Constants {
    265   // Children flag
    266   DW_CHILDREN_no = 0x00,
    267   DW_CHILDREN_yes = 0x01,
    268 
    269   DW_EH_PE_absptr = 0x00,
    270   DW_EH_PE_omit = 0xff,
    271   DW_EH_PE_uleb128 = 0x01,
    272   DW_EH_PE_udata2 = 0x02,
    273   DW_EH_PE_udata4 = 0x03,
    274   DW_EH_PE_udata8 = 0x04,
    275   DW_EH_PE_sleb128 = 0x09,
    276   DW_EH_PE_sdata2 = 0x0A,
    277   DW_EH_PE_sdata4 = 0x0B,
    278   DW_EH_PE_sdata8 = 0x0C,
    279   DW_EH_PE_signed = 0x08,
    280   DW_EH_PE_pcrel = 0x10,
    281   DW_EH_PE_textrel = 0x20,
    282   DW_EH_PE_datarel = 0x30,
    283   DW_EH_PE_funcrel = 0x40,
    284   DW_EH_PE_aligned = 0x50,
    285   DW_EH_PE_indirect = 0x80
    286 };
    287 
    288 /// Constants for location lists in DWARF v5.
    289 enum LocationListEntry : unsigned char {
    290   DW_LLE_end_of_list = 0x00,
    291   DW_LLE_base_addressx = 0x01,
    292   DW_LLE_startx_endx = 0x02,
    293   DW_LLE_startx_length = 0x03,
    294   DW_LLE_offset_pair = 0x04,
    295   DW_LLE_default_location = 0x05,
    296   DW_LLE_base_address = 0x06,
    297   DW_LLE_start_end = 0x07,
    298   DW_LLE_start_length = 0x08
    299 };
    300 
    301 /// Constants for the DW_APPLE_PROPERTY_attributes attribute.
    302 /// Keep this list in sync with clang's DeclSpec.h ObjCPropertyAttributeKind!
    303 enum ApplePropertyAttributes {
    304 #define HANDLE_DW_APPLE_PROPERTY(ID, NAME) DW_APPLE_PROPERTY_##NAME = ID,
    305 #include "llvm/Support/Dwarf.def"
    306 };
    307 
    308 /// Constants for unit types in DWARF v5.
    309 enum UnitType : unsigned char {
    310 #define HANDLE_DW_UT(ID, NAME) DW_UT_##NAME = ID,
    311 #include "llvm/Support/Dwarf.def"
    312   DW_UT_lo_user = 0x80,
    313   DW_UT_hi_user = 0xff
    314 };
    315 
    316 // Constants for the DWARF v5 Accelerator Table Proposal
    317 enum AcceleratorTable {
    318   // Data layout descriptors.
    319   DW_ATOM_null = 0u,       // Marker as the end of a list of atoms.
    320   DW_ATOM_die_offset = 1u, // DIE offset in the debug_info section.
    321   DW_ATOM_cu_offset = 2u, // Offset of the compile unit header that contains the
    322                           // item in question.
    323   DW_ATOM_die_tag = 3u,   // A tag entry.
    324   DW_ATOM_type_flags = 4u, // Set of flags for a type.
    325 
    326   // DW_ATOM_type_flags values.
    327 
    328   // Always set for C++, only set for ObjC if this is the @implementation for a
    329   // class.
    330   DW_FLAG_type_implementation = 2u,
    331 
    332   // Hash functions.
    333 
    334   // Daniel J. Bernstein hash.
    335   DW_hash_function_djb = 0u
    336 };
    337 
    338 // Constants for the GNU pubnames/pubtypes extensions supporting gdb index.
    339 enum GDBIndexEntryKind {
    340   GIEK_NONE,
    341   GIEK_TYPE,
    342   GIEK_VARIABLE,
    343   GIEK_FUNCTION,
    344   GIEK_OTHER,
    345   GIEK_UNUSED5,
    346   GIEK_UNUSED6,
    347   GIEK_UNUSED7
    348 };
    349 
    350 enum GDBIndexEntryLinkage {
    351   GIEL_EXTERNAL,
    352   GIEL_STATIC
    353 };
    354 
    355 /// \defgroup DwarfConstantsDumping Dwarf constants dumping functions
    356 ///
    357 /// All these functions map their argument's value back to the
    358 /// corresponding enumerator name or return nullptr if the value isn't
    359 /// known.
    360 ///
    361 /// @{
    362 StringRef TagString(unsigned Tag);
    363 StringRef ChildrenString(unsigned Children);
    364 StringRef AttributeString(unsigned Attribute);
    365 StringRef FormEncodingString(unsigned Encoding);
    366 StringRef OperationEncodingString(unsigned Encoding);
    367 StringRef AttributeEncodingString(unsigned Encoding);
    368 StringRef DecimalSignString(unsigned Sign);
    369 StringRef EndianityString(unsigned Endian);
    370 StringRef AccessibilityString(unsigned Access);
    371 StringRef VisibilityString(unsigned Visibility);
    372 StringRef VirtualityString(unsigned Virtuality);
    373 StringRef LanguageString(unsigned Language);
    374 StringRef CaseString(unsigned Case);
    375 StringRef ConventionString(unsigned Convention);
    376 StringRef InlineCodeString(unsigned Code);
    377 StringRef ArrayOrderString(unsigned Order);
    378 StringRef DiscriminantString(unsigned Discriminant);
    379 StringRef LNStandardString(unsigned Standard);
    380 StringRef LNExtendedString(unsigned Encoding);
    381 StringRef MacinfoString(unsigned Encoding);
    382 StringRef CallFrameString(unsigned Encoding);
    383 StringRef ApplePropertyString(unsigned);
    384 StringRef UnitTypeString(unsigned);
    385 StringRef AtomTypeString(unsigned Atom);
    386 StringRef GDBIndexEntryKindString(GDBIndexEntryKind Kind);
    387 StringRef GDBIndexEntryLinkageString(GDBIndexEntryLinkage Linkage);
    388 /// @}
    389 
    390 /// \defgroup DwarfConstantsParsing Dwarf constants parsing functions
    391 ///
    392 /// These functions map their strings back to the corresponding enumeration
    393 /// value or return 0 if there is none, except for these exceptions:
    394 ///
    395 /// \li \a getTag() returns \a DW_TAG_invalid on invalid input.
    396 /// \li \a getVirtuality() returns \a DW_VIRTUALITY_invalid on invalid input.
    397 /// \li \a getMacinfo() returns \a DW_MACINFO_invalid on invalid input.
    398 ///
    399 /// @{
    400 unsigned getTag(StringRef TagString);
    401 unsigned getOperationEncoding(StringRef OperationEncodingString);
    402 unsigned getVirtuality(StringRef VirtualityString);
    403 unsigned getLanguage(StringRef LanguageString);
    404 unsigned getCallingConvention(StringRef LanguageString);
    405 unsigned getAttributeEncoding(StringRef EncodingString);
    406 unsigned getMacinfo(StringRef MacinfoString);
    407 /// @}
    408 
    409 /// \brief Returns the symbolic string representing Val when used as a value
    410 /// for attribute Attr.
    411 StringRef AttributeValueString(uint16_t Attr, unsigned Val);
    412 
    413 /// \brief Decsribes an entry of the various gnu_pub* debug sections.
    414 ///
    415 /// The gnu_pub* kind looks like:
    416 ///
    417 /// 0-3  reserved
    418 /// 4-6  symbol kind
    419 /// 7    0 == global, 1 == static
    420 ///
    421 /// A gdb_index descriptor includes the above kind, shifted 24 bits up with the
    422 /// offset of the cu within the debug_info section stored in those 24 bits.
    423 struct PubIndexEntryDescriptor {
    424   GDBIndexEntryKind Kind;
    425   GDBIndexEntryLinkage Linkage;
    426   PubIndexEntryDescriptor(GDBIndexEntryKind Kind, GDBIndexEntryLinkage Linkage)
    427       : Kind(Kind), Linkage(Linkage) {}
    428   /* implicit */ PubIndexEntryDescriptor(GDBIndexEntryKind Kind)
    429       : Kind(Kind), Linkage(GIEL_EXTERNAL) {}
    430   explicit PubIndexEntryDescriptor(uint8_t Value)
    431       : Kind(static_cast<GDBIndexEntryKind>((Value & KIND_MASK) >>
    432                                             KIND_OFFSET)),
    433         Linkage(static_cast<GDBIndexEntryLinkage>((Value & LINKAGE_MASK) >>
    434                                                   LINKAGE_OFFSET)) {}
    435   uint8_t toBits() const {
    436     return Kind << KIND_OFFSET | Linkage << LINKAGE_OFFSET;
    437   }
    438 
    439 private:
    440   enum {
    441     KIND_OFFSET = 4,
    442     KIND_MASK = 7 << KIND_OFFSET,
    443     LINKAGE_OFFSET = 7,
    444     LINKAGE_MASK = 1 << LINKAGE_OFFSET
    445   };
    446 };
    447 
    448 /// Constants that define the DWARF format as 32 or 64 bit.
    449 enum DwarfFormat { DWARF32, DWARF64 };
    450 
    451 } // End of namespace dwarf
    452 
    453 } // End of namespace llvm
    454 
    455 #endif
    456