1 //===- llvm/unittest/DebugInfo/PDB/PDBApiTest.cpp -------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include <unordered_map>
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"
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"
57 using namespace llvm::pdb
;
61 #define MOCK_SYMBOL_ACCESSOR(Func) \
62 decltype(std::declval<IPDBRawSymbol>().Func()) Func() const override { \
63 typedef decltype(IPDBRawSymbol::Func()) ReturnType; \
64 return ReturnType(); \
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(SymIndexId SymbolId
) const override
{
74 std::unique_ptr
<IPDBSourceFile
>
75 getSourceFileById(uint32_t SymbolId
) const override
{
78 bool addressForVA(uint64_t VA
, uint32_t &Section
,
79 uint32_t &Offset
) const override
{
82 bool addressForRVA(uint32_t RVA
, uint32_t &Section
,
83 uint32_t &Offset
) const override
{
86 std::unique_ptr
<PDBSymbol
>
87 findSymbolByAddress(uint64_t Address
, PDB_SymType Type
) const override
{
90 std::unique_ptr
<PDBSymbol
> findSymbolByRVA(uint32_t RVA
,
91 PDB_SymType Type
) const override
{
94 std::unique_ptr
<PDBSymbol
>
95 findSymbolBySectOffset(uint32_t Sect
, uint32_t Offset
,
96 PDB_SymType Type
) const override
{
99 std::unique_ptr
<IPDBEnumLineNumbers
>
100 findLineNumbers(const PDBSymbolCompiland
&Compiland
,
101 const IPDBSourceFile
&File
) const override
{
104 std::unique_ptr
<IPDBEnumLineNumbers
>
105 findLineNumbersByAddress(uint64_t Address
, uint32_t Length
) const override
{
108 std::unique_ptr
<IPDBEnumLineNumbers
>
109 findLineNumbersByRVA(uint32_t RVA
, uint32_t Length
) const override
{
112 std::unique_ptr
<IPDBEnumLineNumbers
>
113 findLineNumbersBySectOffset(uint32_t Section
, uint32_t Offset
,
114 uint32_t Length
) const override
{
117 std::unique_ptr
<IPDBEnumSourceFiles
>
118 findSourceFiles(const PDBSymbolCompiland
*Compiland
, llvm::StringRef Pattern
,
119 PDB_NameSearchFlags Flags
) const override
{
122 std::unique_ptr
<IPDBSourceFile
>
123 findOneSourceFile(const PDBSymbolCompiland
*Compiland
,
124 llvm::StringRef Pattern
,
125 PDB_NameSearchFlags Flags
) const override
{
128 std::unique_ptr
<IPDBEnumChildren
<PDBSymbolCompiland
>>
129 findCompilandsForSourceFile(llvm::StringRef Pattern
,
130 PDB_NameSearchFlags Flags
) const override
{
133 std::unique_ptr
<PDBSymbolCompiland
>
134 findOneCompilandForSourceFile(llvm::StringRef Pattern
,
135 PDB_NameSearchFlags Flags
) const override
{
139 std::unique_ptr
<IPDBEnumSourceFiles
> getAllSourceFiles() const override
{
142 std::unique_ptr
<IPDBEnumSourceFiles
> getSourceFilesForCompiland(
143 const PDBSymbolCompiland
&Compiland
) const override
{
147 std::unique_ptr
<IPDBEnumDataStreams
> getDebugStreams() const override
{
151 std::unique_ptr
<IPDBEnumTables
> getEnumTables() const override
{
155 std::unique_ptr
<IPDBEnumInjectedSources
> getInjectedSources() const override
{
159 std::unique_ptr
<IPDBEnumSectionContribs
> getSectionContribs() const override
{
164 class MockRawSymbol
: public IPDBRawSymbol
{
166 MockRawSymbol(PDB_SymType SymType
)
169 void dump(raw_ostream
&OS
, int Indent
, PdbSymbolIdField ShowIdFields
,
170 PdbSymbolIdField RecurseIdFields
) const override
{}
172 std::unique_ptr
<IPDBEnumSymbols
>
173 findChildren(PDB_SymType Type
) const override
{
176 std::unique_ptr
<IPDBEnumSymbols
>
177 findChildren(PDB_SymType Type
, StringRef Name
,
178 PDB_NameSearchFlags Flags
) const override
{
181 std::unique_ptr
<IPDBEnumSymbols
>
182 findChildrenByAddr(PDB_SymType Type
, StringRef Name
, PDB_NameSearchFlags Flags
,
183 uint32_t Section
, uint32_t Offset
) const override
{
186 std::unique_ptr
<IPDBEnumSymbols
>
187 findChildrenByVA(PDB_SymType Type
, StringRef Name
, PDB_NameSearchFlags Flags
,
188 uint64_t VA
) const override
{
191 std::unique_ptr
<IPDBEnumSymbols
>
192 findChildrenByRVA(PDB_SymType Type
, StringRef Name
, PDB_NameSearchFlags Flags
,
193 uint32_t RVA
) const override
{
196 std::unique_ptr
<IPDBEnumSymbols
>
197 findInlineFramesByAddr(uint32_t Section
, uint32_t Offset
) const override
{
200 std::unique_ptr
<IPDBEnumSymbols
>
201 findInlineFramesByRVA(uint32_t RVA
) const override
{
204 std::unique_ptr
<IPDBEnumSymbols
>
205 findInlineFramesByVA(uint64_t VA
) const override
{
208 std::unique_ptr
<IPDBEnumLineNumbers
> findInlineeLines() const override
{
211 std::unique_ptr
<IPDBEnumLineNumbers
>
212 findInlineeLinesByAddr(uint32_t Section
, uint32_t Offset
,
213 uint32_t Length
) const override
{
216 std::unique_ptr
<IPDBEnumLineNumbers
>
217 findInlineeLinesByRVA(uint32_t RVA
, uint32_t Length
) const override
{
220 std::unique_ptr
<IPDBEnumLineNumbers
>
221 findInlineeLinesByVA(uint64_t VA
, uint32_t Length
) const override
{
225 void getDataBytes(llvm::SmallVector
<uint8_t, 32> &bytes
) const override
{}
226 void getFrontEndVersion(VersionInfo
&Version
) const override
{}
227 void getBackEndVersion(VersionInfo
&Version
) const override
{}
229 PDB_SymType
getSymTag() const override
{ return Type
; }
231 std::string
getUndecoratedNameEx(PDB_UndnameFlags Flags
) const override
{
235 std::unique_ptr
<IPDBLineNumber
> getSrcLineOnTypeDefn() const override
{
239 MOCK_SYMBOL_ACCESSOR(getAccess
)
240 MOCK_SYMBOL_ACCESSOR(getAddressOffset
)
241 MOCK_SYMBOL_ACCESSOR(getAddressSection
)
242 MOCK_SYMBOL_ACCESSOR(getAge
)
243 MOCK_SYMBOL_ACCESSOR(getArrayIndexTypeId
)
244 MOCK_SYMBOL_ACCESSOR(getBaseDataOffset
)
245 MOCK_SYMBOL_ACCESSOR(getBaseDataSlot
)
246 MOCK_SYMBOL_ACCESSOR(getBaseSymbolId
)
247 MOCK_SYMBOL_ACCESSOR(getBuiltinType
)
248 MOCK_SYMBOL_ACCESSOR(getBitPosition
)
249 MOCK_SYMBOL_ACCESSOR(getCallingConvention
)
250 MOCK_SYMBOL_ACCESSOR(getClassParentId
)
251 MOCK_SYMBOL_ACCESSOR(getCompilerName
)
252 MOCK_SYMBOL_ACCESSOR(getCount
)
253 MOCK_SYMBOL_ACCESSOR(getCountLiveRanges
)
254 MOCK_SYMBOL_ACCESSOR(getLanguage
)
255 MOCK_SYMBOL_ACCESSOR(getLexicalParentId
)
256 MOCK_SYMBOL_ACCESSOR(getLibraryName
)
257 MOCK_SYMBOL_ACCESSOR(getLiveRangeStartAddressOffset
)
258 MOCK_SYMBOL_ACCESSOR(getLiveRangeStartAddressSection
)
259 MOCK_SYMBOL_ACCESSOR(getLiveRangeStartRelativeVirtualAddress
)
260 MOCK_SYMBOL_ACCESSOR(getLocalBasePointerRegisterId
)
261 MOCK_SYMBOL_ACCESSOR(getLowerBoundId
)
262 MOCK_SYMBOL_ACCESSOR(getMemorySpaceKind
)
263 MOCK_SYMBOL_ACCESSOR(getName
)
264 MOCK_SYMBOL_ACCESSOR(getNumberOfAcceleratorPointerTags
)
265 MOCK_SYMBOL_ACCESSOR(getNumberOfColumns
)
266 MOCK_SYMBOL_ACCESSOR(getNumberOfModifiers
)
267 MOCK_SYMBOL_ACCESSOR(getNumberOfRegisterIndices
)
268 MOCK_SYMBOL_ACCESSOR(getNumberOfRows
)
269 MOCK_SYMBOL_ACCESSOR(getObjectFileName
)
270 MOCK_SYMBOL_ACCESSOR(getOemId
)
271 MOCK_SYMBOL_ACCESSOR(getOemSymbolId
)
272 MOCK_SYMBOL_ACCESSOR(getOffsetInUdt
)
273 MOCK_SYMBOL_ACCESSOR(getPlatform
)
274 MOCK_SYMBOL_ACCESSOR(getRank
)
275 MOCK_SYMBOL_ACCESSOR(getRegisterId
)
276 MOCK_SYMBOL_ACCESSOR(getRegisterType
)
277 MOCK_SYMBOL_ACCESSOR(getRelativeVirtualAddress
)
278 MOCK_SYMBOL_ACCESSOR(getSamplerSlot
)
279 MOCK_SYMBOL_ACCESSOR(getSignature
)
280 MOCK_SYMBOL_ACCESSOR(getSizeInUdt
)
281 MOCK_SYMBOL_ACCESSOR(getSlot
)
282 MOCK_SYMBOL_ACCESSOR(getSourceFileName
)
283 MOCK_SYMBOL_ACCESSOR(getStride
)
284 MOCK_SYMBOL_ACCESSOR(getSubTypeId
)
285 MOCK_SYMBOL_ACCESSOR(getSymbolsFileName
)
286 MOCK_SYMBOL_ACCESSOR(getSymIndexId
)
287 MOCK_SYMBOL_ACCESSOR(getTargetOffset
)
288 MOCK_SYMBOL_ACCESSOR(getTargetRelativeVirtualAddress
)
289 MOCK_SYMBOL_ACCESSOR(getTargetVirtualAddress
)
290 MOCK_SYMBOL_ACCESSOR(getTargetSection
)
291 MOCK_SYMBOL_ACCESSOR(getTextureSlot
)
292 MOCK_SYMBOL_ACCESSOR(getTimeStamp
)
293 MOCK_SYMBOL_ACCESSOR(getToken
)
294 MOCK_SYMBOL_ACCESSOR(getTypeId
)
295 MOCK_SYMBOL_ACCESSOR(getUavSlot
)
296 MOCK_SYMBOL_ACCESSOR(getUndecoratedName
)
297 MOCK_SYMBOL_ACCESSOR(getUnmodifiedTypeId
)
298 MOCK_SYMBOL_ACCESSOR(getUpperBoundId
)
299 MOCK_SYMBOL_ACCESSOR(getVirtualBaseDispIndex
)
300 MOCK_SYMBOL_ACCESSOR(getVirtualBaseOffset
)
301 MOCK_SYMBOL_ACCESSOR(getVirtualTableShapeId
)
302 MOCK_SYMBOL_ACCESSOR(getDataKind
)
303 MOCK_SYMBOL_ACCESSOR(getGuid
)
304 MOCK_SYMBOL_ACCESSOR(getOffset
)
305 MOCK_SYMBOL_ACCESSOR(getThisAdjust
)
306 MOCK_SYMBOL_ACCESSOR(getVirtualBasePointerOffset
)
307 MOCK_SYMBOL_ACCESSOR(getLocationType
)
308 MOCK_SYMBOL_ACCESSOR(getMachineType
)
309 MOCK_SYMBOL_ACCESSOR(getThunkOrdinal
)
310 MOCK_SYMBOL_ACCESSOR(getLength
)
311 MOCK_SYMBOL_ACCESSOR(getVirtualBaseTableType
)
312 MOCK_SYMBOL_ACCESSOR(getLiveRangeLength
)
313 MOCK_SYMBOL_ACCESSOR(getVirtualAddress
)
314 MOCK_SYMBOL_ACCESSOR(getUdtKind
)
315 MOCK_SYMBOL_ACCESSOR(hasConstructor
)
316 MOCK_SYMBOL_ACCESSOR(hasCustomCallingConvention
)
317 MOCK_SYMBOL_ACCESSOR(hasFarReturn
)
318 MOCK_SYMBOL_ACCESSOR(isCode
)
319 MOCK_SYMBOL_ACCESSOR(isCompilerGenerated
)
320 MOCK_SYMBOL_ACCESSOR(isConstType
)
321 MOCK_SYMBOL_ACCESSOR(isEditAndContinueEnabled
)
322 MOCK_SYMBOL_ACCESSOR(isFunction
)
323 MOCK_SYMBOL_ACCESSOR(getAddressTaken
)
324 MOCK_SYMBOL_ACCESSOR(getNoStackOrdering
)
325 MOCK_SYMBOL_ACCESSOR(hasAlloca
)
326 MOCK_SYMBOL_ACCESSOR(hasAssignmentOperator
)
327 MOCK_SYMBOL_ACCESSOR(hasCTypes
)
328 MOCK_SYMBOL_ACCESSOR(hasCastOperator
)
329 MOCK_SYMBOL_ACCESSOR(hasDebugInfo
)
330 MOCK_SYMBOL_ACCESSOR(hasEH
)
331 MOCK_SYMBOL_ACCESSOR(hasEHa
)
332 MOCK_SYMBOL_ACCESSOR(hasFramePointer
)
333 MOCK_SYMBOL_ACCESSOR(hasInlAsm
)
334 MOCK_SYMBOL_ACCESSOR(hasInlineAttribute
)
335 MOCK_SYMBOL_ACCESSOR(hasInterruptReturn
)
336 MOCK_SYMBOL_ACCESSOR(hasLongJump
)
337 MOCK_SYMBOL_ACCESSOR(hasManagedCode
)
338 MOCK_SYMBOL_ACCESSOR(hasNestedTypes
)
339 MOCK_SYMBOL_ACCESSOR(hasNoInlineAttribute
)
340 MOCK_SYMBOL_ACCESSOR(hasNoReturnAttribute
)
341 MOCK_SYMBOL_ACCESSOR(hasOptimizedCodeDebugInfo
)
342 MOCK_SYMBOL_ACCESSOR(hasOverloadedOperator
)
343 MOCK_SYMBOL_ACCESSOR(hasSEH
)
344 MOCK_SYMBOL_ACCESSOR(hasSecurityChecks
)
345 MOCK_SYMBOL_ACCESSOR(hasSetJump
)
346 MOCK_SYMBOL_ACCESSOR(hasStrictGSCheck
)
347 MOCK_SYMBOL_ACCESSOR(isAcceleratorGroupSharedLocal
)
348 MOCK_SYMBOL_ACCESSOR(isAcceleratorPointerTagLiveRange
)
349 MOCK_SYMBOL_ACCESSOR(isAcceleratorStubFunction
)
350 MOCK_SYMBOL_ACCESSOR(isAggregated
)
351 MOCK_SYMBOL_ACCESSOR(isIntroVirtualFunction
)
352 MOCK_SYMBOL_ACCESSOR(isCVTCIL
)
353 MOCK_SYMBOL_ACCESSOR(isConstructorVirtualBase
)
354 MOCK_SYMBOL_ACCESSOR(isCxxReturnUdt
)
355 MOCK_SYMBOL_ACCESSOR(isDataAligned
)
356 MOCK_SYMBOL_ACCESSOR(isHLSLData
)
357 MOCK_SYMBOL_ACCESSOR(isHotpatchable
)
358 MOCK_SYMBOL_ACCESSOR(isIndirectVirtualBaseClass
)
359 MOCK_SYMBOL_ACCESSOR(isInterfaceUdt
)
360 MOCK_SYMBOL_ACCESSOR(isIntrinsic
)
361 MOCK_SYMBOL_ACCESSOR(isLTCG
)
362 MOCK_SYMBOL_ACCESSOR(isLocationControlFlowDependent
)
363 MOCK_SYMBOL_ACCESSOR(isMSILNetmodule
)
364 MOCK_SYMBOL_ACCESSOR(isMatrixRowMajor
)
365 MOCK_SYMBOL_ACCESSOR(isManagedCode
)
366 MOCK_SYMBOL_ACCESSOR(isMSILCode
)
367 MOCK_SYMBOL_ACCESSOR(isMultipleInheritance
)
368 MOCK_SYMBOL_ACCESSOR(isNaked
)
369 MOCK_SYMBOL_ACCESSOR(isNested
)
370 MOCK_SYMBOL_ACCESSOR(isOptimizedAway
)
371 MOCK_SYMBOL_ACCESSOR(isPacked
)
372 MOCK_SYMBOL_ACCESSOR(isPointerBasedOnSymbolValue
)
373 MOCK_SYMBOL_ACCESSOR(isPointerToDataMember
)
374 MOCK_SYMBOL_ACCESSOR(isPointerToMemberFunction
)
375 MOCK_SYMBOL_ACCESSOR(isPureVirtual
)
376 MOCK_SYMBOL_ACCESSOR(isRValueReference
)
377 MOCK_SYMBOL_ACCESSOR(isRefUdt
)
378 MOCK_SYMBOL_ACCESSOR(isReference
)
379 MOCK_SYMBOL_ACCESSOR(isRestrictedType
)
380 MOCK_SYMBOL_ACCESSOR(isReturnValue
)
381 MOCK_SYMBOL_ACCESSOR(isSafeBuffers
)
382 MOCK_SYMBOL_ACCESSOR(isScoped
)
383 MOCK_SYMBOL_ACCESSOR(isSdl
)
384 MOCK_SYMBOL_ACCESSOR(isSingleInheritance
)
385 MOCK_SYMBOL_ACCESSOR(isSplitted
)
386 MOCK_SYMBOL_ACCESSOR(isStatic
)
387 MOCK_SYMBOL_ACCESSOR(hasPrivateSymbols
)
388 MOCK_SYMBOL_ACCESSOR(isUnalignedType
)
389 MOCK_SYMBOL_ACCESSOR(isUnreached
)
390 MOCK_SYMBOL_ACCESSOR(isValueUdt
)
391 MOCK_SYMBOL_ACCESSOR(isVirtual
)
392 MOCK_SYMBOL_ACCESSOR(isVirtualBaseClass
)
393 MOCK_SYMBOL_ACCESSOR(isVirtualInheritance
)
394 MOCK_SYMBOL_ACCESSOR(isVolatileType
)
395 MOCK_SYMBOL_ACCESSOR(getValue
)
396 MOCK_SYMBOL_ACCESSOR(wasInlined
)
397 MOCK_SYMBOL_ACCESSOR(getUnused
)
403 class PDBApiTest
: public testing::Test
{
405 std::unordered_map
<PDB_SymType
, std::unique_ptr
<PDBSymbol
>> SymbolMap
;
407 void SetUp() override
{
408 Session
.reset(new MockSession());
410 InsertItemWithTag(PDB_SymType::None
);
411 InsertItemWithTag(PDB_SymType::Exe
);
412 InsertItemWithTag(PDB_SymType::Compiland
);
413 InsertItemWithTag(PDB_SymType::CompilandDetails
);
414 InsertItemWithTag(PDB_SymType::CompilandEnv
);
415 InsertItemWithTag(PDB_SymType::Function
);
416 InsertItemWithTag(PDB_SymType::Block
);
417 InsertItemWithTag(PDB_SymType::Data
);
418 InsertItemWithTag(PDB_SymType::Annotation
);
419 InsertItemWithTag(PDB_SymType::Label
);
420 InsertItemWithTag(PDB_SymType::PublicSymbol
);
421 InsertItemWithTag(PDB_SymType::UDT
);
422 InsertItemWithTag(PDB_SymType::Enum
);
423 InsertItemWithTag(PDB_SymType::FunctionSig
);
424 InsertItemWithTag(PDB_SymType::PointerType
);
425 InsertItemWithTag(PDB_SymType::ArrayType
);
426 InsertItemWithTag(PDB_SymType::BuiltinType
);
427 InsertItemWithTag(PDB_SymType::Typedef
);
428 InsertItemWithTag(PDB_SymType::BaseClass
);
429 InsertItemWithTag(PDB_SymType::Friend
);
430 InsertItemWithTag(PDB_SymType::FunctionArg
);
431 InsertItemWithTag(PDB_SymType::FuncDebugStart
);
432 InsertItemWithTag(PDB_SymType::FuncDebugEnd
);
433 InsertItemWithTag(PDB_SymType::UsingNamespace
);
434 InsertItemWithTag(PDB_SymType::VTableShape
);
435 InsertItemWithTag(PDB_SymType::VTable
);
436 InsertItemWithTag(PDB_SymType::Custom
);
437 InsertItemWithTag(PDB_SymType::Thunk
);
438 InsertItemWithTag(PDB_SymType::CustomType
);
439 InsertItemWithTag(PDB_SymType::ManagedType
);
440 InsertItemWithTag(PDB_SymType::Dimension
);
441 InsertItemWithTag(PDB_SymType::Max
);
444 template <class ExpectedType
> void VerifyDyncast(PDB_SymType Tag
) {
445 for (auto item
= SymbolMap
.begin(); item
!= SymbolMap
.end(); ++item
) {
446 EXPECT_EQ(item
->first
== Tag
, llvm::isa
<ExpectedType
>(*item
->second
));
450 void VerifyUnknownDyncasts() {
451 for (auto item
= SymbolMap
.begin(); item
!= SymbolMap
.end(); ++item
) {
452 bool should_match
= false;
453 if (item
->first
== PDB_SymType::None
|| item
->first
>= PDB_SymType::Max
)
456 EXPECT_EQ(should_match
, llvm::isa
<PDBSymbolUnknown
>(*item
->second
));
461 std::unique_ptr
<IPDBSession
> Session
;
463 void InsertItemWithTag(PDB_SymType Tag
) {
464 auto RawSymbol
= llvm::make_unique
<MockRawSymbol
>(Tag
);
465 auto Symbol
= PDBSymbol::create(*Session
, std::move(RawSymbol
));
466 SymbolMap
.insert(std::make_pair(Tag
, std::move(Symbol
)));
470 TEST_F(PDBApiTest
, Dyncast
) {
472 // Most of the types have a one-to-one mapping between Tag and concrete type.
473 VerifyDyncast
<PDBSymbolExe
>(PDB_SymType::Exe
);
474 VerifyDyncast
<PDBSymbolCompiland
>(PDB_SymType::Compiland
);
475 VerifyDyncast
<PDBSymbolCompilandDetails
>(PDB_SymType::CompilandDetails
);
476 VerifyDyncast
<PDBSymbolCompilandEnv
>(PDB_SymType::CompilandEnv
);
477 VerifyDyncast
<PDBSymbolFunc
>(PDB_SymType::Function
);
478 VerifyDyncast
<PDBSymbolBlock
>(PDB_SymType::Block
);
479 VerifyDyncast
<PDBSymbolData
>(PDB_SymType::Data
);
480 VerifyDyncast
<PDBSymbolAnnotation
>(PDB_SymType::Annotation
);
481 VerifyDyncast
<PDBSymbolLabel
>(PDB_SymType::Label
);
482 VerifyDyncast
<PDBSymbolPublicSymbol
>(PDB_SymType::PublicSymbol
);
483 VerifyDyncast
<PDBSymbolTypeUDT
>(PDB_SymType::UDT
);
484 VerifyDyncast
<PDBSymbolTypeEnum
>(PDB_SymType::Enum
);
485 VerifyDyncast
<PDBSymbolTypeFunctionSig
>(PDB_SymType::FunctionSig
);
486 VerifyDyncast
<PDBSymbolTypePointer
>(PDB_SymType::PointerType
);
487 VerifyDyncast
<PDBSymbolTypeArray
>(PDB_SymType::ArrayType
);
488 VerifyDyncast
<PDBSymbolTypeBuiltin
>(PDB_SymType::BuiltinType
);
489 VerifyDyncast
<PDBSymbolTypeTypedef
>(PDB_SymType::Typedef
);
490 VerifyDyncast
<PDBSymbolTypeBaseClass
>(PDB_SymType::BaseClass
);
491 VerifyDyncast
<PDBSymbolTypeFriend
>(PDB_SymType::Friend
);
492 VerifyDyncast
<PDBSymbolTypeFunctionArg
>(PDB_SymType::FunctionArg
);
493 VerifyDyncast
<PDBSymbolFuncDebugStart
>(PDB_SymType::FuncDebugStart
);
494 VerifyDyncast
<PDBSymbolFuncDebugEnd
>(PDB_SymType::FuncDebugEnd
);
495 VerifyDyncast
<PDBSymbolUsingNamespace
>(PDB_SymType::UsingNamespace
);
496 VerifyDyncast
<PDBSymbolTypeVTableShape
>(PDB_SymType::VTableShape
);
497 VerifyDyncast
<PDBSymbolTypeVTable
>(PDB_SymType::VTable
);
498 VerifyDyncast
<PDBSymbolCustom
>(PDB_SymType::Custom
);
499 VerifyDyncast
<PDBSymbolThunk
>(PDB_SymType::Thunk
);
500 VerifyDyncast
<PDBSymbolTypeCustom
>(PDB_SymType::CustomType
);
501 VerifyDyncast
<PDBSymbolTypeManaged
>(PDB_SymType::ManagedType
);
502 VerifyDyncast
<PDBSymbolTypeDimension
>(PDB_SymType::Dimension
);
504 VerifyUnknownDyncasts();
506 } // end anonymous namespace