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