Home | History | Annotate | Download | only in BinaryFormat
      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 
     39 enum LLVMConstants : uint32_t {
     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.
     52   DWARF_VENDOR_APPLE = 1,
     53   DWARF_VENDOR_BORLAND = 2,
     54   DWARF_VENDOR_GNU = 3,
     55   DWARF_VENDOR_GOOGLE = 4,
     56   DWARF_VENDOR_LLVM = 5,
     57   DWARF_VENDOR_MIPS = 6
     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 enum Tag : uint16_t {
     66 #define HANDLE_DW_TAG(ID, NAME, VERSION, VENDOR) DW_TAG_##NAME = ID,
     67 #include "llvm/BinaryFormat/Dwarf.def"
     68   DW_TAG_lo_user = 0x4080,
     69   DW_TAG_hi_user = 0xffff,
     70   DW_TAG_user_base = 0x1000 // Recommended base for user tags.
     71 };
     72 
     73 inline bool isType(Tag T) {
     74   switch (T) {
     75   case DW_TAG_array_type:
     76   case DW_TAG_class_type:
     77   case DW_TAG_interface_type:
     78   case DW_TAG_enumeration_type:
     79   case DW_TAG_pointer_type:
     80   case DW_TAG_reference_type:
     81   case DW_TAG_rvalue_reference_type:
     82   case DW_TAG_string_type:
     83   case DW_TAG_structure_type:
     84   case DW_TAG_subroutine_type:
     85   case DW_TAG_union_type:
     86   case DW_TAG_ptr_to_member_type:
     87   case DW_TAG_set_type:
     88   case DW_TAG_subrange_type:
     89   case DW_TAG_base_type:
     90   case DW_TAG_const_type:
     91   case DW_TAG_file_type:
     92   case DW_TAG_packed_type:
     93   case DW_TAG_volatile_type:
     94   case DW_TAG_typedef:
     95     return true;
     96   default:
     97     return false;
     98   }
     99 }
    100 
    101 /// Attributes.
    102 enum Attribute : uint16_t {
    103 #define HANDLE_DW_AT(ID, NAME, VERSION, VENDOR) DW_AT_##NAME = ID,
    104 #include "llvm/BinaryFormat/Dwarf.def"
    105   DW_AT_lo_user = 0x2000,
    106   DW_AT_hi_user = 0x3fff,
    107 };
    108 
    109 enum Form : uint16_t {
    110 #define HANDLE_DW_FORM(ID, NAME, VERSION, VENDOR) DW_FORM_##NAME = ID,
    111 #include "llvm/BinaryFormat/Dwarf.def"
    112   DW_FORM_lo_user = 0x1f00, ///< Not specified by DWARF.
    113 };
    114 
    115 enum LocationAtom {
    116 #define HANDLE_DW_OP(ID, NAME, VERSION, VENDOR) DW_OP_##NAME = ID,
    117 #include "llvm/BinaryFormat/Dwarf.def"
    118   DW_OP_lo_user = 0xe0,
    119   DW_OP_hi_user = 0xff,
    120   DW_OP_LLVM_fragment = 0x1000 ///< Only used in LLVM metadata.
    121 };
    122 
    123 enum TypeKind {
    124 #define HANDLE_DW_ATE(ID, NAME, VERSION, VENDOR) DW_ATE_##NAME = ID,
    125 #include "llvm/BinaryFormat/Dwarf.def"
    126   DW_ATE_lo_user = 0x80,
    127   DW_ATE_hi_user = 0xff
    128 };
    129 
    130 enum DecimalSignEncoding {
    131   // Decimal sign attribute values
    132   DW_DS_unsigned = 0x01,
    133   DW_DS_leading_overpunch = 0x02,
    134   DW_DS_trailing_overpunch = 0x03,
    135   DW_DS_leading_separate = 0x04,
    136   DW_DS_trailing_separate = 0x05
    137 };
    138 
    139 enum EndianityEncoding {
    140   // Endianity attribute values
    141   DW_END_default = 0x00,
    142   DW_END_big = 0x01,
    143   DW_END_little = 0x02,
    144   DW_END_lo_user = 0x40,
    145   DW_END_hi_user = 0xff
    146 };
    147 
    148 enum AccessAttribute {
    149   // Accessibility codes
    150   DW_ACCESS_public = 0x01,
    151   DW_ACCESS_protected = 0x02,
    152   DW_ACCESS_private = 0x03
    153 };
    154 
    155 enum VisibilityAttribute {
    156   // Visibility codes
    157   DW_VIS_local = 0x01,
    158   DW_VIS_exported = 0x02,
    159   DW_VIS_qualified = 0x03
    160 };
    161 
    162 enum VirtualityAttribute {
    163 #define HANDLE_DW_VIRTUALITY(ID, NAME) DW_VIRTUALITY_##NAME = ID,
    164 #include "llvm/BinaryFormat/Dwarf.def"
    165   DW_VIRTUALITY_max = 0x02
    166 };
    167 
    168 enum DefaultedMemberAttribute {
    169 #define HANDLE_DW_DEFAULTED(ID, NAME) DW_DEFAULTED_##NAME = ID,
    170 #include "llvm/BinaryFormat/Dwarf.def"
    171   DW_DEFAULTED_max = 0x02
    172 };
    173 
    174 enum SourceLanguage {
    175 #define HANDLE_DW_LANG(ID, NAME, VERSION, VENDOR) DW_LANG_##NAME = ID,
    176 #include "llvm/BinaryFormat/Dwarf.def"
    177   DW_LANG_lo_user = 0x8000,
    178   DW_LANG_hi_user = 0xffff
    179 };
    180 
    181 enum CaseSensitivity {
    182   // Identifier case codes
    183   DW_ID_case_sensitive = 0x00,
    184   DW_ID_up_case = 0x01,
    185   DW_ID_down_case = 0x02,
    186   DW_ID_case_insensitive = 0x03
    187 };
    188 
    189 enum CallingConvention {
    190 // Calling convention codes
    191 #define HANDLE_DW_CC(ID, NAME) DW_CC_##NAME = ID,
    192 #include "llvm/BinaryFormat/Dwarf.def"
    193   DW_CC_lo_user = 0x40,
    194   DW_CC_hi_user = 0xff
    195 };
    196 
    197 enum InlineAttribute {
    198   // Inline codes
    199   DW_INL_not_inlined = 0x00,
    200   DW_INL_inlined = 0x01,
    201   DW_INL_declared_not_inlined = 0x02,
    202   DW_INL_declared_inlined = 0x03
    203 };
    204 
    205 enum ArrayDimensionOrdering {
    206   // Array ordering
    207   DW_ORD_row_major = 0x00,
    208   DW_ORD_col_major = 0x01
    209 };
    210 
    211 enum DiscriminantList {
    212   // Discriminant descriptor values
    213   DW_DSC_label = 0x00,
    214   DW_DSC_range = 0x01
    215 };
    216 
    217 /// Line Number Standard Opcode Encodings.
    218 enum LineNumberOps : uint8_t {
    219 #define HANDLE_DW_LNS(ID, NAME) DW_LNS_##NAME = ID,
    220 #include "llvm/BinaryFormat/Dwarf.def"
    221 };
    222 
    223 /// Line Number Extended Opcode Encodings.
    224 enum LineNumberExtendedOps {
    225 #define HANDLE_DW_LNE(ID, NAME) DW_LNE_##NAME = ID,
    226 #include "llvm/BinaryFormat/Dwarf.def"
    227   DW_LNE_lo_user = 0x80,
    228   DW_LNE_hi_user = 0xff
    229 };
    230 
    231 enum LineNumberEntryFormat {
    232 #define HANDLE_DW_LNCT(ID, NAME) DW_LNCT_##NAME = ID,
    233 #include "llvm/BinaryFormat/Dwarf.def"
    234   DW_LNCT_lo_user = 0x2000,
    235   DW_LNCT_hi_user = 0x3fff,
    236 };
    237 
    238 enum MacinfoRecordType {
    239   // Macinfo Type Encodings
    240   DW_MACINFO_define = 0x01,
    241   DW_MACINFO_undef = 0x02,
    242   DW_MACINFO_start_file = 0x03,
    243   DW_MACINFO_end_file = 0x04,
    244   DW_MACINFO_vendor_ext = 0xff
    245 };
    246 
    247 /// DWARF v5 macro information entry type encodings.
    248 enum MacroEntryType {
    249 #define HANDLE_DW_MACRO(ID, NAME) DW_MACRO_##NAME = ID,
    250 #include "llvm/BinaryFormat/Dwarf.def"
    251   DW_MACRO_lo_user = 0xe0,
    252   DW_MACRO_hi_user = 0xff
    253 };
    254 
    255 /// DWARF v5 range list entry encoding values.
    256 enum RangeListEntries {
    257 #define HANDLE_DW_RLE(ID, NAME) DW_RLE_##NAME = ID,
    258 #include "llvm/BinaryFormat/Dwarf.def"
    259 };
    260 
    261 /// Call frame instruction encodings.
    262 enum CallFrameInfo {
    263 #define HANDLE_DW_CFA(ID, NAME) DW_CFA_##NAME = ID,
    264 #include "llvm/BinaryFormat/Dwarf.def"
    265   DW_CFA_extended = 0x00,
    266 
    267   DW_CFA_lo_user = 0x1c,
    268   DW_CFA_hi_user = 0x3f
    269 };
    270 
    271 enum Constants {
    272   // Children flag
    273   DW_CHILDREN_no = 0x00,
    274   DW_CHILDREN_yes = 0x01,
    275 
    276   DW_EH_PE_absptr = 0x00,
    277   DW_EH_PE_omit = 0xff,
    278   DW_EH_PE_uleb128 = 0x01,
    279   DW_EH_PE_udata2 = 0x02,
    280   DW_EH_PE_udata4 = 0x03,
    281   DW_EH_PE_udata8 = 0x04,
    282   DW_EH_PE_sleb128 = 0x09,
    283   DW_EH_PE_sdata2 = 0x0A,
    284   DW_EH_PE_sdata4 = 0x0B,
    285   DW_EH_PE_sdata8 = 0x0C,
    286   DW_EH_PE_signed = 0x08,
    287   DW_EH_PE_pcrel = 0x10,
    288   DW_EH_PE_textrel = 0x20,
    289   DW_EH_PE_datarel = 0x30,
    290   DW_EH_PE_funcrel = 0x40,
    291   DW_EH_PE_aligned = 0x50,
    292   DW_EH_PE_indirect = 0x80
    293 };
    294 
    295 /// Constants for location lists in DWARF v5.
    296 enum LocationListEntry : unsigned char {
    297   DW_LLE_end_of_list = 0x00,
    298   DW_LLE_base_addressx = 0x01,
    299   DW_LLE_startx_endx = 0x02,
    300   DW_LLE_startx_length = 0x03,
    301   DW_LLE_offset_pair = 0x04,
    302   DW_LLE_default_location = 0x05,
    303   DW_LLE_base_address = 0x06,
    304   DW_LLE_start_end = 0x07,
    305   DW_LLE_start_length = 0x08
    306 };
    307 
    308 /// Constants for the DW_APPLE_PROPERTY_attributes attribute.
    309 /// Keep this list in sync with clang's DeclSpec.h ObjCPropertyAttributeKind!
    310 enum ApplePropertyAttributes {
    311 #define HANDLE_DW_APPLE_PROPERTY(ID, NAME) DW_APPLE_PROPERTY_##NAME = ID,
    312 #include "llvm/BinaryFormat/Dwarf.def"
    313 };
    314 
    315 /// Constants for unit types in DWARF v5.
    316 enum UnitType : unsigned char {
    317 #define HANDLE_DW_UT(ID, NAME) DW_UT_##NAME = ID,
    318 #include "llvm/BinaryFormat/Dwarf.def"
    319   DW_UT_lo_user = 0x80,
    320   DW_UT_hi_user = 0xff
    321 };
    322 
    323 // Constants for the DWARF v5 Accelerator Table Proposal
    324 enum AcceleratorTable {
    325   // Data layout descriptors.
    326   DW_ATOM_null = 0u,       // Marker as the end of a list of atoms.
    327   DW_ATOM_die_offset = 1u, // DIE offset in the debug_info section.
    328   DW_ATOM_cu_offset = 2u, // Offset of the compile unit header that contains the
    329                           // item in question.
    330   DW_ATOM_die_tag = 3u,   // A tag entry.
    331   DW_ATOM_type_flags = 4u, // Set of flags for a type.
    332 
    333   // DW_ATOM_type_flags values.
    334 
    335   // Always set for C++, only set for ObjC if this is the @implementation for a
    336   // class.
    337   DW_FLAG_type_implementation = 2u,
    338 
    339   // Hash functions.
    340 
    341   // Daniel J. Bernstein hash.
    342   DW_hash_function_djb = 0u
    343 };
    344 
    345 // Constants for the GNU pubnames/pubtypes extensions supporting gdb index.
    346 enum GDBIndexEntryKind {
    347   GIEK_NONE,
    348   GIEK_TYPE,
    349   GIEK_VARIABLE,
    350   GIEK_FUNCTION,
    351   GIEK_OTHER,
    352   GIEK_UNUSED5,
    353   GIEK_UNUSED6,
    354   GIEK_UNUSED7
    355 };
    356 
    357 enum GDBIndexEntryLinkage { GIEL_EXTERNAL, GIEL_STATIC };
    358 
    359 /// \defgroup DwarfConstantsDumping Dwarf constants dumping functions
    360 ///
    361 /// All these functions map their argument's value back to the
    362 /// corresponding enumerator name or return nullptr if the value isn't
    363 /// known.
    364 ///
    365 /// @{
    366 StringRef TagString(unsigned Tag);
    367 StringRef ChildrenString(unsigned Children);
    368 StringRef AttributeString(unsigned Attribute);
    369 StringRef FormEncodingString(unsigned Encoding);
    370 StringRef OperationEncodingString(unsigned Encoding);
    371 StringRef AttributeEncodingString(unsigned Encoding);
    372 StringRef DecimalSignString(unsigned Sign);
    373 StringRef EndianityString(unsigned Endian);
    374 StringRef AccessibilityString(unsigned Access);
    375 StringRef VisibilityString(unsigned Visibility);
    376 StringRef VirtualityString(unsigned Virtuality);
    377 StringRef LanguageString(unsigned Language);
    378 StringRef CaseString(unsigned Case);
    379 StringRef ConventionString(unsigned Convention);
    380 StringRef InlineCodeString(unsigned Code);
    381 StringRef ArrayOrderString(unsigned Order);
    382 StringRef DiscriminantString(unsigned Discriminant);
    383 StringRef LNStandardString(unsigned Standard);
    384 StringRef LNExtendedString(unsigned Encoding);
    385 StringRef MacinfoString(unsigned Encoding);
    386 StringRef CallFrameString(unsigned Encoding);
    387 StringRef ApplePropertyString(unsigned);
    388 StringRef UnitTypeString(unsigned);
    389 StringRef AtomTypeString(unsigned Atom);
    390 StringRef GDBIndexEntryKindString(GDBIndexEntryKind Kind);
    391 StringRef GDBIndexEntryLinkageString(GDBIndexEntryLinkage Linkage);
    392 /// @}
    393 
    394 /// \defgroup DwarfConstantsParsing Dwarf constants parsing functions
    395 ///
    396 /// These functions map their strings back to the corresponding enumeration
    397 /// value or return 0 if there is none, except for these exceptions:
    398 ///
    399 /// \li \a getTag() returns \a DW_TAG_invalid on invalid input.
    400 /// \li \a getVirtuality() returns \a DW_VIRTUALITY_invalid on invalid input.
    401 /// \li \a getMacinfo() returns \a DW_MACINFO_invalid on invalid input.
    402 ///
    403 /// @{
    404 unsigned getTag(StringRef TagString);
    405 unsigned getOperationEncoding(StringRef OperationEncodingString);
    406 unsigned getVirtuality(StringRef VirtualityString);
    407 unsigned getLanguage(StringRef LanguageString);
    408 unsigned getCallingConvention(StringRef LanguageString);
    409 unsigned getAttributeEncoding(StringRef EncodingString);
    410 unsigned getMacinfo(StringRef MacinfoString);
    411 /// @}
    412 
    413 /// \defgroup DwarfConstantsVersioning Dwarf version for constants
    414 ///
    415 /// For constants defined by DWARF, returns the DWARF version when the constant
    416 /// was first defined. For vendor extensions, if there is a version-related
    417 /// policy for when to emit it, returns a version number for that policy.
    418 /// Otherwise returns 0.
    419 ///
    420 /// @{
    421 unsigned TagVersion(Tag T);
    422 unsigned AttributeVersion(Attribute A);
    423 unsigned FormVersion(Form F);
    424 unsigned OperationVersion(LocationAtom O);
    425 unsigned AttributeEncodingVersion(TypeKind E);
    426 unsigned LanguageVersion(SourceLanguage L);
    427 /// @}
    428 
    429 /// \defgroup DwarfConstantsVendor Dwarf "vendor" for constants
    430 ///
    431 /// These functions return an identifier describing "who" defined the constant,
    432 /// either the DWARF standard itself or the vendor who defined the extension.
    433 ///
    434 /// @{
    435 unsigned TagVendor(Tag T);
    436 unsigned AttributeVendor(Attribute A);
    437 unsigned FormVendor(Form F);
    438 unsigned OperationVendor(LocationAtom O);
    439 unsigned AttributeEncodingVendor(TypeKind E);
    440 unsigned LanguageVendor(SourceLanguage L);
    441 /// @}
    442 
    443 /// Tells whether the specified form is defined in the specified version,
    444 /// or is an extension if extensions are allowed.
    445 bool isValidFormForVersion(Form F, unsigned Version, bool ExtensionsOk = true);
    446 
    447 /// \brief Returns the symbolic string representing Val when used as a value
    448 /// for attribute Attr.
    449 StringRef AttributeValueString(uint16_t Attr, unsigned Val);
    450 
    451 /// \brief Decsribes an entry of the various gnu_pub* debug sections.
    452 ///
    453 /// The gnu_pub* kind looks like:
    454 ///
    455 /// 0-3  reserved
    456 /// 4-6  symbol kind
    457 /// 7    0 == global, 1 == static
    458 ///
    459 /// A gdb_index descriptor includes the above kind, shifted 24 bits up with the
    460 /// offset of the cu within the debug_info section stored in those 24 bits.
    461 struct PubIndexEntryDescriptor {
    462   GDBIndexEntryKind Kind;
    463   GDBIndexEntryLinkage Linkage;
    464   PubIndexEntryDescriptor(GDBIndexEntryKind Kind, GDBIndexEntryLinkage Linkage)
    465       : Kind(Kind), Linkage(Linkage) {}
    466   /* implicit */ PubIndexEntryDescriptor(GDBIndexEntryKind Kind)
    467       : Kind(Kind), Linkage(GIEL_EXTERNAL) {}
    468   explicit PubIndexEntryDescriptor(uint8_t Value)
    469       : Kind(
    470             static_cast<GDBIndexEntryKind>((Value & KIND_MASK) >> KIND_OFFSET)),
    471         Linkage(static_cast<GDBIndexEntryLinkage>((Value & LINKAGE_MASK) >>
    472                                                   LINKAGE_OFFSET)) {}
    473   uint8_t toBits() const {
    474     return Kind << KIND_OFFSET | Linkage << LINKAGE_OFFSET;
    475   }
    476 
    477 private:
    478   enum {
    479     KIND_OFFSET = 4,
    480     KIND_MASK = 7 << KIND_OFFSET,
    481     LINKAGE_OFFSET = 7,
    482     LINKAGE_MASK = 1 << LINKAGE_OFFSET
    483   };
    484 };
    485 
    486 /// Constants that define the DWARF format as 32 or 64 bit.
    487 enum DwarfFormat { DWARF32, DWARF64 };
    488 
    489 } // End of namespace dwarf
    490 
    491 } // End of namespace llvm
    492 
    493 #endif
    494