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/Support/Endian.h" 15 #include <functional> 16 #include <stdint.h> 17 18 namespace llvm { 19 20 class PDBSymDumper; 21 class PDBSymbol; 22 23 class IPDBDataStream; 24 template <class T> class IPDBEnumChildren; 25 class IPDBLineNumber; 26 class IPDBRawSymbol; 27 class IPDBSession; 28 class IPDBSourceFile; 29 30 typedef IPDBEnumChildren<PDBSymbol> IPDBEnumSymbols; 31 typedef IPDBEnumChildren<IPDBSourceFile> IPDBEnumSourceFiles; 32 typedef IPDBEnumChildren<IPDBDataStream> IPDBEnumDataStreams; 33 typedef IPDBEnumChildren<IPDBLineNumber> IPDBEnumLineNumbers; 34 35 class PDBSymbolExe; 36 class PDBSymbolCompiland; 37 class PDBSymbolCompilandDetails; 38 class PDBSymbolCompilandEnv; 39 class PDBSymbolFunc; 40 class PDBSymbolBlock; 41 class PDBSymbolData; 42 class PDBSymbolAnnotation; 43 class PDBSymbolLabel; 44 class PDBSymbolPublicSymbol; 45 class PDBSymbolTypeUDT; 46 class PDBSymbolTypeEnum; 47 class PDBSymbolTypeFunctionSig; 48 class PDBSymbolTypePointer; 49 class PDBSymbolTypeArray; 50 class PDBSymbolTypeBuiltin; 51 class PDBSymbolTypeTypedef; 52 class PDBSymbolTypeBaseClass; 53 class PDBSymbolTypeFriend; 54 class PDBSymbolTypeFunctionArg; 55 class PDBSymbolFuncDebugStart; 56 class PDBSymbolFuncDebugEnd; 57 class PDBSymbolUsingNamespace; 58 class PDBSymbolTypeVTableShape; 59 class PDBSymbolTypeVTable; 60 class PDBSymbolCustom; 61 class PDBSymbolThunk; 62 class PDBSymbolTypeCustom; 63 class PDBSymbolTypeManaged; 64 class PDBSymbolTypeDimension; 65 class PDBSymbolUnknown; 66 67 /// Specifies which PDB reader implementation is to be used. Only a value 68 /// of PDB_ReaderType::DIA is supported. 69 enum class PDB_ReaderType { 70 DIA = 0, 71 }; 72 73 /// Defines a 128-bit unique identifier. This maps to a GUID on Windows, but 74 /// is abstracted here for the purposes of non-Windows platforms that don't have 75 /// the GUID structure defined. 76 struct PDB_UniqueId { 77 uint64_t HighPart; 78 uint64_t LowPart; 79 }; 80 81 /// An enumeration indicating the type of data contained in this table. 82 enum class PDB_TableType { 83 Symbols, 84 SourceFiles, 85 LineNumbers, 86 SectionContribs, 87 Segments, 88 InjectedSources, 89 FrameData 90 }; 91 92 /// Defines flags used for enumerating child symbols. This corresponds to the 93 /// NameSearchOptions enumeration which is documented here: 94 /// https://msdn.microsoft.com/en-us/library/yat28ads.aspx 95 enum PDB_NameSearchFlags { 96 NS_Default = 0x0, 97 NS_CaseSensitive = 0x1, 98 NS_CaseInsensitive = 0x2, 99 NS_FileNameExtMatch = 0x4, 100 NS_Regex = 0x8, 101 NS_UndecoratedName = 0x10 102 }; 103 104 /// Specifies the hash algorithm that a source file from a PDB was hashed with. 105 /// This corresponds to the CV_SourceChksum_t enumeration and are documented 106 /// here: https://msdn.microsoft.com/en-us/library/e96az21x.aspx 107 enum class PDB_Checksum { None = 0, MD5 = 1, SHA1 = 2 }; 108 109 /// These values correspond to the CV_CPU_TYPE_e enumeration, and are documented 110 /// here: https://msdn.microsoft.com/en-us/library/b2fc64ek.aspx 111 enum class PDB_Cpu { 112 Intel8080 = 0x0, 113 Intel8086 = 0x1, 114 Intel80286 = 0x2, 115 Intel80386 = 0x3, 116 Intel80486 = 0x4, 117 Pentium = 0x5, 118 PentiumPro = 0x6, 119 Pentium3 = 0x7, 120 MIPS = 0x10, 121 MIPS16 = 0x11, 122 MIPS32 = 0x12, 123 MIPS64 = 0x13, 124 MIPSI = 0x14, 125 MIPSII = 0x15, 126 MIPSIII = 0x16, 127 MIPSIV = 0x17, 128 MIPSV = 0x18, 129 M68000 = 0x20, 130 M68010 = 0x21, 131 M68020 = 0x22, 132 M68030 = 0x23, 133 M68040 = 0x24, 134 Alpha = 0x30, 135 Alpha21164 = 0x31, 136 Alpha21164A = 0x32, 137 Alpha21264 = 0x33, 138 Alpha21364 = 0x34, 139 PPC601 = 0x40, 140 PPC603 = 0x41, 141 PPC604 = 0x42, 142 PPC620 = 0x43, 143 PPCFP = 0x44, 144 PPCBE = 0x45, 145 SH3 = 0x50, 146 SH3E = 0x51, 147 SH3DSP = 0x52, 148 SH4 = 0x53, 149 SHMedia = 0x54, 150 ARM3 = 0x60, 151 ARM4 = 0x61, 152 ARM4T = 0x62, 153 ARM5 = 0x63, 154 ARM5T = 0x64, 155 ARM6 = 0x65, 156 ARM_XMAC = 0x66, 157 ARM_WMMX = 0x67, 158 ARM7 = 0x68, 159 Omni = 0x70, 160 Ia64 = 0x80, 161 Ia64_2 = 0x81, 162 CEE = 0x90, 163 AM33 = 0xa0, 164 M32R = 0xb0, 165 TriCore = 0xc0, 166 X64 = 0xd0, 167 EBC = 0xe0, 168 Thumb = 0xf0, 169 ARMNT = 0xf4, 170 D3D11_Shader = 0x100, 171 }; 172 173 enum class PDB_Machine { 174 Invalid = 0xffff, 175 Unknown = 0x0, 176 Am33 = 0x13, 177 Amd64 = 0x8664, 178 Arm = 0x1C0, 179 ArmNT = 0x1C4, 180 Ebc = 0xEBC, 181 x86 = 0x14C, 182 Ia64 = 0x200, 183 M32R = 0x9041, 184 Mips16 = 0x266, 185 MipsFpu = 0x366, 186 MipsFpu16 = 0x466, 187 PowerPC = 0x1F0, 188 PowerPCFP = 0x1F1, 189 R4000 = 0x166, 190 SH3 = 0x1A2, 191 SH3DSP = 0x1A3, 192 SH4 = 0x1A6, 193 SH5 = 0x1A8, 194 Thumb = 0x1C2, 195 WceMipsV2 = 0x169 196 }; 197 198 /// These values correspond to the CV_call_e enumeration, and are documented 199 /// at the following locations: 200 /// https://msdn.microsoft.com/en-us/library/b2fc64ek.aspx 201 /// https://msdn.microsoft.com/en-us/library/windows/desktop/ms680207(v=vs.85).aspx 202 /// 203 enum class PDB_CallingConv { 204 NearCdecl = 0x00, 205 FarCdecl = 0x01, 206 NearPascal = 0x02, 207 FarPascal = 0x03, 208 NearFastcall = 0x04, 209 FarFastcall = 0x05, 210 Skipped = 0x06, 211 NearStdcall = 0x07, 212 FarStdcall = 0x08, 213 NearSyscall = 0x09, 214 FarSyscall = 0x0a, 215 Thiscall = 0x0b, 216 MipsCall = 0x0c, 217 Generic = 0x0d, 218 Alphacall = 0x0e, 219 Ppccall = 0x0f, 220 SuperHCall = 0x10, 221 Armcall = 0x11, 222 AM33call = 0x12, 223 Tricall = 0x13, 224 Sh5call = 0x14, 225 M32R = 0x15, 226 Clrcall = 0x16, 227 Inline = 0x17, 228 NearVectorcall = 0x18, 229 Reserved = 0x19, 230 }; 231 232 /// These values correspond to the CV_CFL_LANG enumeration, and are documented 233 /// here: https://msdn.microsoft.com/en-us/library/bw3aekw6.aspx 234 enum class PDB_Lang { 235 C = 0x00, 236 Cpp = 0x01, 237 Fortran = 0x02, 238 Masm = 0x03, 239 Pascal = 0x04, 240 Basic = 0x05, 241 Cobol = 0x06, 242 Link = 0x07, 243 Cvtres = 0x08, 244 Cvtpgd = 0x09, 245 CSharp = 0x0a, 246 VB = 0x0b, 247 ILAsm = 0x0c, 248 Java = 0x0d, 249 JScript = 0x0e, 250 MSIL = 0x0f, 251 HLSL = 0x10 252 }; 253 254 /// These values correspond to the DataKind enumeration, and are documented 255 /// here: https://msdn.microsoft.com/en-us/library/b2x2t313.aspx 256 enum class PDB_DataKind { 257 Unknown, 258 Local, 259 StaticLocal, 260 Param, 261 ObjectPtr, 262 FileStatic, 263 Global, 264 Member, 265 StaticMember, 266 Constant 267 }; 268 269 /// These values correspond to the SymTagEnum enumeration, and are documented 270 /// here: https://msdn.microsoft.com/en-us/library/bkedss5f.aspx 271 enum class PDB_SymType { 272 None, 273 Exe, 274 Compiland, 275 CompilandDetails, 276 CompilandEnv, 277 Function, 278 Block, 279 Data, 280 Annotation, 281 Label, 282 PublicSymbol, 283 UDT, 284 Enum, 285 FunctionSig, 286 PointerType, 287 ArrayType, 288 BuiltinType, 289 Typedef, 290 BaseClass, 291 Friend, 292 FunctionArg, 293 FuncDebugStart, 294 FuncDebugEnd, 295 UsingNamespace, 296 VTableShape, 297 VTable, 298 Custom, 299 Thunk, 300 CustomType, 301 ManagedType, 302 Dimension, 303 Max 304 }; 305 306 /// These values correspond to the LocationType enumeration, and are documented 307 /// here: https://msdn.microsoft.com/en-us/library/f57kaez3.aspx 308 enum class PDB_LocType { 309 Null, 310 Static, 311 TLS, 312 RegRel, 313 ThisRel, 314 Enregistered, 315 BitField, 316 Slot, 317 IlRel, 318 MetaData, 319 Constant, 320 Max 321 }; 322 323 /// These values correspond to the THUNK_ORDINAL enumeration, and are documented 324 /// here: https://msdn.microsoft.com/en-us/library/dh0k8hft.aspx 325 enum class PDB_ThunkOrdinal { 326 Standard, 327 ThisAdjustor, 328 Vcall, 329 Pcode, 330 UnknownLoad, 331 TrampIncremental, 332 BranchIsland 333 }; 334 335 /// These values correspond to the UdtKind enumeration, and are documented 336 /// here: https://msdn.microsoft.com/en-us/library/wcstk66t.aspx 337 enum class PDB_UdtType { Struct, Class, Union, Interface }; 338 339 /// These values correspond to the StackFrameTypeEnum enumeration, and are 340 /// documented here: https://msdn.microsoft.com/en-us/library/bc5207xw.aspx. 341 enum class PDB_StackFrameType { FPO, KernelTrap, KernelTSS, EBP, FrameData }; 342 343 /// These values correspond to the StackFrameTypeEnum enumeration, and are 344 /// documented here: https://msdn.microsoft.com/en-us/library/bc5207xw.aspx. 345 enum class PDB_MemoryType { Code, Data, Stack, HeapCode }; 346 347 /// These values correspond to the Basictype enumeration, and are documented 348 /// here: https://msdn.microsoft.com/en-us/library/4szdtzc3.aspx 349 enum class PDB_BuiltinType { 350 None = 0, 351 Void = 1, 352 Char = 2, 353 WCharT = 3, 354 Int = 6, 355 UInt = 7, 356 Float = 8, 357 BCD = 9, 358 Bool = 10, 359 Long = 13, 360 ULong = 14, 361 Currency = 25, 362 Date = 26, 363 Variant = 27, 364 Complex = 28, 365 Bitfield = 29, 366 BSTR = 30, 367 HResult = 31 368 }; 369 370 enum class PDB_RegisterId { 371 Unknown = 0, 372 VFrame = 30006, 373 AL = 1, 374 CL = 2, 375 DL = 3, 376 BL = 4, 377 AH = 5, 378 CH = 6, 379 DH = 7, 380 BH = 8, 381 AX = 9, 382 CX = 10, 383 DX = 11, 384 BX = 12, 385 SP = 13, 386 BP = 14, 387 SI = 15, 388 DI = 16, 389 EAX = 17, 390 ECX = 18, 391 EDX = 19, 392 EBX = 20, 393 ESP = 21, 394 EBP = 22, 395 ESI = 23, 396 EDI = 24, 397 ES = 25, 398 CS = 26, 399 SS = 27, 400 DS = 28, 401 FS = 29, 402 GS = 30, 403 IP = 31, 404 RAX = 328, 405 RBX = 329, 406 RCX = 330, 407 RDX = 331, 408 RSI = 332, 409 RDI = 333, 410 RBP = 334, 411 RSP = 335, 412 R8 = 336, 413 R9 = 337, 414 R10 = 338, 415 R11 = 339, 416 R12 = 340, 417 R13 = 341, 418 R14 = 342, 419 R15 = 343, 420 }; 421 422 enum class PDB_MemberAccess { Private = 1, Protected = 2, Public = 3 }; 423 424 enum class PDB_ErrorCode { 425 Success, 426 NoPdbImpl, 427 InvalidPath, 428 InvalidFileFormat, 429 InvalidParameter, 430 AlreadyLoaded, 431 UnknownError, 432 NoMemory, 433 DebugInfoMismatch 434 }; 435 436 struct VersionInfo { 437 uint32_t Major; 438 uint32_t Minor; 439 uint32_t Build; 440 uint32_t QFE; 441 }; 442 443 enum PDB_VariantType { 444 Empty, 445 Unknown, 446 Int8, 447 Int16, 448 Int32, 449 Int64, 450 Single, 451 Double, 452 UInt8, 453 UInt16, 454 UInt32, 455 UInt64, 456 Bool, 457 }; 458 459 struct Variant { 460 Variant() 461 : Type(PDB_VariantType::Empty) { 462 } 463 464 PDB_VariantType Type; 465 union { 466 bool Bool; 467 int8_t Int8; 468 int16_t Int16; 469 int32_t Int32; 470 int64_t Int64; 471 float Single; 472 double Double; 473 uint8_t UInt8; 474 uint16_t UInt16; 475 uint32_t UInt32; 476 uint64_t UInt64; 477 }; 478 #define VARIANT_EQUAL_CASE(Enum) \ 479 case PDB_VariantType::Enum: \ 480 return Enum == Other.Enum; 481 bool operator==(const Variant &Other) const { 482 if (Type != Other.Type) 483 return false; 484 switch (Type) { 485 VARIANT_EQUAL_CASE(Bool) 486 VARIANT_EQUAL_CASE(Int8) 487 VARIANT_EQUAL_CASE(Int16) 488 VARIANT_EQUAL_CASE(Int32) 489 VARIANT_EQUAL_CASE(Int64) 490 VARIANT_EQUAL_CASE(Single) 491 VARIANT_EQUAL_CASE(Double) 492 VARIANT_EQUAL_CASE(UInt8) 493 VARIANT_EQUAL_CASE(UInt16) 494 VARIANT_EQUAL_CASE(UInt32) 495 VARIANT_EQUAL_CASE(UInt64) 496 default: 497 return true; 498 } 499 } 500 #undef VARIANT_EQUAL_CASE 501 bool operator!=(const Variant &Other) const { return !(*this == Other); } 502 }; 503 504 namespace PDB { 505 static const char Magic[] = {'M', 'i', 'c', 'r', 'o', 's', 'o', 'f', 506 't', ' ', 'C', '/', 'C', '+', '+', ' ', 507 'M', 'S', 'F', ' ', '7', '.', '0', '0', 508 '\r', '\n', '\x1a', 'D', 'S', '\0', '\0', '\0'}; 509 510 // The superblock is overlaid at the beginning of the file (offset 0). 511 // It starts with a magic header and is followed by information which describes 512 // the layout of the file system. 513 struct SuperBlock { 514 char MagicBytes[sizeof(Magic)]; 515 // The file system is split into a variable number of fixed size elements. 516 // These elements are referred to as blocks. The size of a block may vary 517 // from system to system. 518 support::ulittle32_t BlockSize; 519 // This field's purpose is not yet known. 520 support::ulittle32_t Unknown0; 521 // This contains the number of blocks resident in the file system. In 522 // practice, NumBlocks * BlockSize is equivalent to the size of the PDB file. 523 support::ulittle32_t NumBlocks; 524 // This contains the number of bytes which make up the directory. 525 support::ulittle32_t NumDirectoryBytes; 526 // This field's purpose is not yet known. 527 support::ulittle32_t Unknown1; 528 // This contains the block # of the block map. 529 support::ulittle32_t BlockMapAddr; 530 }; 531 } 532 533 } // namespace llvm 534 535 namespace std { 536 template <> struct hash<llvm::PDB_SymType> { 537 typedef llvm::PDB_SymType argument_type; 538 typedef std::size_t result_type; 539 540 result_type operator()(const argument_type &Arg) const { 541 return std::hash<int>()(static_cast<int>(Arg)); 542 } 543 }; 544 } 545 546 547 #endif 548