1 //===- llvm/unittest/DebugInfo/PDB/PDBApiTest.cpp -------------------------===// 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 #include <unordered_map> 11 12 #include "llvm/ADT/STLExtras.h" 13 #include "llvm/DebugInfo/PDB/IPDBEnumChildren.h" 14 #include "llvm/DebugInfo/PDB/IPDBInjectedSource.h" 15 #include "llvm/DebugInfo/PDB/IPDBLineNumber.h" 16 #include "llvm/DebugInfo/PDB/IPDBRawSymbol.h" 17 #include "llvm/DebugInfo/PDB/IPDBSectionContrib.h" 18 #include "llvm/DebugInfo/PDB/IPDBSession.h" 19 #include "llvm/DebugInfo/PDB/IPDBSourceFile.h" 20 #include "llvm/DebugInfo/PDB/IPDBTable.h" 21 22 #include "llvm/DebugInfo/PDB/PDBSymbol.h" 23 #include "llvm/DebugInfo/PDB/PDBSymbolAnnotation.h" 24 #include "llvm/DebugInfo/PDB/PDBSymbolBlock.h" 25 #include "llvm/DebugInfo/PDB/PDBSymbolCompiland.h" 26 #include "llvm/DebugInfo/PDB/PDBSymbolCompilandDetails.h" 27 #include "llvm/DebugInfo/PDB/PDBSymbolCompilandEnv.h" 28 #include "llvm/DebugInfo/PDB/PDBSymbolCustom.h" 29 #include "llvm/DebugInfo/PDB/PDBSymbolData.h" 30 #include "llvm/DebugInfo/PDB/PDBSymbolExe.h" 31 #include "llvm/DebugInfo/PDB/PDBSymbolFunc.h" 32 #include "llvm/DebugInfo/PDB/PDBSymbolFuncDebugEnd.h" 33 #include "llvm/DebugInfo/PDB/PDBSymbolFuncDebugStart.h" 34 #include "llvm/DebugInfo/PDB/PDBSymbolLabel.h" 35 #include "llvm/DebugInfo/PDB/PDBSymbolPublicSymbol.h" 36 #include "llvm/DebugInfo/PDB/PDBSymbolThunk.h" 37 #include "llvm/DebugInfo/PDB/PDBSymbolTypeArray.h" 38 #include "llvm/DebugInfo/PDB/PDBSymbolTypeBaseClass.h" 39 #include "llvm/DebugInfo/PDB/PDBSymbolTypeBuiltin.h" 40 #include "llvm/DebugInfo/PDB/PDBSymbolTypeCustom.h" 41 #include "llvm/DebugInfo/PDB/PDBSymbolTypeDimension.h" 42 #include "llvm/DebugInfo/PDB/PDBSymbolTypeEnum.h" 43 #include "llvm/DebugInfo/PDB/PDBSymbolTypeFriend.h" 44 #include "llvm/DebugInfo/PDB/PDBSymbolTypeFunctionArg.h" 45 #include "llvm/DebugInfo/PDB/PDBSymbolTypeFunctionSig.h" 46 #include "llvm/DebugInfo/PDB/PDBSymbolTypeManaged.h" 47 #include "llvm/DebugInfo/PDB/PDBSymbolTypePointer.h" 48 #include "llvm/DebugInfo/PDB/PDBSymbolTypeTypedef.h" 49 #include "llvm/DebugInfo/PDB/PDBSymbolTypeUDT.h" 50 #include "llvm/DebugInfo/PDB/PDBSymbolTypeVTable.h" 51 #include "llvm/DebugInfo/PDB/PDBSymbolTypeVTableShape.h" 52 #include "llvm/DebugInfo/PDB/PDBSymbolUnknown.h" 53 #include "llvm/DebugInfo/PDB/PDBSymbolUsingNamespace.h" 54 #include "llvm/DebugInfo/PDB/PDBTypes.h" 55 #include "gtest/gtest.h" 56 using namespace llvm; 57 using namespace llvm::pdb; 58 59 namespace { 60 61 #define MOCK_SYMBOL_ACCESSOR(Func) \ 62 decltype(std::declval<IPDBRawSymbol>().Func()) Func() const override { \ 63 typedef decltype(IPDBRawSymbol::Func()) ReturnType; \ 64 return ReturnType(); \ 65 } 66 67 class MockSession : public IPDBSession { 68 uint64_t getLoadAddress() const override { return 0; } 69 bool setLoadAddress(uint64_t Address) override { return false; } 70 std::unique_ptr<PDBSymbolExe> getGlobalScope() override { return nullptr; } 71 std::unique_ptr<PDBSymbol> getSymbolById(uint32_t SymbolId) const override { 72 return nullptr; 73 } 74 std::unique_ptr<IPDBSourceFile> 75 getSourceFileById(uint32_t SymbolId) const override { 76 return nullptr; 77 } 78 bool addressForVA(uint64_t VA, uint32_t &Section, 79 uint32_t &Offset) const override { 80 return false; 81 } 82 bool addressForRVA(uint32_t RVA, uint32_t &Section, 83 uint32_t &Offset) const override { 84 return false; 85 } 86 std::unique_ptr<PDBSymbol> 87 findSymbolByAddress(uint64_t Address, PDB_SymType Type) const override { 88 return nullptr; 89 } 90 std::unique_ptr<IPDBEnumLineNumbers> 91 findLineNumbers(const PDBSymbolCompiland &Compiland, 92 const IPDBSourceFile &File) const override { 93 return nullptr; 94 } 95 std::unique_ptr<IPDBEnumLineNumbers> 96 findLineNumbersByAddress(uint64_t Address, uint32_t Length) const override { 97 return nullptr; 98 } 99 std::unique_ptr<IPDBEnumLineNumbers> 100 findLineNumbersByRVA(uint32_t RVA, uint32_t Length) const override { 101 return nullptr; 102 } 103 std::unique_ptr<IPDBEnumLineNumbers> 104 findLineNumbersBySectOffset(uint32_t Section, uint32_t Offset, 105 uint32_t Length) const override { 106 return nullptr; 107 } 108 std::unique_ptr<IPDBEnumSourceFiles> 109 findSourceFiles(const PDBSymbolCompiland *Compiland, llvm::StringRef Pattern, 110 PDB_NameSearchFlags Flags) const override { 111 return nullptr; 112 } 113 std::unique_ptr<IPDBSourceFile> 114 findOneSourceFile(const PDBSymbolCompiland *Compiland, 115 llvm::StringRef Pattern, 116 PDB_NameSearchFlags Flags) const override { 117 return nullptr; 118 } 119 std::unique_ptr<IPDBEnumChildren<PDBSymbolCompiland>> 120 findCompilandsForSourceFile(llvm::StringRef Pattern, 121 PDB_NameSearchFlags Flags) const override { 122 return nullptr; 123 } 124 std::unique_ptr<PDBSymbolCompiland> 125 findOneCompilandForSourceFile(llvm::StringRef Pattern, 126 PDB_NameSearchFlags Flags) const override { 127 return nullptr; 128 } 129 130 std::unique_ptr<IPDBEnumSourceFiles> getAllSourceFiles() const override { 131 return nullptr; 132 } 133 std::unique_ptr<IPDBEnumSourceFiles> getSourceFilesForCompiland( 134 const PDBSymbolCompiland &Compiland) const override { 135 return nullptr; 136 } 137 138 std::unique_ptr<IPDBEnumDataStreams> getDebugStreams() const override { 139 return nullptr; 140 } 141 142 std::unique_ptr<IPDBEnumTables> getEnumTables() const override { 143 return nullptr; 144 } 145 146 std::unique_ptr<IPDBEnumInjectedSources> getInjectedSources() const override { 147 return nullptr; 148 } 149 150 std::unique_ptr<IPDBEnumSectionContribs> getSectionContribs() const override { 151 return nullptr; 152 } 153 }; 154 155 class MockRawSymbol : public IPDBRawSymbol { 156 public: 157 MockRawSymbol(PDB_SymType SymType) 158 : Type(SymType) {} 159 160 void dump(raw_ostream &OS, int Indent) const override {} 161 162 std::unique_ptr<IPDBEnumSymbols> 163 findChildren(PDB_SymType Type) const override { 164 return nullptr; 165 } 166 std::unique_ptr<IPDBEnumSymbols> 167 findChildren(PDB_SymType Type, StringRef Name, 168 PDB_NameSearchFlags Flags) const override { 169 return nullptr; 170 } 171 std::unique_ptr<IPDBEnumSymbols> 172 findChildrenByAddr(PDB_SymType Type, StringRef Name, PDB_NameSearchFlags Flags, 173 uint32_t Section, uint32_t Offset) const override { 174 return nullptr; 175 } 176 std::unique_ptr<IPDBEnumSymbols> 177 findChildrenByVA(PDB_SymType Type, StringRef Name, PDB_NameSearchFlags Flags, 178 uint64_t VA) const override { 179 return nullptr; 180 } 181 std::unique_ptr<IPDBEnumSymbols> 182 findChildrenByRVA(PDB_SymType Type, StringRef Name, PDB_NameSearchFlags Flags, 183 uint32_t RVA) const override { 184 return nullptr; 185 } 186 std::unique_ptr<IPDBEnumSymbols> 187 findInlineFramesByAddr(uint32_t Section, uint32_t Offset) const override { 188 return nullptr; 189 } 190 std::unique_ptr<IPDBEnumSymbols> 191 findInlineFramesByRVA(uint32_t RVA) const override { 192 return nullptr; 193 } 194 std::unique_ptr<IPDBEnumSymbols> 195 findInlineFramesByVA(uint64_t VA) const override { 196 return nullptr; 197 } 198 std::unique_ptr<IPDBEnumLineNumbers> findInlineeLines() const override { 199 return nullptr; 200 } 201 std::unique_ptr<IPDBEnumLineNumbers> 202 findInlineeLinesByAddr(uint32_t Section, uint32_t Offset, 203 uint32_t Length) const override { 204 return nullptr; 205 } 206 std::unique_ptr<IPDBEnumLineNumbers> 207 findInlineeLinesByRVA(uint32_t RVA, uint32_t Length) const override { 208 return nullptr; 209 } 210 std::unique_ptr<IPDBEnumLineNumbers> 211 findInlineeLinesByVA(uint64_t VA, uint32_t Length) const override { 212 return nullptr; 213 } 214 215 void getDataBytes(llvm::SmallVector<uint8_t, 32> &bytes) const override {} 216 void getFrontEndVersion(VersionInfo &Version) const override {} 217 void getBackEndVersion(VersionInfo &Version) const override {} 218 219 PDB_SymType getSymTag() const override { return Type; } 220 221 std::string getUndecoratedNameEx(PDB_UndnameFlags Flags) const override { 222 return {}; 223 } 224 225 std::unique_ptr<IPDBLineNumber> getSrcLineOnTypeDefn() const override { 226 return nullptr; 227 } 228 229 MOCK_SYMBOL_ACCESSOR(getAccess) 230 MOCK_SYMBOL_ACCESSOR(getAddressOffset) 231 MOCK_SYMBOL_ACCESSOR(getAddressSection) 232 MOCK_SYMBOL_ACCESSOR(getAge) 233 MOCK_SYMBOL_ACCESSOR(getArrayIndexTypeId) 234 MOCK_SYMBOL_ACCESSOR(getBaseDataOffset) 235 MOCK_SYMBOL_ACCESSOR(getBaseDataSlot) 236 MOCK_SYMBOL_ACCESSOR(getBaseSymbolId) 237 MOCK_SYMBOL_ACCESSOR(getBuiltinType) 238 MOCK_SYMBOL_ACCESSOR(getBitPosition) 239 MOCK_SYMBOL_ACCESSOR(getCallingConvention) 240 MOCK_SYMBOL_ACCESSOR(getClassParentId) 241 MOCK_SYMBOL_ACCESSOR(getCompilerName) 242 MOCK_SYMBOL_ACCESSOR(getCount) 243 MOCK_SYMBOL_ACCESSOR(getCountLiveRanges) 244 MOCK_SYMBOL_ACCESSOR(getLanguage) 245 MOCK_SYMBOL_ACCESSOR(getLexicalParentId) 246 MOCK_SYMBOL_ACCESSOR(getLibraryName) 247 MOCK_SYMBOL_ACCESSOR(getLiveRangeStartAddressOffset) 248 MOCK_SYMBOL_ACCESSOR(getLiveRangeStartAddressSection) 249 MOCK_SYMBOL_ACCESSOR(getLiveRangeStartRelativeVirtualAddress) 250 MOCK_SYMBOL_ACCESSOR(getLocalBasePointerRegisterId) 251 MOCK_SYMBOL_ACCESSOR(getLowerBoundId) 252 MOCK_SYMBOL_ACCESSOR(getMemorySpaceKind) 253 MOCK_SYMBOL_ACCESSOR(getName) 254 MOCK_SYMBOL_ACCESSOR(getNumberOfAcceleratorPointerTags) 255 MOCK_SYMBOL_ACCESSOR(getNumberOfColumns) 256 MOCK_SYMBOL_ACCESSOR(getNumberOfModifiers) 257 MOCK_SYMBOL_ACCESSOR(getNumberOfRegisterIndices) 258 MOCK_SYMBOL_ACCESSOR(getNumberOfRows) 259 MOCK_SYMBOL_ACCESSOR(getObjectFileName) 260 MOCK_SYMBOL_ACCESSOR(getOemId) 261 MOCK_SYMBOL_ACCESSOR(getOemSymbolId) 262 MOCK_SYMBOL_ACCESSOR(getOffsetInUdt) 263 MOCK_SYMBOL_ACCESSOR(getPlatform) 264 MOCK_SYMBOL_ACCESSOR(getRank) 265 MOCK_SYMBOL_ACCESSOR(getRegisterId) 266 MOCK_SYMBOL_ACCESSOR(getRegisterType) 267 MOCK_SYMBOL_ACCESSOR(getRelativeVirtualAddress) 268 MOCK_SYMBOL_ACCESSOR(getSamplerSlot) 269 MOCK_SYMBOL_ACCESSOR(getSignature) 270 MOCK_SYMBOL_ACCESSOR(getSizeInUdt) 271 MOCK_SYMBOL_ACCESSOR(getSlot) 272 MOCK_SYMBOL_ACCESSOR(getSourceFileName) 273 MOCK_SYMBOL_ACCESSOR(getStride) 274 MOCK_SYMBOL_ACCESSOR(getSubTypeId) 275 MOCK_SYMBOL_ACCESSOR(getSymbolsFileName) 276 MOCK_SYMBOL_ACCESSOR(getSymIndexId) 277 MOCK_SYMBOL_ACCESSOR(getTargetOffset) 278 MOCK_SYMBOL_ACCESSOR(getTargetRelativeVirtualAddress) 279 MOCK_SYMBOL_ACCESSOR(getTargetVirtualAddress) 280 MOCK_SYMBOL_ACCESSOR(getTargetSection) 281 MOCK_SYMBOL_ACCESSOR(getTextureSlot) 282 MOCK_SYMBOL_ACCESSOR(getTimeStamp) 283 MOCK_SYMBOL_ACCESSOR(getToken) 284 MOCK_SYMBOL_ACCESSOR(getTypeId) 285 MOCK_SYMBOL_ACCESSOR(getUavSlot) 286 MOCK_SYMBOL_ACCESSOR(getUndecoratedName) 287 MOCK_SYMBOL_ACCESSOR(getUnmodifiedTypeId) 288 MOCK_SYMBOL_ACCESSOR(getUpperBoundId) 289 MOCK_SYMBOL_ACCESSOR(getVirtualBaseDispIndex) 290 MOCK_SYMBOL_ACCESSOR(getVirtualBaseOffset) 291 MOCK_SYMBOL_ACCESSOR(getVirtualTableShapeId) 292 MOCK_SYMBOL_ACCESSOR(getDataKind) 293 MOCK_SYMBOL_ACCESSOR(getGuid) 294 MOCK_SYMBOL_ACCESSOR(getOffset) 295 MOCK_SYMBOL_ACCESSOR(getThisAdjust) 296 MOCK_SYMBOL_ACCESSOR(getVirtualBasePointerOffset) 297 MOCK_SYMBOL_ACCESSOR(getLocationType) 298 MOCK_SYMBOL_ACCESSOR(getMachineType) 299 MOCK_SYMBOL_ACCESSOR(getThunkOrdinal) 300 MOCK_SYMBOL_ACCESSOR(getLength) 301 MOCK_SYMBOL_ACCESSOR(getVirtualBaseTableType) 302 MOCK_SYMBOL_ACCESSOR(getLiveRangeLength) 303 MOCK_SYMBOL_ACCESSOR(getVirtualAddress) 304 MOCK_SYMBOL_ACCESSOR(getUdtKind) 305 MOCK_SYMBOL_ACCESSOR(hasConstructor) 306 MOCK_SYMBOL_ACCESSOR(hasCustomCallingConvention) 307 MOCK_SYMBOL_ACCESSOR(hasFarReturn) 308 MOCK_SYMBOL_ACCESSOR(isCode) 309 MOCK_SYMBOL_ACCESSOR(isCompilerGenerated) 310 MOCK_SYMBOL_ACCESSOR(isConstType) 311 MOCK_SYMBOL_ACCESSOR(isEditAndContinueEnabled) 312 MOCK_SYMBOL_ACCESSOR(isFunction) 313 MOCK_SYMBOL_ACCESSOR(getAddressTaken) 314 MOCK_SYMBOL_ACCESSOR(getNoStackOrdering) 315 MOCK_SYMBOL_ACCESSOR(hasAlloca) 316 MOCK_SYMBOL_ACCESSOR(hasAssignmentOperator) 317 MOCK_SYMBOL_ACCESSOR(hasCTypes) 318 MOCK_SYMBOL_ACCESSOR(hasCastOperator) 319 MOCK_SYMBOL_ACCESSOR(hasDebugInfo) 320 MOCK_SYMBOL_ACCESSOR(hasEH) 321 MOCK_SYMBOL_ACCESSOR(hasEHa) 322 MOCK_SYMBOL_ACCESSOR(hasFramePointer) 323 MOCK_SYMBOL_ACCESSOR(hasInlAsm) 324 MOCK_SYMBOL_ACCESSOR(hasInlineAttribute) 325 MOCK_SYMBOL_ACCESSOR(hasInterruptReturn) 326 MOCK_SYMBOL_ACCESSOR(hasLongJump) 327 MOCK_SYMBOL_ACCESSOR(hasManagedCode) 328 MOCK_SYMBOL_ACCESSOR(hasNestedTypes) 329 MOCK_SYMBOL_ACCESSOR(hasNoInlineAttribute) 330 MOCK_SYMBOL_ACCESSOR(hasNoReturnAttribute) 331 MOCK_SYMBOL_ACCESSOR(hasOptimizedCodeDebugInfo) 332 MOCK_SYMBOL_ACCESSOR(hasOverloadedOperator) 333 MOCK_SYMBOL_ACCESSOR(hasSEH) 334 MOCK_SYMBOL_ACCESSOR(hasSecurityChecks) 335 MOCK_SYMBOL_ACCESSOR(hasSetJump) 336 MOCK_SYMBOL_ACCESSOR(hasStrictGSCheck) 337 MOCK_SYMBOL_ACCESSOR(isAcceleratorGroupSharedLocal) 338 MOCK_SYMBOL_ACCESSOR(isAcceleratorPointerTagLiveRange) 339 MOCK_SYMBOL_ACCESSOR(isAcceleratorStubFunction) 340 MOCK_SYMBOL_ACCESSOR(isAggregated) 341 MOCK_SYMBOL_ACCESSOR(isIntroVirtualFunction) 342 MOCK_SYMBOL_ACCESSOR(isCVTCIL) 343 MOCK_SYMBOL_ACCESSOR(isConstructorVirtualBase) 344 MOCK_SYMBOL_ACCESSOR(isCxxReturnUdt) 345 MOCK_SYMBOL_ACCESSOR(isDataAligned) 346 MOCK_SYMBOL_ACCESSOR(isHLSLData) 347 MOCK_SYMBOL_ACCESSOR(isHotpatchable) 348 MOCK_SYMBOL_ACCESSOR(isIndirectVirtualBaseClass) 349 MOCK_SYMBOL_ACCESSOR(isInterfaceUdt) 350 MOCK_SYMBOL_ACCESSOR(isIntrinsic) 351 MOCK_SYMBOL_ACCESSOR(isLTCG) 352 MOCK_SYMBOL_ACCESSOR(isLocationControlFlowDependent) 353 MOCK_SYMBOL_ACCESSOR(isMSILNetmodule) 354 MOCK_SYMBOL_ACCESSOR(isMatrixRowMajor) 355 MOCK_SYMBOL_ACCESSOR(isManagedCode) 356 MOCK_SYMBOL_ACCESSOR(isMSILCode) 357 MOCK_SYMBOL_ACCESSOR(isMultipleInheritance) 358 MOCK_SYMBOL_ACCESSOR(isNaked) 359 MOCK_SYMBOL_ACCESSOR(isNested) 360 MOCK_SYMBOL_ACCESSOR(isOptimizedAway) 361 MOCK_SYMBOL_ACCESSOR(isPacked) 362 MOCK_SYMBOL_ACCESSOR(isPointerBasedOnSymbolValue) 363 MOCK_SYMBOL_ACCESSOR(isPointerToDataMember) 364 MOCK_SYMBOL_ACCESSOR(isPointerToMemberFunction) 365 MOCK_SYMBOL_ACCESSOR(isPureVirtual) 366 MOCK_SYMBOL_ACCESSOR(isRValueReference) 367 MOCK_SYMBOL_ACCESSOR(isRefUdt) 368 MOCK_SYMBOL_ACCESSOR(isReference) 369 MOCK_SYMBOL_ACCESSOR(isRestrictedType) 370 MOCK_SYMBOL_ACCESSOR(isReturnValue) 371 MOCK_SYMBOL_ACCESSOR(isSafeBuffers) 372 MOCK_SYMBOL_ACCESSOR(isScoped) 373 MOCK_SYMBOL_ACCESSOR(isSdl) 374 MOCK_SYMBOL_ACCESSOR(isSingleInheritance) 375 MOCK_SYMBOL_ACCESSOR(isSplitted) 376 MOCK_SYMBOL_ACCESSOR(isStatic) 377 MOCK_SYMBOL_ACCESSOR(hasPrivateSymbols) 378 MOCK_SYMBOL_ACCESSOR(isUnalignedType) 379 MOCK_SYMBOL_ACCESSOR(isUnreached) 380 MOCK_SYMBOL_ACCESSOR(isValueUdt) 381 MOCK_SYMBOL_ACCESSOR(isVirtual) 382 MOCK_SYMBOL_ACCESSOR(isVirtualBaseClass) 383 MOCK_SYMBOL_ACCESSOR(isVirtualInheritance) 384 MOCK_SYMBOL_ACCESSOR(isVolatileType) 385 MOCK_SYMBOL_ACCESSOR(getValue) 386 MOCK_SYMBOL_ACCESSOR(wasInlined) 387 MOCK_SYMBOL_ACCESSOR(getUnused) 388 389 private: 390 PDB_SymType Type; 391 }; 392 393 class PDBApiTest : public testing::Test { 394 public: 395 std::unordered_map<PDB_SymType, std::unique_ptr<PDBSymbol>> SymbolMap; 396 397 void SetUp() override { 398 Session.reset(new MockSession()); 399 400 InsertItemWithTag(PDB_SymType::None); 401 InsertItemWithTag(PDB_SymType::Exe); 402 InsertItemWithTag(PDB_SymType::Compiland); 403 InsertItemWithTag(PDB_SymType::CompilandDetails); 404 InsertItemWithTag(PDB_SymType::CompilandEnv); 405 InsertItemWithTag(PDB_SymType::Function); 406 InsertItemWithTag(PDB_SymType::Block); 407 InsertItemWithTag(PDB_SymType::Data); 408 InsertItemWithTag(PDB_SymType::Annotation); 409 InsertItemWithTag(PDB_SymType::Label); 410 InsertItemWithTag(PDB_SymType::PublicSymbol); 411 InsertItemWithTag(PDB_SymType::UDT); 412 InsertItemWithTag(PDB_SymType::Enum); 413 InsertItemWithTag(PDB_SymType::FunctionSig); 414 InsertItemWithTag(PDB_SymType::PointerType); 415 InsertItemWithTag(PDB_SymType::ArrayType); 416 InsertItemWithTag(PDB_SymType::BuiltinType); 417 InsertItemWithTag(PDB_SymType::Typedef); 418 InsertItemWithTag(PDB_SymType::BaseClass); 419 InsertItemWithTag(PDB_SymType::Friend); 420 InsertItemWithTag(PDB_SymType::FunctionArg); 421 InsertItemWithTag(PDB_SymType::FuncDebugStart); 422 InsertItemWithTag(PDB_SymType::FuncDebugEnd); 423 InsertItemWithTag(PDB_SymType::UsingNamespace); 424 InsertItemWithTag(PDB_SymType::VTableShape); 425 InsertItemWithTag(PDB_SymType::VTable); 426 InsertItemWithTag(PDB_SymType::Custom); 427 InsertItemWithTag(PDB_SymType::Thunk); 428 InsertItemWithTag(PDB_SymType::CustomType); 429 InsertItemWithTag(PDB_SymType::ManagedType); 430 InsertItemWithTag(PDB_SymType::Dimension); 431 InsertItemWithTag(PDB_SymType::Max); 432 } 433 434 template <class ExpectedType> void VerifyDyncast(PDB_SymType Tag) { 435 for (auto item = SymbolMap.begin(); item != SymbolMap.end(); ++item) { 436 EXPECT_EQ(item->first == Tag, llvm::isa<ExpectedType>(*item->second)); 437 } 438 } 439 440 void VerifyUnknownDyncasts() { 441 for (auto item = SymbolMap.begin(); item != SymbolMap.end(); ++item) { 442 bool should_match = false; 443 if (item->first == PDB_SymType::None || item->first >= PDB_SymType::Max) 444 should_match = true; 445 446 EXPECT_EQ(should_match, llvm::isa<PDBSymbolUnknown>(*item->second)); 447 } 448 } 449 450 private: 451 std::unique_ptr<IPDBSession> Session; 452 453 void InsertItemWithTag(PDB_SymType Tag) { 454 auto RawSymbol = llvm::make_unique<MockRawSymbol>(Tag); 455 auto Symbol = PDBSymbol::create(*Session, std::move(RawSymbol)); 456 SymbolMap.insert(std::make_pair(Tag, std::move(Symbol))); 457 } 458 }; 459 460 TEST_F(PDBApiTest, Dyncast) { 461 462 // Most of the types have a one-to-one mapping between Tag and concrete type. 463 VerifyDyncast<PDBSymbolExe>(PDB_SymType::Exe); 464 VerifyDyncast<PDBSymbolCompiland>(PDB_SymType::Compiland); 465 VerifyDyncast<PDBSymbolCompilandDetails>(PDB_SymType::CompilandDetails); 466 VerifyDyncast<PDBSymbolCompilandEnv>(PDB_SymType::CompilandEnv); 467 VerifyDyncast<PDBSymbolFunc>(PDB_SymType::Function); 468 VerifyDyncast<PDBSymbolBlock>(PDB_SymType::Block); 469 VerifyDyncast<PDBSymbolData>(PDB_SymType::Data); 470 VerifyDyncast<PDBSymbolAnnotation>(PDB_SymType::Annotation); 471 VerifyDyncast<PDBSymbolLabel>(PDB_SymType::Label); 472 VerifyDyncast<PDBSymbolPublicSymbol>(PDB_SymType::PublicSymbol); 473 VerifyDyncast<PDBSymbolTypeUDT>(PDB_SymType::UDT); 474 VerifyDyncast<PDBSymbolTypeEnum>(PDB_SymType::Enum); 475 VerifyDyncast<PDBSymbolTypeFunctionSig>(PDB_SymType::FunctionSig); 476 VerifyDyncast<PDBSymbolTypePointer>(PDB_SymType::PointerType); 477 VerifyDyncast<PDBSymbolTypeArray>(PDB_SymType::ArrayType); 478 VerifyDyncast<PDBSymbolTypeBuiltin>(PDB_SymType::BuiltinType); 479 VerifyDyncast<PDBSymbolTypeTypedef>(PDB_SymType::Typedef); 480 VerifyDyncast<PDBSymbolTypeBaseClass>(PDB_SymType::BaseClass); 481 VerifyDyncast<PDBSymbolTypeFriend>(PDB_SymType::Friend); 482 VerifyDyncast<PDBSymbolTypeFunctionArg>(PDB_SymType::FunctionArg); 483 VerifyDyncast<PDBSymbolFuncDebugStart>(PDB_SymType::FuncDebugStart); 484 VerifyDyncast<PDBSymbolFuncDebugEnd>(PDB_SymType::FuncDebugEnd); 485 VerifyDyncast<PDBSymbolUsingNamespace>(PDB_SymType::UsingNamespace); 486 VerifyDyncast<PDBSymbolTypeVTableShape>(PDB_SymType::VTableShape); 487 VerifyDyncast<PDBSymbolTypeVTable>(PDB_SymType::VTable); 488 VerifyDyncast<PDBSymbolCustom>(PDB_SymType::Custom); 489 VerifyDyncast<PDBSymbolThunk>(PDB_SymType::Thunk); 490 VerifyDyncast<PDBSymbolTypeCustom>(PDB_SymType::CustomType); 491 VerifyDyncast<PDBSymbolTypeManaged>(PDB_SymType::ManagedType); 492 VerifyDyncast<PDBSymbolTypeDimension>(PDB_SymType::Dimension); 493 494 VerifyUnknownDyncasts(); 495 } 496 } // end anonymous namespace 497