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(uint32_t SymbolId) const71 std::unique_ptr<PDBSymbol> getSymbolById(uint32_t 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 };
163
164 class MockRawSymbol : public IPDBRawSymbol {
165 public:
MockRawSymbol(PDB_SymType SymType)166 MockRawSymbol(PDB_SymType SymType)
167 : Type(SymType) {}
168
dump(raw_ostream & OS,int Indent) const169 void dump(raw_ostream &OS, int Indent) const override {}
170
171 std::unique_ptr<IPDBEnumSymbols>
findChildren(PDB_SymType Type) const172 findChildren(PDB_SymType Type) const override {
173 return nullptr;
174 }
175 std::unique_ptr<IPDBEnumSymbols>
findChildren(PDB_SymType Type,StringRef Name,PDB_NameSearchFlags Flags) const176 findChildren(PDB_SymType Type, StringRef Name,
177 PDB_NameSearchFlags Flags) const override {
178 return nullptr;
179 }
180 std::unique_ptr<IPDBEnumSymbols>
findChildrenByAddr(PDB_SymType Type,StringRef Name,PDB_NameSearchFlags Flags,uint32_t Section,uint32_t Offset) const181 findChildrenByAddr(PDB_SymType Type, StringRef Name, PDB_NameSearchFlags Flags,
182 uint32_t Section, uint32_t Offset) const override {
183 return nullptr;
184 }
185 std::unique_ptr<IPDBEnumSymbols>
findChildrenByVA(PDB_SymType Type,StringRef Name,PDB_NameSearchFlags Flags,uint64_t VA) const186 findChildrenByVA(PDB_SymType Type, StringRef Name, PDB_NameSearchFlags Flags,
187 uint64_t VA) const override {
188 return nullptr;
189 }
190 std::unique_ptr<IPDBEnumSymbols>
findChildrenByRVA(PDB_SymType Type,StringRef Name,PDB_NameSearchFlags Flags,uint32_t RVA) const191 findChildrenByRVA(PDB_SymType Type, StringRef Name, PDB_NameSearchFlags Flags,
192 uint32_t RVA) const override {
193 return nullptr;
194 }
195 std::unique_ptr<IPDBEnumSymbols>
findInlineFramesByAddr(uint32_t Section,uint32_t Offset) const196 findInlineFramesByAddr(uint32_t Section, uint32_t Offset) const override {
197 return nullptr;
198 }
199 std::unique_ptr<IPDBEnumSymbols>
findInlineFramesByRVA(uint32_t RVA) const200 findInlineFramesByRVA(uint32_t RVA) const override {
201 return nullptr;
202 }
203 std::unique_ptr<IPDBEnumSymbols>
findInlineFramesByVA(uint64_t VA) const204 findInlineFramesByVA(uint64_t VA) const override {
205 return nullptr;
206 }
findInlineeLines() const207 std::unique_ptr<IPDBEnumLineNumbers> findInlineeLines() const override {
208 return nullptr;
209 }
210 std::unique_ptr<IPDBEnumLineNumbers>
findInlineeLinesByAddr(uint32_t Section,uint32_t Offset,uint32_t Length) const211 findInlineeLinesByAddr(uint32_t Section, uint32_t Offset,
212 uint32_t Length) const override {
213 return nullptr;
214 }
215 std::unique_ptr<IPDBEnumLineNumbers>
findInlineeLinesByRVA(uint32_t RVA,uint32_t Length) const216 findInlineeLinesByRVA(uint32_t RVA, uint32_t Length) const override {
217 return nullptr;
218 }
219 std::unique_ptr<IPDBEnumLineNumbers>
findInlineeLinesByVA(uint64_t VA,uint32_t Length) const220 findInlineeLinesByVA(uint64_t VA, uint32_t Length) const override {
221 return nullptr;
222 }
223
getDataBytes(llvm::SmallVector<uint8_t,32> & bytes) const224 void getDataBytes(llvm::SmallVector<uint8_t, 32> &bytes) const override {}
getFrontEndVersion(VersionInfo & Version) const225 void getFrontEndVersion(VersionInfo &Version) const override {}
getBackEndVersion(VersionInfo & Version) const226 void getBackEndVersion(VersionInfo &Version) const override {}
227
getSymTag() const228 PDB_SymType getSymTag() const override { return Type; }
229
getUndecoratedNameEx(PDB_UndnameFlags Flags) const230 std::string getUndecoratedNameEx(PDB_UndnameFlags Flags) const override {
231 return {};
232 }
233
getSrcLineOnTypeDefn() const234 std::unique_ptr<IPDBLineNumber> getSrcLineOnTypeDefn() const override {
235 return nullptr;
236 }
237
238 MOCK_SYMBOL_ACCESSOR(getAccess)
239 MOCK_SYMBOL_ACCESSOR(getAddressOffset)
240 MOCK_SYMBOL_ACCESSOR(getAddressSection)
241 MOCK_SYMBOL_ACCESSOR(getAge)
242 MOCK_SYMBOL_ACCESSOR(getArrayIndexTypeId)
243 MOCK_SYMBOL_ACCESSOR(getBaseDataOffset)
244 MOCK_SYMBOL_ACCESSOR(getBaseDataSlot)
245 MOCK_SYMBOL_ACCESSOR(getBaseSymbolId)
246 MOCK_SYMBOL_ACCESSOR(getBuiltinType)
247 MOCK_SYMBOL_ACCESSOR(getBitPosition)
248 MOCK_SYMBOL_ACCESSOR(getCallingConvention)
249 MOCK_SYMBOL_ACCESSOR(getClassParentId)
250 MOCK_SYMBOL_ACCESSOR(getCompilerName)
251 MOCK_SYMBOL_ACCESSOR(getCount)
252 MOCK_SYMBOL_ACCESSOR(getCountLiveRanges)
253 MOCK_SYMBOL_ACCESSOR(getLanguage)
254 MOCK_SYMBOL_ACCESSOR(getLexicalParentId)
255 MOCK_SYMBOL_ACCESSOR(getLibraryName)
256 MOCK_SYMBOL_ACCESSOR(getLiveRangeStartAddressOffset)
257 MOCK_SYMBOL_ACCESSOR(getLiveRangeStartAddressSection)
258 MOCK_SYMBOL_ACCESSOR(getLiveRangeStartRelativeVirtualAddress)
259 MOCK_SYMBOL_ACCESSOR(getLocalBasePointerRegisterId)
260 MOCK_SYMBOL_ACCESSOR(getLowerBoundId)
261 MOCK_SYMBOL_ACCESSOR(getMemorySpaceKind)
262 MOCK_SYMBOL_ACCESSOR(getName)
263 MOCK_SYMBOL_ACCESSOR(getNumberOfAcceleratorPointerTags)
264 MOCK_SYMBOL_ACCESSOR(getNumberOfColumns)
265 MOCK_SYMBOL_ACCESSOR(getNumberOfModifiers)
266 MOCK_SYMBOL_ACCESSOR(getNumberOfRegisterIndices)
267 MOCK_SYMBOL_ACCESSOR(getNumberOfRows)
268 MOCK_SYMBOL_ACCESSOR(getObjectFileName)
269 MOCK_SYMBOL_ACCESSOR(getOemId)
270 MOCK_SYMBOL_ACCESSOR(getOemSymbolId)
271 MOCK_SYMBOL_ACCESSOR(getOffsetInUdt)
272 MOCK_SYMBOL_ACCESSOR(getPlatform)
273 MOCK_SYMBOL_ACCESSOR(getRank)
274 MOCK_SYMBOL_ACCESSOR(getRegisterId)
275 MOCK_SYMBOL_ACCESSOR(getRegisterType)
276 MOCK_SYMBOL_ACCESSOR(getRelativeVirtualAddress)
277 MOCK_SYMBOL_ACCESSOR(getSamplerSlot)
278 MOCK_SYMBOL_ACCESSOR(getSignature)
279 MOCK_SYMBOL_ACCESSOR(getSizeInUdt)
280 MOCK_SYMBOL_ACCESSOR(getSlot)
281 MOCK_SYMBOL_ACCESSOR(getSourceFileName)
282 MOCK_SYMBOL_ACCESSOR(getStride)
283 MOCK_SYMBOL_ACCESSOR(getSubTypeId)
284 MOCK_SYMBOL_ACCESSOR(getSymbolsFileName)
285 MOCK_SYMBOL_ACCESSOR(getSymIndexId)
286 MOCK_SYMBOL_ACCESSOR(getTargetOffset)
287 MOCK_SYMBOL_ACCESSOR(getTargetRelativeVirtualAddress)
288 MOCK_SYMBOL_ACCESSOR(getTargetVirtualAddress)
289 MOCK_SYMBOL_ACCESSOR(getTargetSection)
290 MOCK_SYMBOL_ACCESSOR(getTextureSlot)
291 MOCK_SYMBOL_ACCESSOR(getTimeStamp)
292 MOCK_SYMBOL_ACCESSOR(getToken)
293 MOCK_SYMBOL_ACCESSOR(getTypeId)
294 MOCK_SYMBOL_ACCESSOR(getUavSlot)
295 MOCK_SYMBOL_ACCESSOR(getUndecoratedName)
296 MOCK_SYMBOL_ACCESSOR(getUnmodifiedTypeId)
297 MOCK_SYMBOL_ACCESSOR(getUpperBoundId)
298 MOCK_SYMBOL_ACCESSOR(getVirtualBaseDispIndex)
299 MOCK_SYMBOL_ACCESSOR(getVirtualBaseOffset)
300 MOCK_SYMBOL_ACCESSOR(getVirtualTableShapeId)
301 MOCK_SYMBOL_ACCESSOR(getDataKind)
302 MOCK_SYMBOL_ACCESSOR(getGuid)
303 MOCK_SYMBOL_ACCESSOR(getOffset)
304 MOCK_SYMBOL_ACCESSOR(getThisAdjust)
305 MOCK_SYMBOL_ACCESSOR(getVirtualBasePointerOffset)
306 MOCK_SYMBOL_ACCESSOR(getLocationType)
307 MOCK_SYMBOL_ACCESSOR(getMachineType)
308 MOCK_SYMBOL_ACCESSOR(getThunkOrdinal)
309 MOCK_SYMBOL_ACCESSOR(getLength)
310 MOCK_SYMBOL_ACCESSOR(getVirtualBaseTableType)
311 MOCK_SYMBOL_ACCESSOR(getLiveRangeLength)
312 MOCK_SYMBOL_ACCESSOR(getVirtualAddress)
313 MOCK_SYMBOL_ACCESSOR(getUdtKind)
314 MOCK_SYMBOL_ACCESSOR(hasConstructor)
315 MOCK_SYMBOL_ACCESSOR(hasCustomCallingConvention)
316 MOCK_SYMBOL_ACCESSOR(hasFarReturn)
317 MOCK_SYMBOL_ACCESSOR(isCode)
318 MOCK_SYMBOL_ACCESSOR(isCompilerGenerated)
319 MOCK_SYMBOL_ACCESSOR(isConstType)
320 MOCK_SYMBOL_ACCESSOR(isEditAndContinueEnabled)
321 MOCK_SYMBOL_ACCESSOR(isFunction)
322 MOCK_SYMBOL_ACCESSOR(getAddressTaken)
323 MOCK_SYMBOL_ACCESSOR(getNoStackOrdering)
324 MOCK_SYMBOL_ACCESSOR(hasAlloca)
325 MOCK_SYMBOL_ACCESSOR(hasAssignmentOperator)
326 MOCK_SYMBOL_ACCESSOR(hasCTypes)
327 MOCK_SYMBOL_ACCESSOR(hasCastOperator)
328 MOCK_SYMBOL_ACCESSOR(hasDebugInfo)
329 MOCK_SYMBOL_ACCESSOR(hasEH)
330 MOCK_SYMBOL_ACCESSOR(hasEHa)
331 MOCK_SYMBOL_ACCESSOR(hasFramePointer)
332 MOCK_SYMBOL_ACCESSOR(hasInlAsm)
333 MOCK_SYMBOL_ACCESSOR(hasInlineAttribute)
334 MOCK_SYMBOL_ACCESSOR(hasInterruptReturn)
335 MOCK_SYMBOL_ACCESSOR(hasLongJump)
336 MOCK_SYMBOL_ACCESSOR(hasManagedCode)
337 MOCK_SYMBOL_ACCESSOR(hasNestedTypes)
338 MOCK_SYMBOL_ACCESSOR(hasNoInlineAttribute)
339 MOCK_SYMBOL_ACCESSOR(hasNoReturnAttribute)
340 MOCK_SYMBOL_ACCESSOR(hasOptimizedCodeDebugInfo)
341 MOCK_SYMBOL_ACCESSOR(hasOverloadedOperator)
342 MOCK_SYMBOL_ACCESSOR(hasSEH)
343 MOCK_SYMBOL_ACCESSOR(hasSecurityChecks)
344 MOCK_SYMBOL_ACCESSOR(hasSetJump)
345 MOCK_SYMBOL_ACCESSOR(hasStrictGSCheck)
346 MOCK_SYMBOL_ACCESSOR(isAcceleratorGroupSharedLocal)
347 MOCK_SYMBOL_ACCESSOR(isAcceleratorPointerTagLiveRange)
348 MOCK_SYMBOL_ACCESSOR(isAcceleratorStubFunction)
349 MOCK_SYMBOL_ACCESSOR(isAggregated)
350 MOCK_SYMBOL_ACCESSOR(isIntroVirtualFunction)
351 MOCK_SYMBOL_ACCESSOR(isCVTCIL)
352 MOCK_SYMBOL_ACCESSOR(isConstructorVirtualBase)
353 MOCK_SYMBOL_ACCESSOR(isCxxReturnUdt)
354 MOCK_SYMBOL_ACCESSOR(isDataAligned)
355 MOCK_SYMBOL_ACCESSOR(isHLSLData)
356 MOCK_SYMBOL_ACCESSOR(isHotpatchable)
357 MOCK_SYMBOL_ACCESSOR(isIndirectVirtualBaseClass)
358 MOCK_SYMBOL_ACCESSOR(isInterfaceUdt)
359 MOCK_SYMBOL_ACCESSOR(isIntrinsic)
360 MOCK_SYMBOL_ACCESSOR(isLTCG)
361 MOCK_SYMBOL_ACCESSOR(isLocationControlFlowDependent)
362 MOCK_SYMBOL_ACCESSOR(isMSILNetmodule)
363 MOCK_SYMBOL_ACCESSOR(isMatrixRowMajor)
364 MOCK_SYMBOL_ACCESSOR(isManagedCode)
365 MOCK_SYMBOL_ACCESSOR(isMSILCode)
366 MOCK_SYMBOL_ACCESSOR(isMultipleInheritance)
367 MOCK_SYMBOL_ACCESSOR(isNaked)
368 MOCK_SYMBOL_ACCESSOR(isNested)
369 MOCK_SYMBOL_ACCESSOR(isOptimizedAway)
370 MOCK_SYMBOL_ACCESSOR(isPacked)
371 MOCK_SYMBOL_ACCESSOR(isPointerBasedOnSymbolValue)
372 MOCK_SYMBOL_ACCESSOR(isPointerToDataMember)
373 MOCK_SYMBOL_ACCESSOR(isPointerToMemberFunction)
374 MOCK_SYMBOL_ACCESSOR(isPureVirtual)
375 MOCK_SYMBOL_ACCESSOR(isRValueReference)
376 MOCK_SYMBOL_ACCESSOR(isRefUdt)
377 MOCK_SYMBOL_ACCESSOR(isReference)
378 MOCK_SYMBOL_ACCESSOR(isRestrictedType)
379 MOCK_SYMBOL_ACCESSOR(isReturnValue)
380 MOCK_SYMBOL_ACCESSOR(isSafeBuffers)
381 MOCK_SYMBOL_ACCESSOR(isScoped)
382 MOCK_SYMBOL_ACCESSOR(isSdl)
383 MOCK_SYMBOL_ACCESSOR(isSingleInheritance)
384 MOCK_SYMBOL_ACCESSOR(isSplitted)
385 MOCK_SYMBOL_ACCESSOR(isStatic)
386 MOCK_SYMBOL_ACCESSOR(hasPrivateSymbols)
387 MOCK_SYMBOL_ACCESSOR(isUnalignedType)
388 MOCK_SYMBOL_ACCESSOR(isUnreached)
389 MOCK_SYMBOL_ACCESSOR(isValueUdt)
390 MOCK_SYMBOL_ACCESSOR(isVirtual)
391 MOCK_SYMBOL_ACCESSOR(isVirtualBaseClass)
392 MOCK_SYMBOL_ACCESSOR(isVirtualInheritance)
393 MOCK_SYMBOL_ACCESSOR(isVolatileType)
394 MOCK_SYMBOL_ACCESSOR(getValue)
395 MOCK_SYMBOL_ACCESSOR(wasInlined)
396 MOCK_SYMBOL_ACCESSOR(getUnused)
397
398 private:
399 PDB_SymType Type;
400 };
401
402 class PDBApiTest : public testing::Test {
403 public:
404 std::unordered_map<PDB_SymType, std::unique_ptr<PDBSymbol>> SymbolMap;
405
SetUp()406 void SetUp() override {
407 Session.reset(new MockSession());
408
409 InsertItemWithTag(PDB_SymType::None);
410 InsertItemWithTag(PDB_SymType::Exe);
411 InsertItemWithTag(PDB_SymType::Compiland);
412 InsertItemWithTag(PDB_SymType::CompilandDetails);
413 InsertItemWithTag(PDB_SymType::CompilandEnv);
414 InsertItemWithTag(PDB_SymType::Function);
415 InsertItemWithTag(PDB_SymType::Block);
416 InsertItemWithTag(PDB_SymType::Data);
417 InsertItemWithTag(PDB_SymType::Annotation);
418 InsertItemWithTag(PDB_SymType::Label);
419 InsertItemWithTag(PDB_SymType::PublicSymbol);
420 InsertItemWithTag(PDB_SymType::UDT);
421 InsertItemWithTag(PDB_SymType::Enum);
422 InsertItemWithTag(PDB_SymType::FunctionSig);
423 InsertItemWithTag(PDB_SymType::PointerType);
424 InsertItemWithTag(PDB_SymType::ArrayType);
425 InsertItemWithTag(PDB_SymType::BuiltinType);
426 InsertItemWithTag(PDB_SymType::Typedef);
427 InsertItemWithTag(PDB_SymType::BaseClass);
428 InsertItemWithTag(PDB_SymType::Friend);
429 InsertItemWithTag(PDB_SymType::FunctionArg);
430 InsertItemWithTag(PDB_SymType::FuncDebugStart);
431 InsertItemWithTag(PDB_SymType::FuncDebugEnd);
432 InsertItemWithTag(PDB_SymType::UsingNamespace);
433 InsertItemWithTag(PDB_SymType::VTableShape);
434 InsertItemWithTag(PDB_SymType::VTable);
435 InsertItemWithTag(PDB_SymType::Custom);
436 InsertItemWithTag(PDB_SymType::Thunk);
437 InsertItemWithTag(PDB_SymType::CustomType);
438 InsertItemWithTag(PDB_SymType::ManagedType);
439 InsertItemWithTag(PDB_SymType::Dimension);
440 InsertItemWithTag(PDB_SymType::Max);
441 }
442
VerifyDyncast(PDB_SymType Tag)443 template <class ExpectedType> void VerifyDyncast(PDB_SymType Tag) {
444 for (auto item = SymbolMap.begin(); item != SymbolMap.end(); ++item) {
445 EXPECT_EQ(item->first == Tag, llvm::isa<ExpectedType>(*item->second));
446 }
447 }
448
VerifyUnknownDyncasts()449 void VerifyUnknownDyncasts() {
450 for (auto item = SymbolMap.begin(); item != SymbolMap.end(); ++item) {
451 bool should_match = false;
452 if (item->first == PDB_SymType::None || item->first >= PDB_SymType::Max)
453 should_match = true;
454
455 EXPECT_EQ(should_match, llvm::isa<PDBSymbolUnknown>(*item->second));
456 }
457 }
458
459 private:
460 std::unique_ptr<IPDBSession> Session;
461
InsertItemWithTag(PDB_SymType Tag)462 void InsertItemWithTag(PDB_SymType Tag) {
463 auto RawSymbol = llvm::make_unique<MockRawSymbol>(Tag);
464 auto Symbol = PDBSymbol::create(*Session, std::move(RawSymbol));
465 SymbolMap.insert(std::make_pair(Tag, std::move(Symbol)));
466 }
467 };
468
TEST_F(PDBApiTest,Dyncast)469 TEST_F(PDBApiTest, Dyncast) {
470
471 // Most of the types have a one-to-one mapping between Tag and concrete type.
472 VerifyDyncast<PDBSymbolExe>(PDB_SymType::Exe);
473 VerifyDyncast<PDBSymbolCompiland>(PDB_SymType::Compiland);
474 VerifyDyncast<PDBSymbolCompilandDetails>(PDB_SymType::CompilandDetails);
475 VerifyDyncast<PDBSymbolCompilandEnv>(PDB_SymType::CompilandEnv);
476 VerifyDyncast<PDBSymbolFunc>(PDB_SymType::Function);
477 VerifyDyncast<PDBSymbolBlock>(PDB_SymType::Block);
478 VerifyDyncast<PDBSymbolData>(PDB_SymType::Data);
479 VerifyDyncast<PDBSymbolAnnotation>(PDB_SymType::Annotation);
480 VerifyDyncast<PDBSymbolLabel>(PDB_SymType::Label);
481 VerifyDyncast<PDBSymbolPublicSymbol>(PDB_SymType::PublicSymbol);
482 VerifyDyncast<PDBSymbolTypeUDT>(PDB_SymType::UDT);
483 VerifyDyncast<PDBSymbolTypeEnum>(PDB_SymType::Enum);
484 VerifyDyncast<PDBSymbolTypeFunctionSig>(PDB_SymType::FunctionSig);
485 VerifyDyncast<PDBSymbolTypePointer>(PDB_SymType::PointerType);
486 VerifyDyncast<PDBSymbolTypeArray>(PDB_SymType::ArrayType);
487 VerifyDyncast<PDBSymbolTypeBuiltin>(PDB_SymType::BuiltinType);
488 VerifyDyncast<PDBSymbolTypeTypedef>(PDB_SymType::Typedef);
489 VerifyDyncast<PDBSymbolTypeBaseClass>(PDB_SymType::BaseClass);
490 VerifyDyncast<PDBSymbolTypeFriend>(PDB_SymType::Friend);
491 VerifyDyncast<PDBSymbolTypeFunctionArg>(PDB_SymType::FunctionArg);
492 VerifyDyncast<PDBSymbolFuncDebugStart>(PDB_SymType::FuncDebugStart);
493 VerifyDyncast<PDBSymbolFuncDebugEnd>(PDB_SymType::FuncDebugEnd);
494 VerifyDyncast<PDBSymbolUsingNamespace>(PDB_SymType::UsingNamespace);
495 VerifyDyncast<PDBSymbolTypeVTableShape>(PDB_SymType::VTableShape);
496 VerifyDyncast<PDBSymbolTypeVTable>(PDB_SymType::VTable);
497 VerifyDyncast<PDBSymbolCustom>(PDB_SymType::Custom);
498 VerifyDyncast<PDBSymbolThunk>(PDB_SymType::Thunk);
499 VerifyDyncast<PDBSymbolTypeCustom>(PDB_SymType::CustomType);
500 VerifyDyncast<PDBSymbolTypeManaged>(PDB_SymType::ManagedType);
501 VerifyDyncast<PDBSymbolTypeDimension>(PDB_SymType::Dimension);
502
503 VerifyUnknownDyncasts();
504 }
505 } // end anonymous namespace
506