LCOV - code coverage report
Current view: top level - include/llvm/BinaryFormat - Dwarf.h (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 9 9 100.0 %
Date: 2017-09-14 15:23:50 Functions: 1 1 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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             : // 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         181 : inline bool isType(Tag T) {
      77         181 :   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         117 :   default:
     100         117 :     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             : 
     118             : enum LocationAtom {
     119             : #define HANDLE_DW_OP(ID, NAME, VERSION, VENDOR) DW_OP_##NAME = ID,
     120             : #include "llvm/BinaryFormat/Dwarf.def"
     121             :   DW_OP_lo_user = 0xe0,
     122             :   DW_OP_hi_user = 0xff,
     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"
     129             :   DW_ATE_lo_user = 0x80,
     130             :   DW_ATE_hi_user = 0xff
     131             : };
     132             : 
     133             : enum DecimalSignEncoding {
     134             :   // Decimal sign attribute values
     135             :   DW_DS_unsigned = 0x01,
     136             :   DW_DS_leading_overpunch = 0x02,
     137             :   DW_DS_trailing_overpunch = 0x03,
     138             :   DW_DS_leading_separate = 0x04,
     139             :   DW_DS_trailing_separate = 0x05
     140             : };
     141             : 
     142             : enum EndianityEncoding {
     143             :   // Endianity attribute values
     144             :   DW_END_default = 0x00,
     145             :   DW_END_big = 0x01,
     146             :   DW_END_little = 0x02,
     147             :   DW_END_lo_user = 0x40,
     148             :   DW_END_hi_user = 0xff
     149             : };
     150             : 
     151             : enum AccessAttribute {
     152             :   // Accessibility codes
     153             :   DW_ACCESS_public = 0x01,
     154             :   DW_ACCESS_protected = 0x02,
     155             :   DW_ACCESS_private = 0x03
     156             : };
     157             : 
     158             : enum VisibilityAttribute {
     159             :   // Visibility codes
     160             :   DW_VIS_local = 0x01,
     161             :   DW_VIS_exported = 0x02,
     162             :   DW_VIS_qualified = 0x03
     163             : };
     164             : 
     165             : enum VirtualityAttribute {
     166             : #define HANDLE_DW_VIRTUALITY(ID, NAME) DW_VIRTUALITY_##NAME = ID,
     167             : #include "llvm/BinaryFormat/Dwarf.def"
     168             :   DW_VIRTUALITY_max = 0x02
     169             : };
     170             : 
     171             : enum DefaultedMemberAttribute {
     172             : #define HANDLE_DW_DEFAULTED(ID, NAME) DW_DEFAULTED_##NAME = ID,
     173             : #include "llvm/BinaryFormat/Dwarf.def"
     174             :   DW_DEFAULTED_max = 0x02
     175             : };
     176             : 
     177             : enum SourceLanguage {
     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,
     181             :   DW_LANG_hi_user = 0xffff
     182             : };
     183             : 
     184             : enum CaseSensitivity {
     185             :   // Identifier case codes
     186             :   DW_ID_case_sensitive = 0x00,
     187             :   DW_ID_up_case = 0x01,
     188             :   DW_ID_down_case = 0x02,
     189             :   DW_ID_case_insensitive = 0x03
     190             : };
     191             : 
     192             : enum CallingConvention {
     193             : // Calling convention codes
     194             : #define HANDLE_DW_CC(ID, NAME) DW_CC_##NAME = ID,
     195             : #include "llvm/BinaryFormat/Dwarf.def"
     196             :   DW_CC_lo_user = 0x40,
     197             :   DW_CC_hi_user = 0xff
     198             : };
     199             : 
     200             : enum InlineAttribute {
     201             :   // Inline codes
     202             :   DW_INL_not_inlined = 0x00,
     203             :   DW_INL_inlined = 0x01,
     204             :   DW_INL_declared_not_inlined = 0x02,
     205             :   DW_INL_declared_inlined = 0x03
     206             : };
     207             : 
     208             : enum ArrayDimensionOrdering {
     209             :   // Array ordering
     210             :   DW_ORD_row_major = 0x00,
     211             :   DW_ORD_col_major = 0x01
     212             : };
     213             : 
     214             : enum DiscriminantList {
     215             :   // Discriminant descriptor values
     216             :   DW_DSC_label = 0x00,
     217             :   DW_DSC_range = 0x01
     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.
     227             : enum LineNumberExtendedOps {
     228             : #define HANDLE_DW_LNE(ID, NAME) DW_LNE_##NAME = ID,
     229             : #include "llvm/BinaryFormat/Dwarf.def"
     230             :   DW_LNE_lo_user = 0x80,
     231             :   DW_LNE_hi_user = 0xff
     232             : };
     233             : 
     234             : enum LineNumberEntryFormat {
     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             : 
     241             : enum MacinfoRecordType {
     242             :   // Macinfo Type Encodings
     243             :   DW_MACINFO_define = 0x01,
     244             :   DW_MACINFO_undef = 0x02,
     245             :   DW_MACINFO_start_file = 0x03,
     246             :   DW_MACINFO_end_file = 0x04,
     247             :   DW_MACINFO_vendor_ext = 0xff
     248             : };
     249             : 
     250             : /// DWARF v5 macro information entry type encodings.
     251             : enum MacroEntryType {
     252             : #define HANDLE_DW_MACRO(ID, NAME) DW_MACRO_##NAME = ID,
     253             : #include "llvm/BinaryFormat/Dwarf.def"
     254             :   DW_MACRO_lo_user = 0xe0,
     255             :   DW_MACRO_hi_user = 0xff
     256             : };
     257             : 
     258             : /// DWARF v5 range list entry encoding values.
     259             : enum RangeListEntries {
     260             : #define HANDLE_DW_RLE(ID, NAME) DW_RLE_##NAME = ID,
     261             : #include "llvm/BinaryFormat/Dwarf.def"
     262             : };
     263             : 
     264             : /// Call frame instruction encodings.
     265             : enum CallFrameInfo {
     266             : #define HANDLE_DW_CFA(ID, NAME) DW_CFA_##NAME = ID,
     267             : #include "llvm/BinaryFormat/Dwarf.def"
     268             :   DW_CFA_extended = 0x00,
     269             : 
     270             :   DW_CFA_lo_user = 0x1c,
     271             :   DW_CFA_hi_user = 0x3f
     272             : };
     273             : 
     274             : enum Constants {
     275             :   // Children flag
     276             :   DW_CHILDREN_no = 0x00,
     277             :   DW_CHILDREN_yes = 0x01,
     278             : 
     279             :   DW_EH_PE_absptr = 0x00,
     280             :   DW_EH_PE_omit = 0xff,
     281             :   DW_EH_PE_uleb128 = 0x01,
     282             :   DW_EH_PE_udata2 = 0x02,
     283             :   DW_EH_PE_udata4 = 0x03,
     284             :   DW_EH_PE_udata8 = 0x04,
     285             :   DW_EH_PE_sleb128 = 0x09,
     286             :   DW_EH_PE_sdata2 = 0x0A,
     287             :   DW_EH_PE_sdata4 = 0x0B,
     288             :   DW_EH_PE_sdata8 = 0x0C,
     289             :   DW_EH_PE_signed = 0x08,
     290             :   DW_EH_PE_pcrel = 0x10,
     291             :   DW_EH_PE_textrel = 0x20,
     292             :   DW_EH_PE_datarel = 0x30,
     293             :   DW_EH_PE_funcrel = 0x40,
     294             :   DW_EH_PE_aligned = 0x50,
     295             :   DW_EH_PE_indirect = 0x80
     296             : };
     297             : 
     298             : /// Constants for location lists in DWARF v5.
     299             : enum LocationListEntry : unsigned char {
     300             :   DW_LLE_end_of_list = 0x00,
     301             :   DW_LLE_base_addressx = 0x01,
     302             :   DW_LLE_startx_endx = 0x02,
     303             :   DW_LLE_startx_length = 0x03,
     304             :   DW_LLE_offset_pair = 0x04,
     305             :   DW_LLE_default_location = 0x05,
     306             :   DW_LLE_base_address = 0x06,
     307             :   DW_LLE_start_end = 0x07,
     308             :   DW_LLE_start_length = 0x08
     309             : };
     310             : 
     311             : /// Constants for the DW_APPLE_PROPERTY_attributes attribute.
     312             : /// Keep this list in sync with clang's DeclSpec.h ObjCPropertyAttributeKind!
     313             : enum ApplePropertyAttributes {
     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"
     322             :   DW_UT_lo_user = 0x80,
     323             :   DW_UT_hi_user = 0xff
     324             : };
     325             : 
     326             : // Constants for the DWARF v5 Accelerator Table Proposal
     327             : enum AcceleratorTable {
     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.
     340             :   DW_FLAG_type_implementation = 2u,
     341             : 
     342             :   // Hash functions.
     343             : 
     344             :   // Daniel J. Bernstein hash.
     345             :   DW_hash_function_djb = 0u
     346             : };
     347             : 
     348             : // Constants for the GNU pubnames/pubtypes extensions supporting gdb index.
     349             : enum GDBIndexEntryKind {
     350             :   GIEK_NONE,
     351             :   GIEK_TYPE,
     352             :   GIEK_VARIABLE,
     353             :   GIEK_FUNCTION,
     354             :   GIEK_OTHER,
     355             :   GIEK_UNUSED5,
     356             :   GIEK_UNUSED6,
     357             :   GIEK_UNUSED7
     358             : };
     359             : 
     360             : enum GDBIndexEntryLinkage { GIEL_EXTERNAL, GIEL_STATIC };
     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);
     371             : StringRef AttributeString(unsigned Attribute);
     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);
     378             : StringRef VisibilityString(unsigned Visibility);
     379             : StringRef VirtualityString(unsigned Virtuality);
     380             : StringRef LanguageString(unsigned Language);
     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);
     390             : StringRef ApplePropertyString(unsigned);
     391             : StringRef UnitTypeString(unsigned);
     392             : StringRef AtomTypeString(unsigned Atom);
     393             : StringRef GDBIndexEntryKindString(GDBIndexEntryKind Kind);
     394             : StringRef GDBIndexEntryLinkageString(GDBIndexEntryLinkage Linkage);
     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);
     428             : unsigned AttributeEncodingVersion(TypeKind E);
     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);
     442             : unsigned AttributeEncodingVendor(TypeKind E);
     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.
     464             : struct PubIndexEntryDescriptor {
     465             :   GDBIndexEntryKind Kind;
     466             :   GDBIndexEntryLinkage Linkage;
     467             :   PubIndexEntryDescriptor(GDBIndexEntryKind Kind, GDBIndexEntryLinkage Linkage)
     468             :       : Kind(Kind), Linkage(Linkage) {}
     469             :   /* implicit */ PubIndexEntryDescriptor(GDBIndexEntryKind Kind)
     470             :       : Kind(Kind), Linkage(GIEL_EXTERNAL) {}
     471             :   explicit PubIndexEntryDescriptor(uint8_t Value)
     472         533 :       : Kind(
     473         533 :             static_cast<GDBIndexEntryKind>((Value & KIND_MASK) >> KIND_OFFSET)),
     474         533 :         Linkage(static_cast<GDBIndexEntryLinkage>((Value & LINKAGE_MASK) >>
     475        1066 :                                                   LINKAGE_OFFSET)) {}
     476             :   uint8_t toBits() const {
     477          58 :     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

Generated by: LCOV version 1.13