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