Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:43:46

0001 //===- PDBTypes.h - Defines enums for various fields contained in PDB ----====//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLVM_DEBUGINFO_PDB_PDBTYPES_H
0010 #define LLVM_DEBUGINFO_PDB_PDBTYPES_H
0011 
0012 #include "llvm/ADT/APFloat.h"
0013 #include "llvm/DebugInfo/CodeView/CodeView.h"
0014 #include "llvm/DebugInfo/PDB/IPDBEnumChildren.h"
0015 #include "llvm/DebugInfo/PDB/IPDBFrameData.h"
0016 #include "llvm/DebugInfo/PDB/Native/RawTypes.h"
0017 #include <cctype>
0018 #include <cstddef>
0019 #include <cstdint>
0020 #include <cstring>
0021 #include <functional>
0022 
0023 namespace llvm {
0024 namespace pdb {
0025 
0026 typedef uint32_t SymIndexId;
0027 
0028 class IPDBDataStream;
0029 class IPDBInjectedSource;
0030 class IPDBLineNumber;
0031 class IPDBSectionContrib;
0032 class IPDBSession;
0033 class IPDBSourceFile;
0034 class IPDBTable;
0035 class PDBSymDumper;
0036 class PDBSymbol;
0037 class PDBSymbolExe;
0038 class PDBSymbolCompiland;
0039 class PDBSymbolCompilandDetails;
0040 class PDBSymbolCompilandEnv;
0041 class PDBSymbolFunc;
0042 class PDBSymbolBlock;
0043 class PDBSymbolData;
0044 class PDBSymbolAnnotation;
0045 class PDBSymbolLabel;
0046 class PDBSymbolPublicSymbol;
0047 class PDBSymbolTypeUDT;
0048 class PDBSymbolTypeEnum;
0049 class PDBSymbolTypeFunctionSig;
0050 class PDBSymbolTypePointer;
0051 class PDBSymbolTypeArray;
0052 class PDBSymbolTypeBuiltin;
0053 class PDBSymbolTypeTypedef;
0054 class PDBSymbolTypeBaseClass;
0055 class PDBSymbolTypeFriend;
0056 class PDBSymbolTypeFunctionArg;
0057 class PDBSymbolFuncDebugStart;
0058 class PDBSymbolFuncDebugEnd;
0059 class PDBSymbolUsingNamespace;
0060 class PDBSymbolTypeVTableShape;
0061 class PDBSymbolTypeVTable;
0062 class PDBSymbolCustom;
0063 class PDBSymbolThunk;
0064 class PDBSymbolTypeCustom;
0065 class PDBSymbolTypeManaged;
0066 class PDBSymbolTypeDimension;
0067 class PDBSymbolUnknown;
0068 
0069 using IPDBEnumSymbols = IPDBEnumChildren<PDBSymbol>;
0070 using IPDBEnumSourceFiles = IPDBEnumChildren<IPDBSourceFile>;
0071 using IPDBEnumDataStreams = IPDBEnumChildren<IPDBDataStream>;
0072 using IPDBEnumLineNumbers = IPDBEnumChildren<IPDBLineNumber>;
0073 using IPDBEnumTables = IPDBEnumChildren<IPDBTable>;
0074 using IPDBEnumInjectedSources = IPDBEnumChildren<IPDBInjectedSource>;
0075 using IPDBEnumSectionContribs = IPDBEnumChildren<IPDBSectionContrib>;
0076 using IPDBEnumFrameData = IPDBEnumChildren<IPDBFrameData>;
0077 
0078 /// Specifies which PDB reader implementation is to be used.  Only a value
0079 /// of PDB_ReaderType::DIA is currently supported, but Native is in the works.
0080 enum class PDB_ReaderType {
0081   DIA = 0,
0082   Native = 1,
0083 };
0084 
0085 /// An enumeration indicating the type of data contained in this table.
0086 enum class PDB_TableType {
0087   TableInvalid = 0,
0088   Symbols,
0089   SourceFiles,
0090   LineNumbers,
0091   SectionContribs,
0092   Segments,
0093   InjectedSources,
0094   FrameData,
0095   InputAssemblyFiles,
0096   Dbg
0097 };
0098 
0099 /// Defines flags used for enumerating child symbols.  This corresponds to the
0100 /// NameSearchOptions enumeration which is documented here:
0101 /// https://msdn.microsoft.com/en-us/library/yat28ads.aspx
0102 enum PDB_NameSearchFlags {
0103   NS_Default = 0x0,
0104   NS_CaseSensitive = 0x1,
0105   NS_CaseInsensitive = 0x2,
0106   NS_FileNameExtMatch = 0x4,
0107   NS_Regex = 0x8,
0108   NS_UndecoratedName = 0x10,
0109 
0110   // For backward compatibility.
0111   NS_CaseInFileNameExt = NS_CaseInsensitive | NS_FileNameExtMatch,
0112   NS_CaseRegex = NS_Regex | NS_CaseSensitive,
0113   NS_CaseInRex = NS_Regex | NS_CaseInsensitive
0114 };
0115 
0116 /// Specifies the hash algorithm that a source file from a PDB was hashed with.
0117 /// This corresponds to the CV_SourceChksum_t enumeration and are documented
0118 /// here: https://msdn.microsoft.com/en-us/library/e96az21x.aspx
0119 enum class PDB_Checksum { None = 0, MD5 = 1, SHA1 = 2, SHA256 = 3 };
0120 
0121 /// These values correspond to the CV_CPU_TYPE_e enumeration, and are documented
0122 /// here: https://msdn.microsoft.com/en-us/library/b2fc64ek.aspx
0123 using PDB_Cpu = codeview::CPUType;
0124 
0125 enum class PDB_Machine {
0126   Invalid = 0xffff,
0127   Unknown = 0x0,
0128   Am33 = 0x13,
0129   Amd64 = 0x8664,
0130   Arm = 0x1C0,
0131   Arm64 = 0xaa64,
0132   ArmNT = 0x1C4,
0133   Ebc = 0xEBC,
0134   x86 = 0x14C,
0135   Ia64 = 0x200,
0136   M32R = 0x9041,
0137   Mips16 = 0x266,
0138   MipsFpu = 0x366,
0139   MipsFpu16 = 0x466,
0140   PowerPC = 0x1F0,
0141   PowerPCFP = 0x1F1,
0142   R4000 = 0x166,
0143   SH3 = 0x1A2,
0144   SH3DSP = 0x1A3,
0145   SH4 = 0x1A6,
0146   SH5 = 0x1A8,
0147   Thumb = 0x1C2,
0148   WceMipsV2 = 0x169
0149 };
0150 
0151 // A struct with an inner unnamed enum with explicit underlying type resuls
0152 // in an enum class that can implicitly convert to the underlying type, which
0153 // is convenient for this enum.
0154 struct PDB_SourceCompression {
0155   enum : uint32_t {
0156     // No compression. Produced e.g. by `link.exe /natvis:foo.natvis`.
0157     None,
0158     // Not known what produces this.
0159     RunLengthEncoded,
0160     // Not known what produces this.
0161     Huffman,
0162     // Not known what produces this.
0163     LZ,
0164     // Produced e.g. by `csc /debug`. The encoded data is its own mini-stream
0165     // with the following layout (in little endian):
0166     //   GUID LanguageTypeGuid;
0167     //   GUID LanguageVendorGuid;
0168     //   GUID DocumentTypeGuid;
0169     //   GUID HashFunctionGuid;
0170     //   uint32_t HashDataSize;
0171     //   uint32_t CompressedDataSize;
0172     // Followed by HashDataSize bytes containing a hash checksum,
0173     // followed by CompressedDataSize bytes containing source contents.
0174     //
0175     // CompressedDataSize can be 0, in this case only the hash data is present.
0176     // (CompressedDataSize is != 0 e.g. if `/embed` is passed to csc.exe.)
0177     // The compressed data format is:
0178     //   uint32_t UncompressedDataSize;
0179     // If UncompressedDataSize is 0, the data is stored uncompressed and
0180     // CompressedDataSize stores the uncompressed size.
0181     // If UncompressedDataSize is != 0, then the data is in raw deflate
0182     // encoding as described in rfc1951.
0183     //
0184     // A GUID is 16 bytes, stored in the usual
0185     //   uint32_t
0186     //   uint16_t
0187     //   uint16_t
0188     //   uint8_t[24]
0189     // layout.
0190     //
0191     // Well-known GUIDs for LanguageTypeGuid are:
0192     //   63a08714-fc37-11d2-904c-00c04fa302a1 C
0193     //   3a12d0b7-c26c-11d0-b442-00a0244a1dd2 C++
0194     //   3f5162f8-07c6-11d3-9053-00c04fa302a1 C#
0195     //   af046cd1-d0e1-11d2-977c-00a0c9b4d50c Cobol
0196     //   ab4f38c9-b6e6-43ba-be3b-58080b2ccce3 F#
0197     //   3a12d0b4-c26c-11d0-b442-00a0244a1dd2 Java
0198     //   3a12d0b6-c26c-11d0-b442-00a0244a1dd2 JScript
0199     //   af046cd2-d0e1-11d2-977c-00a0c9b4d50c Pascal
0200     //   3a12d0b8-c26c-11d0-b442-00a0244a1dd2 Visual Basic
0201     //
0202     // Well-known GUIDs for LanguageVendorGuid are:
0203     //   994b45c4-e6e9-11d2-903f-00c04fa302a1 Microsoft
0204     //
0205     // Well-known GUIDs for DocumentTypeGuid are:
0206     //   5a869d0b-6611-11d3-bd2a-0000f80849bd Text
0207     //
0208     // Well-known GUIDs for HashFunctionGuid are:
0209     //   406ea660-64cf-4c82-b6f0-42d48172a799 MD5    (HashDataSize is 16)
0210     //   ff1816ec-aa5e-4d10-87f7-6f4963833460 SHA1   (HashDataSize is 20)
0211     //   8829d00f-11b8-4213-878b-770e8597ac16 SHA256 (HashDataSize is 32)
0212     DotNet = 101,
0213   };
0214 };
0215 
0216 /// These values correspond to the CV_call_e enumeration, and are documented
0217 /// at the following locations:
0218 ///   https://msdn.microsoft.com/en-us/library/b2fc64ek.aspx
0219 ///   https://msdn.microsoft.com/en-us/library/windows/desktop/ms680207(v=vs.85).aspx
0220 using PDB_CallingConv = codeview::CallingConvention;
0221 
0222 /// These values correspond to the CV_CFL_LANG enumeration, and are documented
0223 /// here: https://msdn.microsoft.com/en-us/library/bw3aekw6.aspx
0224 using PDB_Lang = codeview::SourceLanguage;
0225 
0226 /// These values correspond to the DataKind enumeration, and are documented
0227 /// here: https://msdn.microsoft.com/en-us/library/b2x2t313.aspx
0228 enum class PDB_DataKind {
0229   Unknown,
0230   Local,
0231   StaticLocal,
0232   Param,
0233   ObjectPtr,
0234   FileStatic,
0235   Global,
0236   Member,
0237   StaticMember,
0238   Constant
0239 };
0240 
0241 /// These values correspond to the SymTagEnum enumeration, and are documented
0242 /// here: https://msdn.microsoft.com/en-us/library/bkedss5f.aspx
0243 enum class PDB_SymType {
0244   None,
0245   Exe,
0246   Compiland,
0247   CompilandDetails,
0248   CompilandEnv,
0249   Function,
0250   Block,
0251   Data,
0252   Annotation,
0253   Label,
0254   PublicSymbol,
0255   UDT,
0256   Enum,
0257   FunctionSig,
0258   PointerType,
0259   ArrayType,
0260   BuiltinType,
0261   Typedef,
0262   BaseClass,
0263   Friend,
0264   FunctionArg,
0265   FuncDebugStart,
0266   FuncDebugEnd,
0267   UsingNamespace,
0268   VTableShape,
0269   VTable,
0270   Custom,
0271   Thunk,
0272   CustomType,
0273   ManagedType,
0274   Dimension,
0275   CallSite,
0276   InlineSite,
0277   BaseInterface,
0278   VectorType,
0279   MatrixType,
0280   HLSLType,
0281   Caller,
0282   Callee,
0283   Export,
0284   HeapAllocationSite,
0285   CoffGroup,
0286   Inlinee,
0287   Max
0288 };
0289 
0290 /// These values correspond to the LocationType enumeration, and are documented
0291 /// here: https://msdn.microsoft.com/en-us/library/f57kaez3.aspx
0292 enum class PDB_LocType {
0293   Null,
0294   Static,
0295   TLS,
0296   RegRel,
0297   ThisRel,
0298   Enregistered,
0299   BitField,
0300   Slot,
0301   IlRel,
0302   MetaData,
0303   Constant,
0304   RegRelAliasIndir,
0305   Max
0306 };
0307 
0308 /// These values correspond to the UdtKind enumeration, and are documented
0309 /// here: https://msdn.microsoft.com/en-us/library/wcstk66t.aspx
0310 enum class PDB_UdtType { Struct, Class, Union, Interface };
0311 
0312 /// These values correspond to the StackFrameTypeEnum enumeration, and are
0313 /// documented here: https://msdn.microsoft.com/en-us/library/bc5207xw.aspx.
0314 enum class PDB_StackFrameType : uint16_t {
0315   FPO,
0316   KernelTrap,
0317   KernelTSS,
0318   EBP,
0319   FrameData,
0320   Unknown = 0xffff
0321 };
0322 
0323 /// These values correspond to the MemoryTypeEnum enumeration, and are
0324 /// documented here: https://msdn.microsoft.com/en-us/library/ms165609.aspx.
0325 enum class PDB_MemoryType : uint16_t {
0326   Code,
0327   Data,
0328   Stack,
0329   HeapCode,
0330   Any = 0xffff
0331 };
0332 
0333 /// These values correspond to the Basictype enumeration, and are documented
0334 /// here: https://msdn.microsoft.com/en-us/library/4szdtzc3.aspx
0335 enum class PDB_BuiltinType {
0336   None = 0,
0337   Void = 1,
0338   Char = 2,
0339   WCharT = 3,
0340   Int = 6,
0341   UInt = 7,
0342   Float = 8,
0343   BCD = 9,
0344   Bool = 10,
0345   Long = 13,
0346   ULong = 14,
0347   Currency = 25,
0348   Date = 26,
0349   Variant = 27,
0350   Complex = 28,
0351   Bitfield = 29,
0352   BSTR = 30,
0353   HResult = 31,
0354   Char16 = 32,
0355   Char32 = 33,
0356   Char8 = 34,
0357 };
0358 
0359 /// These values correspond to the flags that can be combined to control the
0360 /// return of an undecorated name for a C++ decorated name, and are documented
0361 /// here: https://msdn.microsoft.com/en-us/library/kszfk0fs.aspx
0362 enum PDB_UndnameFlags : uint32_t {
0363   Undname_Complete = 0x0,
0364   Undname_NoLeadingUnderscores = 0x1,
0365   Undname_NoMsKeywords = 0x2,
0366   Undname_NoFuncReturns = 0x4,
0367   Undname_NoAllocModel = 0x8,
0368   Undname_NoAllocLang = 0x10,
0369   Undname_Reserved1 = 0x20,
0370   Undname_Reserved2 = 0x40,
0371   Undname_NoThisType = 0x60,
0372   Undname_NoAccessSpec = 0x80,
0373   Undname_NoThrowSig = 0x100,
0374   Undname_NoMemberType = 0x200,
0375   Undname_NoReturnUDTModel = 0x400,
0376   Undname_32BitDecode = 0x800,
0377   Undname_NameOnly = 0x1000,
0378   Undname_TypeOnly = 0x2000,
0379   Undname_HaveParams = 0x4000,
0380   Undname_NoECSU = 0x8000,
0381   Undname_NoIdentCharCheck = 0x10000,
0382   Undname_NoPTR64 = 0x20000
0383 };
0384 
0385 enum class PDB_MemberAccess { Private = 1, Protected = 2, Public = 3 };
0386 
0387 struct VersionInfo {
0388   uint32_t Major;
0389   uint32_t Minor;
0390   uint32_t Build;
0391   uint32_t QFE;
0392 };
0393 
0394 enum PDB_VariantType {
0395   Empty,
0396   Unknown,
0397   Int8,
0398   Int16,
0399   Int32,
0400   Int64,
0401   Single,
0402   Double,
0403   UInt8,
0404   UInt16,
0405   UInt32,
0406   UInt64,
0407   Bool,
0408   String
0409 };
0410 
0411 struct Variant {
0412   Variant() = default;
0413 
0414   explicit Variant(bool V) : Type(PDB_VariantType::Bool) { Value.Bool = V; }
0415   explicit Variant(int8_t V) : Type(PDB_VariantType::Int8) { Value.Int8 = V; }
0416   explicit Variant(int16_t V) : Type(PDB_VariantType::Int16) {
0417     Value.Int16 = V;
0418   }
0419   explicit Variant(int32_t V) : Type(PDB_VariantType::Int32) {
0420     Value.Int32 = V;
0421   }
0422   explicit Variant(int64_t V) : Type(PDB_VariantType::Int64) {
0423     Value.Int64 = V;
0424   }
0425   explicit Variant(float V) : Type(PDB_VariantType::Single) {
0426     Value.Single = V;
0427   }
0428   explicit Variant(double V) : Type(PDB_VariantType::Double) {
0429     Value.Double = V;
0430   }
0431   explicit Variant(uint8_t V) : Type(PDB_VariantType::UInt8) {
0432     Value.UInt8 = V;
0433   }
0434   explicit Variant(uint16_t V) : Type(PDB_VariantType::UInt16) {
0435     Value.UInt16 = V;
0436   }
0437   explicit Variant(uint32_t V) : Type(PDB_VariantType::UInt32) {
0438     Value.UInt32 = V;
0439   }
0440   explicit Variant(uint64_t V) : Type(PDB_VariantType::UInt64) {
0441     Value.UInt64 = V;
0442   }
0443 
0444   Variant(const Variant &Other) {
0445     *this = Other;
0446   }
0447 
0448   ~Variant() {
0449     if (Type == PDB_VariantType::String)
0450       delete[] Value.String;
0451   }
0452 
0453   PDB_VariantType Type = PDB_VariantType::Empty;
0454   union {
0455     bool Bool;
0456     int8_t Int8;
0457     int16_t Int16;
0458     int32_t Int32;
0459     int64_t Int64;
0460     float Single;
0461     double Double;
0462     uint8_t UInt8;
0463     uint16_t UInt16;
0464     uint32_t UInt32;
0465     uint64_t UInt64;
0466     char *String;
0467   } Value;
0468 
0469   bool isIntegralType() const {
0470     switch (Type) {
0471     case Bool:
0472     case Int8:
0473     case Int16:
0474     case Int32:
0475     case Int64:
0476     case UInt8:
0477     case UInt16:
0478     case UInt32:
0479     case UInt64:
0480       return true;
0481     default:
0482       return false;
0483     }
0484   }
0485 
0486 #define VARIANT_WIDTH(Enum, NumBits)                                           \
0487   case PDB_VariantType::Enum:                                                  \
0488     return NumBits;
0489 
0490   unsigned getBitWidth() const {
0491     switch (Type) {
0492       VARIANT_WIDTH(Bool, 1u)
0493       VARIANT_WIDTH(Int8, 8u)
0494       VARIANT_WIDTH(Int16, 16u)
0495       VARIANT_WIDTH(Int32, 32u)
0496       VARIANT_WIDTH(Int64, 64u)
0497       VARIANT_WIDTH(Single, 32u)
0498       VARIANT_WIDTH(Double, 64u)
0499       VARIANT_WIDTH(UInt8, 8u)
0500       VARIANT_WIDTH(UInt16, 16u)
0501       VARIANT_WIDTH(UInt32, 32u)
0502       VARIANT_WIDTH(UInt64, 64u)
0503     default:
0504       assert(false && "Variant::toAPSInt called on non-numeric type");
0505       return 0u;
0506     }
0507   }
0508 
0509 #undef VARIANT_WIDTH
0510 
0511 #define VARIANT_APSINT(Enum, NumBits, IsUnsigned)                              \
0512   case PDB_VariantType::Enum:                                                  \
0513     return APSInt(APInt(NumBits, Value.Enum), IsUnsigned);
0514 
0515   APSInt toAPSInt() const {
0516     switch (Type) {
0517       VARIANT_APSINT(Bool, 1u, true)
0518       VARIANT_APSINT(Int8, 8u, false)
0519       VARIANT_APSINT(Int16, 16u, false)
0520       VARIANT_APSINT(Int32, 32u, false)
0521       VARIANT_APSINT(Int64, 64u, false)
0522       VARIANT_APSINT(UInt8, 8u, true)
0523       VARIANT_APSINT(UInt16, 16u, true)
0524       VARIANT_APSINT(UInt32, 32u, true)
0525       VARIANT_APSINT(UInt64, 64u, true)
0526     default:
0527       assert(false && "Variant::toAPSInt called on non-integral type");
0528       return APSInt();
0529     }
0530   }
0531 
0532 #undef VARIANT_APSINT
0533 
0534   APFloat toAPFloat() const {
0535     // Float constants may be tagged as integers.
0536     switch (Type) {
0537     case PDB_VariantType::Single:
0538     case PDB_VariantType::UInt32:
0539     case PDB_VariantType::Int32:
0540       return APFloat(Value.Single);
0541     case PDB_VariantType::Double:
0542     case PDB_VariantType::UInt64:
0543     case PDB_VariantType::Int64:
0544       return APFloat(Value.Double);
0545     default:
0546       assert(false && "Variant::toAPFloat called on non-floating-point type");
0547       return APFloat::getZero(APFloat::IEEEsingle());
0548     }
0549   }
0550 
0551 #define VARIANT_EQUAL_CASE(Enum)                                               \
0552   case PDB_VariantType::Enum:                                                  \
0553     return Value.Enum == Other.Value.Enum;
0554 
0555   bool operator==(const Variant &Other) const {
0556     if (Type != Other.Type)
0557       return false;
0558     switch (Type) {
0559       VARIANT_EQUAL_CASE(Bool)
0560       VARIANT_EQUAL_CASE(Int8)
0561       VARIANT_EQUAL_CASE(Int16)
0562       VARIANT_EQUAL_CASE(Int32)
0563       VARIANT_EQUAL_CASE(Int64)
0564       VARIANT_EQUAL_CASE(Single)
0565       VARIANT_EQUAL_CASE(Double)
0566       VARIANT_EQUAL_CASE(UInt8)
0567       VARIANT_EQUAL_CASE(UInt16)
0568       VARIANT_EQUAL_CASE(UInt32)
0569       VARIANT_EQUAL_CASE(UInt64)
0570       VARIANT_EQUAL_CASE(String)
0571     default:
0572       return true;
0573     }
0574   }
0575 
0576 #undef VARIANT_EQUAL_CASE
0577 
0578   bool operator!=(const Variant &Other) const { return !(*this == Other); }
0579   Variant &operator=(const Variant &Other) {
0580     if (this == &Other)
0581       return *this;
0582     if (Type == PDB_VariantType::String)
0583       delete[] Value.String;
0584     Type = Other.Type;
0585     Value = Other.Value;
0586     if (Other.Type == PDB_VariantType::String &&
0587         Other.Value.String != nullptr) {
0588       Value.String = new char[strlen(Other.Value.String) + 1];
0589       ::strcpy(Value.String, Other.Value.String);
0590     }
0591     return *this;
0592   }
0593 };
0594 
0595 } // end namespace pdb
0596 } // end namespace llvm
0597 
0598 namespace std {
0599 
0600 template <> struct hash<llvm::pdb::PDB_SymType> {
0601   using argument_type = llvm::pdb::PDB_SymType;
0602   using result_type = std::size_t;
0603 
0604   result_type operator()(const argument_type &Arg) const {
0605     return std::hash<int>()(static_cast<int>(Arg));
0606   }
0607 };
0608 
0609 } // end namespace std
0610 
0611 #endif // LLVM_DEBUGINFO_PDB_PDBTYPES_H