Home | History | Annotate | Download | only in PDB
      1 //===- PDBTypes.h - Defines enums for various fields contained in PDB ---*-===//
      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 #ifndef LLVM_DEBUGINFO_PDB_PDBTYPES_H
     11 #define LLVM_DEBUGINFO_PDB_PDBTYPES_H
     12 
     13 #include "llvm/Config/llvm-config.h"
     14 #include "llvm/DebugInfo/CodeView/CodeView.h"
     15 #include <functional>
     16 #include <cstdint>
     17 #include <cstring>
     18 
     19 namespace llvm {
     20 namespace pdb {
     21 
     22 class PDBSymDumper;
     23 class PDBSymbol;
     24 
     25 class IPDBDataStream;
     26 template <class T> class IPDBEnumChildren;
     27 class IPDBLineNumber;
     28 class IPDBRawSymbol;
     29 class IPDBSession;
     30 class IPDBSourceFile;
     31 
     32 typedef IPDBEnumChildren<PDBSymbol> IPDBEnumSymbols;
     33 typedef IPDBEnumChildren<IPDBSourceFile> IPDBEnumSourceFiles;
     34 typedef IPDBEnumChildren<IPDBDataStream> IPDBEnumDataStreams;
     35 typedef IPDBEnumChildren<IPDBLineNumber> IPDBEnumLineNumbers;
     36 
     37 class PDBSymbolExe;
     38 class PDBSymbolCompiland;
     39 class PDBSymbolCompilandDetails;
     40 class PDBSymbolCompilandEnv;
     41 class PDBSymbolFunc;
     42 class PDBSymbolBlock;
     43 class PDBSymbolData;
     44 class PDBSymbolAnnotation;
     45 class PDBSymbolLabel;
     46 class PDBSymbolPublicSymbol;
     47 class PDBSymbolTypeUDT;
     48 class PDBSymbolTypeEnum;
     49 class PDBSymbolTypeFunctionSig;
     50 class PDBSymbolTypePointer;
     51 class PDBSymbolTypeArray;
     52 class PDBSymbolTypeBuiltin;
     53 class PDBSymbolTypeTypedef;
     54 class PDBSymbolTypeBaseClass;
     55 class PDBSymbolTypeFriend;
     56 class PDBSymbolTypeFunctionArg;
     57 class PDBSymbolFuncDebugStart;
     58 class PDBSymbolFuncDebugEnd;
     59 class PDBSymbolUsingNamespace;
     60 class PDBSymbolTypeVTableShape;
     61 class PDBSymbolTypeVTable;
     62 class PDBSymbolCustom;
     63 class PDBSymbolThunk;
     64 class PDBSymbolTypeCustom;
     65 class PDBSymbolTypeManaged;
     66 class PDBSymbolTypeDimension;
     67 class PDBSymbolUnknown;
     68 
     69 /// Specifies which PDB reader implementation is to be used.  Only a value
     70 /// of PDB_ReaderType::DIA is supported.
     71 enum class PDB_ReaderType {
     72   DIA = 0,
     73   Raw = 1,
     74 };
     75 
     76 /// Defines a 128-bit unique identifier.  This maps to a GUID on Windows, but
     77 /// is abstracted here for the purposes of non-Windows platforms that don't have
     78 /// the GUID structure defined.
     79 struct PDB_UniqueId {
     80   char Guid[16];
     81 };
     82 
     83 /// An enumeration indicating the type of data contained in this table.
     84 enum class PDB_TableType {
     85   Symbols,
     86   SourceFiles,
     87   LineNumbers,
     88   SectionContribs,
     89   Segments,
     90   InjectedSources,
     91   FrameData
     92 };
     93 
     94 /// Defines flags used for enumerating child symbols.  This corresponds to the
     95 /// NameSearchOptions enumeration which is documented here:
     96 /// https://msdn.microsoft.com/en-us/library/yat28ads.aspx
     97 enum PDB_NameSearchFlags {
     98   NS_Default = 0x0,
     99   NS_CaseSensitive = 0x1,
    100   NS_CaseInsensitive = 0x2,
    101   NS_FileNameExtMatch = 0x4,
    102   NS_Regex = 0x8,
    103   NS_UndecoratedName = 0x10
    104 };
    105 
    106 /// Specifies the hash algorithm that a source file from a PDB was hashed with.
    107 /// This corresponds to the CV_SourceChksum_t enumeration and are documented
    108 /// here: https://msdn.microsoft.com/en-us/library/e96az21x.aspx
    109 enum class PDB_Checksum { None = 0, MD5 = 1, SHA1 = 2 };
    110 
    111 /// These values correspond to the CV_CPU_TYPE_e enumeration, and are documented
    112 /// here: https://msdn.microsoft.com/en-us/library/b2fc64ek.aspx
    113 typedef codeview::CPUType PDB_Cpu;
    114 
    115 enum class PDB_Machine {
    116   Invalid = 0xffff,
    117   Unknown = 0x0,
    118   Am33 = 0x13,
    119   Amd64 = 0x8664,
    120   Arm = 0x1C0,
    121   ArmNT = 0x1C4,
    122   Ebc = 0xEBC,
    123   x86 = 0x14C,
    124   Ia64 = 0x200,
    125   M32R = 0x9041,
    126   Mips16 = 0x266,
    127   MipsFpu = 0x366,
    128   MipsFpu16 = 0x466,
    129   PowerPC = 0x1F0,
    130   PowerPCFP = 0x1F1,
    131   R4000 = 0x166,
    132   SH3 = 0x1A2,
    133   SH3DSP = 0x1A3,
    134   SH4 = 0x1A6,
    135   SH5 = 0x1A8,
    136   Thumb = 0x1C2,
    137   WceMipsV2 = 0x169
    138 };
    139 
    140 /// These values correspond to the CV_call_e enumeration, and are documented
    141 /// at the following locations:
    142 ///   https://msdn.microsoft.com/en-us/library/b2fc64ek.aspx
    143 ///   https://msdn.microsoft.com/en-us/library/windows/desktop/ms680207(v=vs.85).aspx
    144 ///
    145 typedef codeview::CallingConvention PDB_CallingConv;
    146 
    147 /// These values correspond to the CV_CFL_LANG enumeration, and are documented
    148 /// here: https://msdn.microsoft.com/en-us/library/bw3aekw6.aspx
    149 typedef codeview::SourceLanguage PDB_Lang;
    150 
    151 /// These values correspond to the DataKind enumeration, and are documented
    152 /// here: https://msdn.microsoft.com/en-us/library/b2x2t313.aspx
    153 enum class PDB_DataKind {
    154   Unknown,
    155   Local,
    156   StaticLocal,
    157   Param,
    158   ObjectPtr,
    159   FileStatic,
    160   Global,
    161   Member,
    162   StaticMember,
    163   Constant
    164 };
    165 
    166 /// These values correspond to the SymTagEnum enumeration, and are documented
    167 /// here: https://msdn.microsoft.com/en-us/library/bkedss5f.aspx
    168 enum class PDB_SymType {
    169   None,
    170   Exe,
    171   Compiland,
    172   CompilandDetails,
    173   CompilandEnv,
    174   Function,
    175   Block,
    176   Data,
    177   Annotation,
    178   Label,
    179   PublicSymbol,
    180   UDT,
    181   Enum,
    182   FunctionSig,
    183   PointerType,
    184   ArrayType,
    185   BuiltinType,
    186   Typedef,
    187   BaseClass,
    188   Friend,
    189   FunctionArg,
    190   FuncDebugStart,
    191   FuncDebugEnd,
    192   UsingNamespace,
    193   VTableShape,
    194   VTable,
    195   Custom,
    196   Thunk,
    197   CustomType,
    198   ManagedType,
    199   Dimension,
    200   Max
    201 };
    202 
    203 /// These values correspond to the LocationType enumeration, and are documented
    204 /// here: https://msdn.microsoft.com/en-us/library/f57kaez3.aspx
    205 enum class PDB_LocType {
    206   Null,
    207   Static,
    208   TLS,
    209   RegRel,
    210   ThisRel,
    211   Enregistered,
    212   BitField,
    213   Slot,
    214   IlRel,
    215   MetaData,
    216   Constant,
    217   Max
    218 };
    219 
    220 /// These values correspond to the UdtKind enumeration, and are documented
    221 /// here: https://msdn.microsoft.com/en-us/library/wcstk66t.aspx
    222 enum class PDB_UdtType { Struct, Class, Union, Interface };
    223 
    224 /// These values correspond to the StackFrameTypeEnum enumeration, and are
    225 /// documented here: https://msdn.microsoft.com/en-us/library/bc5207xw.aspx.
    226 enum class PDB_StackFrameType { FPO, KernelTrap, KernelTSS, EBP, FrameData };
    227 
    228 /// These values correspond to the StackFrameTypeEnum enumeration, and are
    229 /// documented here: https://msdn.microsoft.com/en-us/library/bc5207xw.aspx.
    230 enum class PDB_MemoryType { Code, Data, Stack, HeapCode };
    231 
    232 /// These values correspond to the Basictype enumeration, and are documented
    233 /// here: https://msdn.microsoft.com/en-us/library/4szdtzc3.aspx
    234 enum class PDB_BuiltinType {
    235   None = 0,
    236   Void = 1,
    237   Char = 2,
    238   WCharT = 3,
    239   Int = 6,
    240   UInt = 7,
    241   Float = 8,
    242   BCD = 9,
    243   Bool = 10,
    244   Long = 13,
    245   ULong = 14,
    246   Currency = 25,
    247   Date = 26,
    248   Variant = 27,
    249   Complex = 28,
    250   Bitfield = 29,
    251   BSTR = 30,
    252   HResult = 31
    253 };
    254 
    255 enum class PDB_MemberAccess { Private = 1, Protected = 2, Public = 3 };
    256 
    257 struct VersionInfo {
    258   uint32_t Major;
    259   uint32_t Minor;
    260   uint32_t Build;
    261   uint32_t QFE;
    262 };
    263 
    264 enum PDB_VariantType {
    265   Empty,
    266   Unknown,
    267   Int8,
    268   Int16,
    269   Int32,
    270   Int64,
    271   Single,
    272   Double,
    273   UInt8,
    274   UInt16,
    275   UInt32,
    276   UInt64,
    277   Bool,
    278   String
    279 };
    280 
    281 struct Variant {
    282   Variant() : Type(PDB_VariantType::Empty) {}
    283 
    284   Variant(const Variant &Other) : Type(PDB_VariantType::Empty) {
    285     *this = Other;
    286   }
    287 
    288   ~Variant() {
    289     if (Type == PDB_VariantType::String)
    290       delete[] Value.String;
    291   }
    292 
    293   PDB_VariantType Type;
    294   union {
    295     bool Bool;
    296     int8_t Int8;
    297     int16_t Int16;
    298     int32_t Int32;
    299     int64_t Int64;
    300     float Single;
    301     double Double;
    302     uint8_t UInt8;
    303     uint16_t UInt16;
    304     uint32_t UInt32;
    305     uint64_t UInt64;
    306     char *String;
    307   } Value;
    308 
    309 #define VARIANT_EQUAL_CASE(Enum)                                               \
    310   case PDB_VariantType::Enum:                                                  \
    311     return Value.Enum == Other.Value.Enum;
    312 
    313   bool operator==(const Variant &Other) const {
    314     if (Type != Other.Type)
    315       return false;
    316     switch (Type) {
    317       VARIANT_EQUAL_CASE(Bool)
    318       VARIANT_EQUAL_CASE(Int8)
    319       VARIANT_EQUAL_CASE(Int16)
    320       VARIANT_EQUAL_CASE(Int32)
    321       VARIANT_EQUAL_CASE(Int64)
    322       VARIANT_EQUAL_CASE(Single)
    323       VARIANT_EQUAL_CASE(Double)
    324       VARIANT_EQUAL_CASE(UInt8)
    325       VARIANT_EQUAL_CASE(UInt16)
    326       VARIANT_EQUAL_CASE(UInt32)
    327       VARIANT_EQUAL_CASE(UInt64)
    328       VARIANT_EQUAL_CASE(String)
    329     default:
    330       return true;
    331     }
    332   }
    333 
    334 #undef VARIANT_EQUAL_CASE
    335 
    336   bool operator!=(const Variant &Other) const { return !(*this == Other); }
    337   Variant &operator=(const Variant &Other) {
    338     if (this == &Other)
    339       return *this;
    340     if (Type == PDB_VariantType::String)
    341       delete[] Value.String;
    342     Type = Other.Type;
    343     Value = Other.Value;
    344     if (Other.Type == PDB_VariantType::String &&
    345         Other.Value.String != nullptr) {
    346       Value.String = new char[strlen(Other.Value.String) + 1];
    347       ::strcpy(Value.String, Other.Value.String);
    348     }
    349     return *this;
    350   }
    351 };
    352 
    353 } // end namespace llvm
    354 }
    355 
    356 namespace std {
    357 template <> struct hash<llvm::pdb::PDB_SymType> {
    358   typedef llvm::pdb::PDB_SymType argument_type;
    359   typedef std::size_t result_type;
    360 
    361   result_type operator()(const argument_type &Arg) const {
    362     return std::hash<int>()(static_cast<int>(Arg));
    363   }
    364 };
    365 } // end namespace std
    366 
    367 #endif // LLVM_DEBUGINFO_PDB_PDBTYPES_H
    368