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

source code of llvm/unittests/DebugInfo/PDB/PDBApiTest.cpp