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