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