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