blob: 2b8050a50f380a659d77683777cf8d87d0348957 [file] [log] [blame]
Zachary Turner94269a42015-02-07 01:47:14 +00001//===- 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
Zachary Turnerbe6d1e42015-02-10 23:46:48 +000012#include "llvm/ADT/STLExtras.h"
Zachary Turner94269a42015-02-07 01:47:14 +000013#include "llvm/DebugInfo/PDB/IPDBEnumChildren.h"
Zachary Turnera389c842018-03-13 17:58:28 +000014#include "llvm/DebugInfo/PDB/IPDBInjectedSource.h"
Aaron Smith25409dd2018-03-07 00:33:09 +000015#include "llvm/DebugInfo/PDB/IPDBLineNumber.h"
Zachary Turner94269a42015-02-07 01:47:14 +000016#include "llvm/DebugInfo/PDB/IPDBRawSymbol.h"
Zachary Turnerbae16b32015-02-08 20:58:09 +000017#include "llvm/DebugInfo/PDB/IPDBSession.h"
18#include "llvm/DebugInfo/PDB/IPDBSourceFile.h"
Aaron Smith89bca9e2017-11-16 14:33:09 +000019#include "llvm/DebugInfo/PDB/IPDBTable.h"
Zachary Turnerbae16b32015-02-08 20:58:09 +000020
Zachary Turner94269a42015-02-07 01:47:14 +000021#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;
Zachary Turnere13787e2016-05-04 21:06:12 +000056using namespace llvm::pdb;
Zachary Turner94269a42015-02-07 01:47:14 +000057
Zachary Turner94269a42015-02-07 01:47:14 +000058namespace {
59
60#define MOCK_SYMBOL_ACCESSOR(Func) \
Zachary Turner635c2c42015-02-07 02:02:23 +000061 decltype(std::declval<IPDBRawSymbol>().Func()) Func() const override { \
Zachary Turner94269a42015-02-07 01:47:14 +000062 typedef decltype(IPDBRawSymbol::Func()) ReturnType; \
63 return ReturnType(); \
64 }
65
Zachary Turnerbae16b32015-02-08 20:58:09 +000066class MockSession : public IPDBSession {
67 uint64_t getLoadAddress() const override { return 0; }
Aaron Smith89a19ac2018-02-23 00:02:27 +000068 bool setLoadAddress(uint64_t Address) override { return false; }
Adrian McCarthy6a4b0802017-06-22 18:42:23 +000069 std::unique_ptr<PDBSymbolExe> getGlobalScope() override { return nullptr; }
Zachary Turner0ca2bde2015-02-10 21:40:29 +000070 std::unique_ptr<PDBSymbol> getSymbolById(uint32_t SymbolId) const override {
71 return nullptr;
72 }
73 std::unique_ptr<IPDBSourceFile>
74 getSourceFileById(uint32_t SymbolId) const override {
Zachary Turnerbae16b32015-02-08 20:58:09 +000075 return nullptr;
76 }
Zachary Turner4b083542015-04-17 22:40:36 +000077
78 std::unique_ptr<PDBSymbol>
Zachary Turner292e92d2015-05-01 20:51:49 +000079 findSymbolByAddress(uint64_t Address, PDB_SymType Type) const override {
Zachary Turner4b083542015-04-17 22:40:36 +000080 return nullptr;
81 }
82 std::unique_ptr<IPDBEnumLineNumbers>
Zachary Turner43ec3af2016-02-18 18:47:29 +000083 findLineNumbers(const PDBSymbolCompiland &Compiland,
84 const IPDBSourceFile &File) const override {
85 return nullptr;
86 }
87 std::unique_ptr<IPDBEnumLineNumbers>
Zachary Turner4b083542015-04-17 22:40:36 +000088 findLineNumbersByAddress(uint64_t Address, uint32_t Length) const override {
89 return nullptr;
90 }
Aaron Smith40198f52018-03-15 06:04:51 +000091 std::unique_ptr<IPDBEnumLineNumbers>
92 findLineNumbersBySectOffset(uint32_t Section, uint32_t Offset,
93 uint32_t Length) const override {
94 return nullptr;
95 }
Zachary Turner43ec3af2016-02-18 18:47:29 +000096 std::unique_ptr<IPDBEnumSourceFiles>
97 findSourceFiles(const PDBSymbolCompiland *Compiland, llvm::StringRef Pattern,
98 PDB_NameSearchFlags Flags) const override {
99 return nullptr;
100 }
101 std::unique_ptr<IPDBSourceFile>
102 findOneSourceFile(const PDBSymbolCompiland *Compiland,
103 llvm::StringRef Pattern,
104 PDB_NameSearchFlags Flags) const override {
105 return nullptr;
106 }
107 std::unique_ptr<IPDBEnumChildren<PDBSymbolCompiland>>
108 findCompilandsForSourceFile(llvm::StringRef Pattern,
109 PDB_NameSearchFlags Flags) const override {
110 return nullptr;
111 }
112 std::unique_ptr<PDBSymbolCompiland>
113 findOneCompilandForSourceFile(llvm::StringRef Pattern,
114 PDB_NameSearchFlags Flags) const override {
115 return nullptr;
116 }
Zachary Turner4b083542015-04-17 22:40:36 +0000117
Zachary Turnera5549172015-02-10 22:43:25 +0000118 std::unique_ptr<IPDBEnumSourceFiles> getAllSourceFiles() const override {
119 return nullptr;
120 }
121 std::unique_ptr<IPDBEnumSourceFiles> getSourceFilesForCompiland(
122 const PDBSymbolCompiland &Compiland) const override {
Zachary Turnerbae16b32015-02-08 20:58:09 +0000123 return nullptr;
124 }
Zachary Turnerc9c9c342015-02-10 22:56:21 +0000125
126 std::unique_ptr<IPDBEnumDataStreams> getDebugStreams() const override {
127 return nullptr;
128 }
Aaron Smith89bca9e2017-11-16 14:33:09 +0000129
130 std::unique_ptr<IPDBEnumTables> getEnumTables() const override {
131 return nullptr;
132 }
Zachary Turnera389c842018-03-13 17:58:28 +0000133
134 std::unique_ptr<IPDBEnumInjectedSources> getInjectedSources() const override {
135 return nullptr;
136 }
Zachary Turnerbae16b32015-02-08 20:58:09 +0000137};
138
Zachary Turner94269a42015-02-07 01:47:14 +0000139class MockRawSymbol : public IPDBRawSymbol {
140public:
Zachary Turnerf07ef222015-02-11 00:33:00 +0000141 MockRawSymbol(PDB_SymType SymType)
142 : Type(SymType) {}
Zachary Turner94269a42015-02-07 01:47:14 +0000143
Zachary Turnerbc42da02015-02-23 05:59:14 +0000144 void dump(raw_ostream &OS, int Indent) const override {}
Zachary Turner94269a42015-02-07 01:47:14 +0000145
Chandler Carruthc94234c2015-02-07 08:12:22 +0000146 std::unique_ptr<IPDBEnumSymbols>
Zachary Turnera5549172015-02-10 22:43:25 +0000147 findChildren(PDB_SymType Type) const override {
148 return nullptr;
149 }
150 std::unique_ptr<IPDBEnumSymbols>
Zachary Turner94269a42015-02-07 01:47:14 +0000151 findChildren(PDB_SymType Type, StringRef Name,
Chandler Carruthc94234c2015-02-07 08:12:22 +0000152 PDB_NameSearchFlags Flags) const override {
Zachary Turner94269a42015-02-07 01:47:14 +0000153 return nullptr;
154 }
Chandler Carruthc94234c2015-02-07 08:12:22 +0000155 std::unique_ptr<IPDBEnumSymbols>
Aaron Smithfbe65402018-02-22 19:47:43 +0000156 findChildrenByAddr(PDB_SymType Type, StringRef Name, PDB_NameSearchFlags Flags,
Aaron Smith9930e902018-02-22 20:28:40 +0000157 uint32_t Section, uint32_t Offset) const override {
Aaron Smithfbe65402018-02-22 19:47:43 +0000158 return nullptr;
159 }
160 std::unique_ptr<IPDBEnumSymbols>
161 findChildrenByVA(PDB_SymType Type, StringRef Name, PDB_NameSearchFlags Flags,
162 uint64_t VA) const override {
163 return nullptr;
164 }
165 std::unique_ptr<IPDBEnumSymbols>
Zachary Turner94269a42015-02-07 01:47:14 +0000166 findChildrenByRVA(PDB_SymType Type, StringRef Name, PDB_NameSearchFlags Flags,
Chandler Carruthc94234c2015-02-07 08:12:22 +0000167 uint32_t RVA) const override {
Zachary Turner94269a42015-02-07 01:47:14 +0000168 return nullptr;
169 }
Chandler Carruthc94234c2015-02-07 08:12:22 +0000170 std::unique_ptr<IPDBEnumSymbols>
Aaron Smithfbe65402018-02-22 19:47:43 +0000171 findInlineFramesByAddr(uint32_t Section, uint32_t Offset) const override {
172 return nullptr;
173 }
174 std::unique_ptr<IPDBEnumSymbols>
Chandler Carruthc94234c2015-02-07 08:12:22 +0000175 findInlineFramesByRVA(uint32_t RVA) const override {
Zachary Turner94269a42015-02-07 01:47:14 +0000176 return nullptr;
177 }
Aaron Smithfbe65402018-02-22 19:47:43 +0000178 std::unique_ptr<IPDBEnumSymbols>
179 findInlineFramesByVA(uint64_t VA) const override {
180 return nullptr;
181 }
182 std::unique_ptr<IPDBEnumLineNumbers> findInlineeLines() const override {
183 return nullptr;
184 }
185 std::unique_ptr<IPDBEnumLineNumbers>
186 findInlineeLinesByAddr(uint32_t Section, uint32_t Offset,
187 uint32_t Length) const override {
188 return nullptr;
189 }
190 std::unique_ptr<IPDBEnumLineNumbers>
191 findInlineeLinesByRVA(uint32_t RVA, uint32_t Length) const override {
192 return nullptr;
193 }
194 std::unique_ptr<IPDBEnumLineNumbers>
195 findInlineeLinesByVA(uint64_t VA, uint32_t Length) const override {
196 return nullptr;
197 }
Zachary Turner94269a42015-02-07 01:47:14 +0000198
Chandler Carruthc94234c2015-02-07 08:12:22 +0000199 void getDataBytes(llvm::SmallVector<uint8_t, 32> &bytes) const override {}
Zachary Turner21473f72015-02-08 00:29:29 +0000200 void getFrontEndVersion(VersionInfo &Version) const override {}
201 void getBackEndVersion(VersionInfo &Version) const override {}
Zachary Turner94269a42015-02-07 01:47:14 +0000202
203 PDB_SymType getSymTag() const override { return Type; }
204
Aaron Smith89bca9e2017-11-16 14:33:09 +0000205 std::string getUndecoratedNameEx(PDB_UndnameFlags Flags) const override {
206 return {};
207 }
208
Aaron Smith25409dd2018-03-07 00:33:09 +0000209 std::unique_ptr<IPDBLineNumber> getSrcLineOnTypeDefn() const override {
210 return nullptr;
211 }
212
Zachary Turner94269a42015-02-07 01:47:14 +0000213 MOCK_SYMBOL_ACCESSOR(getAccess)
214 MOCK_SYMBOL_ACCESSOR(getAddressOffset)
215 MOCK_SYMBOL_ACCESSOR(getAddressSection)
216 MOCK_SYMBOL_ACCESSOR(getAge)
217 MOCK_SYMBOL_ACCESSOR(getArrayIndexTypeId)
Zachary Turner94269a42015-02-07 01:47:14 +0000218 MOCK_SYMBOL_ACCESSOR(getBaseDataOffset)
219 MOCK_SYMBOL_ACCESSOR(getBaseDataSlot)
220 MOCK_SYMBOL_ACCESSOR(getBaseSymbolId)
221 MOCK_SYMBOL_ACCESSOR(getBuiltinType)
222 MOCK_SYMBOL_ACCESSOR(getBitPosition)
223 MOCK_SYMBOL_ACCESSOR(getCallingConvention)
224 MOCK_SYMBOL_ACCESSOR(getClassParentId)
225 MOCK_SYMBOL_ACCESSOR(getCompilerName)
226 MOCK_SYMBOL_ACCESSOR(getCount)
227 MOCK_SYMBOL_ACCESSOR(getCountLiveRanges)
Zachary Turner94269a42015-02-07 01:47:14 +0000228 MOCK_SYMBOL_ACCESSOR(getLanguage)
229 MOCK_SYMBOL_ACCESSOR(getLexicalParentId)
230 MOCK_SYMBOL_ACCESSOR(getLibraryName)
231 MOCK_SYMBOL_ACCESSOR(getLiveRangeStartAddressOffset)
232 MOCK_SYMBOL_ACCESSOR(getLiveRangeStartAddressSection)
233 MOCK_SYMBOL_ACCESSOR(getLiveRangeStartRelativeVirtualAddress)
234 MOCK_SYMBOL_ACCESSOR(getLocalBasePointerRegisterId)
235 MOCK_SYMBOL_ACCESSOR(getLowerBoundId)
236 MOCK_SYMBOL_ACCESSOR(getMemorySpaceKind)
237 MOCK_SYMBOL_ACCESSOR(getName)
238 MOCK_SYMBOL_ACCESSOR(getNumberOfAcceleratorPointerTags)
239 MOCK_SYMBOL_ACCESSOR(getNumberOfColumns)
240 MOCK_SYMBOL_ACCESSOR(getNumberOfModifiers)
241 MOCK_SYMBOL_ACCESSOR(getNumberOfRegisterIndices)
242 MOCK_SYMBOL_ACCESSOR(getNumberOfRows)
243 MOCK_SYMBOL_ACCESSOR(getObjectFileName)
244 MOCK_SYMBOL_ACCESSOR(getOemId)
245 MOCK_SYMBOL_ACCESSOR(getOemSymbolId)
246 MOCK_SYMBOL_ACCESSOR(getOffsetInUdt)
247 MOCK_SYMBOL_ACCESSOR(getPlatform)
248 MOCK_SYMBOL_ACCESSOR(getRank)
249 MOCK_SYMBOL_ACCESSOR(getRegisterId)
250 MOCK_SYMBOL_ACCESSOR(getRegisterType)
251 MOCK_SYMBOL_ACCESSOR(getRelativeVirtualAddress)
252 MOCK_SYMBOL_ACCESSOR(getSamplerSlot)
253 MOCK_SYMBOL_ACCESSOR(getSignature)
254 MOCK_SYMBOL_ACCESSOR(getSizeInUdt)
255 MOCK_SYMBOL_ACCESSOR(getSlot)
256 MOCK_SYMBOL_ACCESSOR(getSourceFileName)
257 MOCK_SYMBOL_ACCESSOR(getStride)
258 MOCK_SYMBOL_ACCESSOR(getSubTypeId)
259 MOCK_SYMBOL_ACCESSOR(getSymbolsFileName)
260 MOCK_SYMBOL_ACCESSOR(getSymIndexId)
261 MOCK_SYMBOL_ACCESSOR(getTargetOffset)
262 MOCK_SYMBOL_ACCESSOR(getTargetRelativeVirtualAddress)
263 MOCK_SYMBOL_ACCESSOR(getTargetVirtualAddress)
264 MOCK_SYMBOL_ACCESSOR(getTargetSection)
265 MOCK_SYMBOL_ACCESSOR(getTextureSlot)
266 MOCK_SYMBOL_ACCESSOR(getTimeStamp)
267 MOCK_SYMBOL_ACCESSOR(getToken)
268 MOCK_SYMBOL_ACCESSOR(getTypeId)
269 MOCK_SYMBOL_ACCESSOR(getUavSlot)
270 MOCK_SYMBOL_ACCESSOR(getUndecoratedName)
271 MOCK_SYMBOL_ACCESSOR(getUnmodifiedTypeId)
272 MOCK_SYMBOL_ACCESSOR(getUpperBoundId)
273 MOCK_SYMBOL_ACCESSOR(getVirtualBaseDispIndex)
274 MOCK_SYMBOL_ACCESSOR(getVirtualBaseOffset)
275 MOCK_SYMBOL_ACCESSOR(getVirtualTableShapeId)
276 MOCK_SYMBOL_ACCESSOR(getDataKind)
277 MOCK_SYMBOL_ACCESSOR(getGuid)
278 MOCK_SYMBOL_ACCESSOR(getOffset)
279 MOCK_SYMBOL_ACCESSOR(getThisAdjust)
280 MOCK_SYMBOL_ACCESSOR(getVirtualBasePointerOffset)
281 MOCK_SYMBOL_ACCESSOR(getLocationType)
282 MOCK_SYMBOL_ACCESSOR(getMachineType)
283 MOCK_SYMBOL_ACCESSOR(getThunkOrdinal)
284 MOCK_SYMBOL_ACCESSOR(getLength)
Zachary Turnerc883a8c2017-04-12 23:18:21 +0000285 MOCK_SYMBOL_ACCESSOR(getVirtualBaseTableType)
Zachary Turner94269a42015-02-07 01:47:14 +0000286 MOCK_SYMBOL_ACCESSOR(getLiveRangeLength)
287 MOCK_SYMBOL_ACCESSOR(getVirtualAddress)
288 MOCK_SYMBOL_ACCESSOR(getUdtKind)
289 MOCK_SYMBOL_ACCESSOR(hasConstructor)
290 MOCK_SYMBOL_ACCESSOR(hasCustomCallingConvention)
291 MOCK_SYMBOL_ACCESSOR(hasFarReturn)
292 MOCK_SYMBOL_ACCESSOR(isCode)
293 MOCK_SYMBOL_ACCESSOR(isCompilerGenerated)
294 MOCK_SYMBOL_ACCESSOR(isConstType)
295 MOCK_SYMBOL_ACCESSOR(isEditAndContinueEnabled)
296 MOCK_SYMBOL_ACCESSOR(isFunction)
297 MOCK_SYMBOL_ACCESSOR(getAddressTaken)
298 MOCK_SYMBOL_ACCESSOR(getNoStackOrdering)
299 MOCK_SYMBOL_ACCESSOR(hasAlloca)
300 MOCK_SYMBOL_ACCESSOR(hasAssignmentOperator)
301 MOCK_SYMBOL_ACCESSOR(hasCTypes)
302 MOCK_SYMBOL_ACCESSOR(hasCastOperator)
303 MOCK_SYMBOL_ACCESSOR(hasDebugInfo)
304 MOCK_SYMBOL_ACCESSOR(hasEH)
305 MOCK_SYMBOL_ACCESSOR(hasEHa)
Zachary Turnera5549172015-02-10 22:43:25 +0000306 MOCK_SYMBOL_ACCESSOR(hasFramePointer)
Zachary Turner94269a42015-02-07 01:47:14 +0000307 MOCK_SYMBOL_ACCESSOR(hasInlAsm)
308 MOCK_SYMBOL_ACCESSOR(hasInlineAttribute)
309 MOCK_SYMBOL_ACCESSOR(hasInterruptReturn)
310 MOCK_SYMBOL_ACCESSOR(hasLongJump)
311 MOCK_SYMBOL_ACCESSOR(hasManagedCode)
312 MOCK_SYMBOL_ACCESSOR(hasNestedTypes)
313 MOCK_SYMBOL_ACCESSOR(hasNoInlineAttribute)
314 MOCK_SYMBOL_ACCESSOR(hasNoReturnAttribute)
315 MOCK_SYMBOL_ACCESSOR(hasOptimizedCodeDebugInfo)
316 MOCK_SYMBOL_ACCESSOR(hasOverloadedOperator)
317 MOCK_SYMBOL_ACCESSOR(hasSEH)
318 MOCK_SYMBOL_ACCESSOR(hasSecurityChecks)
319 MOCK_SYMBOL_ACCESSOR(hasSetJump)
320 MOCK_SYMBOL_ACCESSOR(hasStrictGSCheck)
321 MOCK_SYMBOL_ACCESSOR(isAcceleratorGroupSharedLocal)
322 MOCK_SYMBOL_ACCESSOR(isAcceleratorPointerTagLiveRange)
323 MOCK_SYMBOL_ACCESSOR(isAcceleratorStubFunction)
324 MOCK_SYMBOL_ACCESSOR(isAggregated)
325 MOCK_SYMBOL_ACCESSOR(isIntroVirtualFunction)
326 MOCK_SYMBOL_ACCESSOR(isCVTCIL)
327 MOCK_SYMBOL_ACCESSOR(isConstructorVirtualBase)
328 MOCK_SYMBOL_ACCESSOR(isCxxReturnUdt)
329 MOCK_SYMBOL_ACCESSOR(isDataAligned)
330 MOCK_SYMBOL_ACCESSOR(isHLSLData)
331 MOCK_SYMBOL_ACCESSOR(isHotpatchable)
332 MOCK_SYMBOL_ACCESSOR(isIndirectVirtualBaseClass)
333 MOCK_SYMBOL_ACCESSOR(isInterfaceUdt)
334 MOCK_SYMBOL_ACCESSOR(isIntrinsic)
335 MOCK_SYMBOL_ACCESSOR(isLTCG)
336 MOCK_SYMBOL_ACCESSOR(isLocationControlFlowDependent)
337 MOCK_SYMBOL_ACCESSOR(isMSILNetmodule)
338 MOCK_SYMBOL_ACCESSOR(isMatrixRowMajor)
339 MOCK_SYMBOL_ACCESSOR(isManagedCode)
340 MOCK_SYMBOL_ACCESSOR(isMSILCode)
341 MOCK_SYMBOL_ACCESSOR(isMultipleInheritance)
342 MOCK_SYMBOL_ACCESSOR(isNaked)
343 MOCK_SYMBOL_ACCESSOR(isNested)
344 MOCK_SYMBOL_ACCESSOR(isOptimizedAway)
345 MOCK_SYMBOL_ACCESSOR(isPacked)
346 MOCK_SYMBOL_ACCESSOR(isPointerBasedOnSymbolValue)
347 MOCK_SYMBOL_ACCESSOR(isPointerToDataMember)
348 MOCK_SYMBOL_ACCESSOR(isPointerToMemberFunction)
349 MOCK_SYMBOL_ACCESSOR(isPureVirtual)
350 MOCK_SYMBOL_ACCESSOR(isRValueReference)
351 MOCK_SYMBOL_ACCESSOR(isRefUdt)
352 MOCK_SYMBOL_ACCESSOR(isReference)
353 MOCK_SYMBOL_ACCESSOR(isRestrictedType)
354 MOCK_SYMBOL_ACCESSOR(isReturnValue)
355 MOCK_SYMBOL_ACCESSOR(isSafeBuffers)
356 MOCK_SYMBOL_ACCESSOR(isScoped)
357 MOCK_SYMBOL_ACCESSOR(isSdl)
358 MOCK_SYMBOL_ACCESSOR(isSingleInheritance)
359 MOCK_SYMBOL_ACCESSOR(isSplitted)
360 MOCK_SYMBOL_ACCESSOR(isStatic)
361 MOCK_SYMBOL_ACCESSOR(hasPrivateSymbols)
362 MOCK_SYMBOL_ACCESSOR(isUnalignedType)
363 MOCK_SYMBOL_ACCESSOR(isUnreached)
364 MOCK_SYMBOL_ACCESSOR(isValueUdt)
365 MOCK_SYMBOL_ACCESSOR(isVirtual)
366 MOCK_SYMBOL_ACCESSOR(isVirtualBaseClass)
367 MOCK_SYMBOL_ACCESSOR(isVirtualInheritance)
368 MOCK_SYMBOL_ACCESSOR(isVolatileType)
Zachary Turner00dbc752015-02-13 01:39:22 +0000369 MOCK_SYMBOL_ACCESSOR(getValue)
370 MOCK_SYMBOL_ACCESSOR(wasInlined)
371 MOCK_SYMBOL_ACCESSOR(getUnused)
Zachary Turner94269a42015-02-07 01:47:14 +0000372
373private:
374 PDB_SymType Type;
375};
376
377class PDBApiTest : public testing::Test {
378public:
379 std::unordered_map<PDB_SymType, std::unique_ptr<PDBSymbol>> SymbolMap;
380
381 void SetUp() override {
Zachary Turnerbae16b32015-02-08 20:58:09 +0000382 Session.reset(new MockSession());
383
Zachary Turner94269a42015-02-07 01:47:14 +0000384 InsertItemWithTag(PDB_SymType::None);
385 InsertItemWithTag(PDB_SymType::Exe);
386 InsertItemWithTag(PDB_SymType::Compiland);
387 InsertItemWithTag(PDB_SymType::CompilandDetails);
388 InsertItemWithTag(PDB_SymType::CompilandEnv);
389 InsertItemWithTag(PDB_SymType::Function);
390 InsertItemWithTag(PDB_SymType::Block);
391 InsertItemWithTag(PDB_SymType::Data);
392 InsertItemWithTag(PDB_SymType::Annotation);
393 InsertItemWithTag(PDB_SymType::Label);
394 InsertItemWithTag(PDB_SymType::PublicSymbol);
395 InsertItemWithTag(PDB_SymType::UDT);
396 InsertItemWithTag(PDB_SymType::Enum);
397 InsertItemWithTag(PDB_SymType::FunctionSig);
398 InsertItemWithTag(PDB_SymType::PointerType);
399 InsertItemWithTag(PDB_SymType::ArrayType);
400 InsertItemWithTag(PDB_SymType::BuiltinType);
401 InsertItemWithTag(PDB_SymType::Typedef);
402 InsertItemWithTag(PDB_SymType::BaseClass);
403 InsertItemWithTag(PDB_SymType::Friend);
404 InsertItemWithTag(PDB_SymType::FunctionArg);
405 InsertItemWithTag(PDB_SymType::FuncDebugStart);
406 InsertItemWithTag(PDB_SymType::FuncDebugEnd);
407 InsertItemWithTag(PDB_SymType::UsingNamespace);
408 InsertItemWithTag(PDB_SymType::VTableShape);
409 InsertItemWithTag(PDB_SymType::VTable);
410 InsertItemWithTag(PDB_SymType::Custom);
411 InsertItemWithTag(PDB_SymType::Thunk);
412 InsertItemWithTag(PDB_SymType::CustomType);
413 InsertItemWithTag(PDB_SymType::ManagedType);
414 InsertItemWithTag(PDB_SymType::Dimension);
415 InsertItemWithTag(PDB_SymType::Max);
416 }
417
Zachary Turner94269a42015-02-07 01:47:14 +0000418 template <class ExpectedType> void VerifyDyncast(PDB_SymType Tag) {
419 for (auto item = SymbolMap.begin(); item != SymbolMap.end(); ++item) {
420 EXPECT_EQ(item->first == Tag, llvm::isa<ExpectedType>(*item->second));
421 }
422 }
423
424 void VerifyUnknownDyncasts() {
425 for (auto item = SymbolMap.begin(); item != SymbolMap.end(); ++item) {
426 bool should_match = false;
427 if (item->first == PDB_SymType::None || item->first >= PDB_SymType::Max)
428 should_match = true;
429
430 EXPECT_EQ(should_match, llvm::isa<PDBSymbolUnknown>(*item->second));
431 }
432 }
Zachary Turnerbae16b32015-02-08 20:58:09 +0000433
434private:
435 std::unique_ptr<IPDBSession> Session;
436
437 void InsertItemWithTag(PDB_SymType Tag) {
Zachary Turnerf07ef222015-02-11 00:33:00 +0000438 auto RawSymbol = llvm::make_unique<MockRawSymbol>(Tag);
Zachary Turnerbae16b32015-02-08 20:58:09 +0000439 auto Symbol = PDBSymbol::create(*Session, std::move(RawSymbol));
440 SymbolMap.insert(std::make_pair(Tag, std::move(Symbol)));
441 }
Zachary Turner94269a42015-02-07 01:47:14 +0000442};
443
444TEST_F(PDBApiTest, Dyncast) {
445
446 // Most of the types have a one-to-one mapping between Tag and concrete type.
447 VerifyDyncast<PDBSymbolExe>(PDB_SymType::Exe);
448 VerifyDyncast<PDBSymbolCompiland>(PDB_SymType::Compiland);
449 VerifyDyncast<PDBSymbolCompilandDetails>(PDB_SymType::CompilandDetails);
450 VerifyDyncast<PDBSymbolCompilandEnv>(PDB_SymType::CompilandEnv);
451 VerifyDyncast<PDBSymbolFunc>(PDB_SymType::Function);
452 VerifyDyncast<PDBSymbolBlock>(PDB_SymType::Block);
453 VerifyDyncast<PDBSymbolData>(PDB_SymType::Data);
454 VerifyDyncast<PDBSymbolAnnotation>(PDB_SymType::Annotation);
455 VerifyDyncast<PDBSymbolLabel>(PDB_SymType::Label);
456 VerifyDyncast<PDBSymbolPublicSymbol>(PDB_SymType::PublicSymbol);
457 VerifyDyncast<PDBSymbolTypeUDT>(PDB_SymType::UDT);
458 VerifyDyncast<PDBSymbolTypeEnum>(PDB_SymType::Enum);
459 VerifyDyncast<PDBSymbolTypeFunctionSig>(PDB_SymType::FunctionSig);
460 VerifyDyncast<PDBSymbolTypePointer>(PDB_SymType::PointerType);
461 VerifyDyncast<PDBSymbolTypeArray>(PDB_SymType::ArrayType);
462 VerifyDyncast<PDBSymbolTypeBuiltin>(PDB_SymType::BuiltinType);
463 VerifyDyncast<PDBSymbolTypeTypedef>(PDB_SymType::Typedef);
464 VerifyDyncast<PDBSymbolTypeBaseClass>(PDB_SymType::BaseClass);
465 VerifyDyncast<PDBSymbolTypeFriend>(PDB_SymType::Friend);
466 VerifyDyncast<PDBSymbolTypeFunctionArg>(PDB_SymType::FunctionArg);
467 VerifyDyncast<PDBSymbolFuncDebugStart>(PDB_SymType::FuncDebugStart);
468 VerifyDyncast<PDBSymbolFuncDebugEnd>(PDB_SymType::FuncDebugEnd);
469 VerifyDyncast<PDBSymbolUsingNamespace>(PDB_SymType::UsingNamespace);
470 VerifyDyncast<PDBSymbolTypeVTableShape>(PDB_SymType::VTableShape);
471 VerifyDyncast<PDBSymbolTypeVTable>(PDB_SymType::VTable);
472 VerifyDyncast<PDBSymbolCustom>(PDB_SymType::Custom);
473 VerifyDyncast<PDBSymbolThunk>(PDB_SymType::Thunk);
474 VerifyDyncast<PDBSymbolTypeCustom>(PDB_SymType::CustomType);
475 VerifyDyncast<PDBSymbolTypeManaged>(PDB_SymType::ManagedType);
476 VerifyDyncast<PDBSymbolTypeDimension>(PDB_SymType::Dimension);
477
478 VerifyUnknownDyncasts();
479}
480
481} // end anonymous namespace