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