blob: 4cc47aa454040916c9e7b59eed77a70d218189bd [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 }
Zachary Turner43ec3af2016-02-18 18:47:29 +000091 std::unique_ptr<IPDBEnumSourceFiles>
92 findSourceFiles(const PDBSymbolCompiland *Compiland, llvm::StringRef Pattern,
93 PDB_NameSearchFlags Flags) const override {
94 return nullptr;
95 }
96 std::unique_ptr<IPDBSourceFile>
97 findOneSourceFile(const PDBSymbolCompiland *Compiland,
98 llvm::StringRef Pattern,
99 PDB_NameSearchFlags Flags) const override {
100 return nullptr;
101 }
102 std::unique_ptr<IPDBEnumChildren<PDBSymbolCompiland>>
103 findCompilandsForSourceFile(llvm::StringRef Pattern,
104 PDB_NameSearchFlags Flags) const override {
105 return nullptr;
106 }
107 std::unique_ptr<PDBSymbolCompiland>
108 findOneCompilandForSourceFile(llvm::StringRef Pattern,
109 PDB_NameSearchFlags Flags) const override {
110 return nullptr;
111 }
Zachary Turner4b083542015-04-17 22:40:36 +0000112
Zachary Turnera5549172015-02-10 22:43:25 +0000113 std::unique_ptr<IPDBEnumSourceFiles> getAllSourceFiles() const override {
114 return nullptr;
115 }
116 std::unique_ptr<IPDBEnumSourceFiles> getSourceFilesForCompiland(
117 const PDBSymbolCompiland &Compiland) const override {
Zachary Turnerbae16b32015-02-08 20:58:09 +0000118 return nullptr;
119 }
Zachary Turnerc9c9c342015-02-10 22:56:21 +0000120
121 std::unique_ptr<IPDBEnumDataStreams> getDebugStreams() const override {
122 return nullptr;
123 }
Aaron Smith89bca9e2017-11-16 14:33:09 +0000124
125 std::unique_ptr<IPDBEnumTables> getEnumTables() const override {
126 return nullptr;
127 }
Zachary Turnera389c842018-03-13 17:58:28 +0000128
129 std::unique_ptr<IPDBEnumInjectedSources> getInjectedSources() const override {
130 return nullptr;
131 }
Zachary Turnerbae16b32015-02-08 20:58:09 +0000132};
133
Zachary Turner94269a42015-02-07 01:47:14 +0000134class MockRawSymbol : public IPDBRawSymbol {
135public:
Zachary Turnerf07ef222015-02-11 00:33:00 +0000136 MockRawSymbol(PDB_SymType SymType)
137 : Type(SymType) {}
Zachary Turner94269a42015-02-07 01:47:14 +0000138
Zachary Turnerbc42da02015-02-23 05:59:14 +0000139 void dump(raw_ostream &OS, int Indent) const override {}
Zachary Turner94269a42015-02-07 01:47:14 +0000140
Chandler Carruthc94234c2015-02-07 08:12:22 +0000141 std::unique_ptr<IPDBEnumSymbols>
Zachary Turnera5549172015-02-10 22:43:25 +0000142 findChildren(PDB_SymType Type) const override {
143 return nullptr;
144 }
145 std::unique_ptr<IPDBEnumSymbols>
Zachary Turner94269a42015-02-07 01:47:14 +0000146 findChildren(PDB_SymType Type, StringRef Name,
Chandler Carruthc94234c2015-02-07 08:12:22 +0000147 PDB_NameSearchFlags Flags) const override {
Zachary Turner94269a42015-02-07 01:47:14 +0000148 return nullptr;
149 }
Chandler Carruthc94234c2015-02-07 08:12:22 +0000150 std::unique_ptr<IPDBEnumSymbols>
Aaron Smithfbe65402018-02-22 19:47:43 +0000151 findChildrenByAddr(PDB_SymType Type, StringRef Name, PDB_NameSearchFlags Flags,
Aaron Smith9930e902018-02-22 20:28:40 +0000152 uint32_t Section, uint32_t Offset) const override {
Aaron Smithfbe65402018-02-22 19:47:43 +0000153 return nullptr;
154 }
155 std::unique_ptr<IPDBEnumSymbols>
156 findChildrenByVA(PDB_SymType Type, StringRef Name, PDB_NameSearchFlags Flags,
157 uint64_t VA) const override {
158 return nullptr;
159 }
160 std::unique_ptr<IPDBEnumSymbols>
Zachary Turner94269a42015-02-07 01:47:14 +0000161 findChildrenByRVA(PDB_SymType Type, StringRef Name, PDB_NameSearchFlags Flags,
Chandler Carruthc94234c2015-02-07 08:12:22 +0000162 uint32_t RVA) const override {
Zachary Turner94269a42015-02-07 01:47:14 +0000163 return nullptr;
164 }
Chandler Carruthc94234c2015-02-07 08:12:22 +0000165 std::unique_ptr<IPDBEnumSymbols>
Aaron Smithfbe65402018-02-22 19:47:43 +0000166 findInlineFramesByAddr(uint32_t Section, uint32_t Offset) const override {
167 return nullptr;
168 }
169 std::unique_ptr<IPDBEnumSymbols>
Chandler Carruthc94234c2015-02-07 08:12:22 +0000170 findInlineFramesByRVA(uint32_t RVA) const override {
Zachary Turner94269a42015-02-07 01:47:14 +0000171 return nullptr;
172 }
Aaron Smithfbe65402018-02-22 19:47:43 +0000173 std::unique_ptr<IPDBEnumSymbols>
174 findInlineFramesByVA(uint64_t VA) const override {
175 return nullptr;
176 }
177 std::unique_ptr<IPDBEnumLineNumbers> findInlineeLines() const override {
178 return nullptr;
179 }
180 std::unique_ptr<IPDBEnumLineNumbers>
181 findInlineeLinesByAddr(uint32_t Section, uint32_t Offset,
182 uint32_t Length) const override {
183 return nullptr;
184 }
185 std::unique_ptr<IPDBEnumLineNumbers>
186 findInlineeLinesByRVA(uint32_t RVA, uint32_t Length) const override {
187 return nullptr;
188 }
189 std::unique_ptr<IPDBEnumLineNumbers>
190 findInlineeLinesByVA(uint64_t VA, uint32_t Length) const override {
191 return nullptr;
192 }
Zachary Turner94269a42015-02-07 01:47:14 +0000193
Chandler Carruthc94234c2015-02-07 08:12:22 +0000194 void getDataBytes(llvm::SmallVector<uint8_t, 32> &bytes) const override {}
Zachary Turner21473f72015-02-08 00:29:29 +0000195 void getFrontEndVersion(VersionInfo &Version) const override {}
196 void getBackEndVersion(VersionInfo &Version) const override {}
Zachary Turner94269a42015-02-07 01:47:14 +0000197
198 PDB_SymType getSymTag() const override { return Type; }
199
Aaron Smith89bca9e2017-11-16 14:33:09 +0000200 std::string getUndecoratedNameEx(PDB_UndnameFlags Flags) const override {
201 return {};
202 }
203
Aaron Smith25409dd2018-03-07 00:33:09 +0000204 std::unique_ptr<IPDBLineNumber> getSrcLineOnTypeDefn() const override {
205 return nullptr;
206 }
207
Zachary Turner94269a42015-02-07 01:47:14 +0000208 MOCK_SYMBOL_ACCESSOR(getAccess)
209 MOCK_SYMBOL_ACCESSOR(getAddressOffset)
210 MOCK_SYMBOL_ACCESSOR(getAddressSection)
211 MOCK_SYMBOL_ACCESSOR(getAge)
212 MOCK_SYMBOL_ACCESSOR(getArrayIndexTypeId)
Zachary Turner94269a42015-02-07 01:47:14 +0000213 MOCK_SYMBOL_ACCESSOR(getBaseDataOffset)
214 MOCK_SYMBOL_ACCESSOR(getBaseDataSlot)
215 MOCK_SYMBOL_ACCESSOR(getBaseSymbolId)
216 MOCK_SYMBOL_ACCESSOR(getBuiltinType)
217 MOCK_SYMBOL_ACCESSOR(getBitPosition)
218 MOCK_SYMBOL_ACCESSOR(getCallingConvention)
219 MOCK_SYMBOL_ACCESSOR(getClassParentId)
220 MOCK_SYMBOL_ACCESSOR(getCompilerName)
221 MOCK_SYMBOL_ACCESSOR(getCount)
222 MOCK_SYMBOL_ACCESSOR(getCountLiveRanges)
Zachary Turner94269a42015-02-07 01:47:14 +0000223 MOCK_SYMBOL_ACCESSOR(getLanguage)
224 MOCK_SYMBOL_ACCESSOR(getLexicalParentId)
225 MOCK_SYMBOL_ACCESSOR(getLibraryName)
226 MOCK_SYMBOL_ACCESSOR(getLiveRangeStartAddressOffset)
227 MOCK_SYMBOL_ACCESSOR(getLiveRangeStartAddressSection)
228 MOCK_SYMBOL_ACCESSOR(getLiveRangeStartRelativeVirtualAddress)
229 MOCK_SYMBOL_ACCESSOR(getLocalBasePointerRegisterId)
230 MOCK_SYMBOL_ACCESSOR(getLowerBoundId)
231 MOCK_SYMBOL_ACCESSOR(getMemorySpaceKind)
232 MOCK_SYMBOL_ACCESSOR(getName)
233 MOCK_SYMBOL_ACCESSOR(getNumberOfAcceleratorPointerTags)
234 MOCK_SYMBOL_ACCESSOR(getNumberOfColumns)
235 MOCK_SYMBOL_ACCESSOR(getNumberOfModifiers)
236 MOCK_SYMBOL_ACCESSOR(getNumberOfRegisterIndices)
237 MOCK_SYMBOL_ACCESSOR(getNumberOfRows)
238 MOCK_SYMBOL_ACCESSOR(getObjectFileName)
239 MOCK_SYMBOL_ACCESSOR(getOemId)
240 MOCK_SYMBOL_ACCESSOR(getOemSymbolId)
241 MOCK_SYMBOL_ACCESSOR(getOffsetInUdt)
242 MOCK_SYMBOL_ACCESSOR(getPlatform)
243 MOCK_SYMBOL_ACCESSOR(getRank)
244 MOCK_SYMBOL_ACCESSOR(getRegisterId)
245 MOCK_SYMBOL_ACCESSOR(getRegisterType)
246 MOCK_SYMBOL_ACCESSOR(getRelativeVirtualAddress)
247 MOCK_SYMBOL_ACCESSOR(getSamplerSlot)
248 MOCK_SYMBOL_ACCESSOR(getSignature)
249 MOCK_SYMBOL_ACCESSOR(getSizeInUdt)
250 MOCK_SYMBOL_ACCESSOR(getSlot)
251 MOCK_SYMBOL_ACCESSOR(getSourceFileName)
252 MOCK_SYMBOL_ACCESSOR(getStride)
253 MOCK_SYMBOL_ACCESSOR(getSubTypeId)
254 MOCK_SYMBOL_ACCESSOR(getSymbolsFileName)
255 MOCK_SYMBOL_ACCESSOR(getSymIndexId)
256 MOCK_SYMBOL_ACCESSOR(getTargetOffset)
257 MOCK_SYMBOL_ACCESSOR(getTargetRelativeVirtualAddress)
258 MOCK_SYMBOL_ACCESSOR(getTargetVirtualAddress)
259 MOCK_SYMBOL_ACCESSOR(getTargetSection)
260 MOCK_SYMBOL_ACCESSOR(getTextureSlot)
261 MOCK_SYMBOL_ACCESSOR(getTimeStamp)
262 MOCK_SYMBOL_ACCESSOR(getToken)
263 MOCK_SYMBOL_ACCESSOR(getTypeId)
264 MOCK_SYMBOL_ACCESSOR(getUavSlot)
265 MOCK_SYMBOL_ACCESSOR(getUndecoratedName)
266 MOCK_SYMBOL_ACCESSOR(getUnmodifiedTypeId)
267 MOCK_SYMBOL_ACCESSOR(getUpperBoundId)
268 MOCK_SYMBOL_ACCESSOR(getVirtualBaseDispIndex)
269 MOCK_SYMBOL_ACCESSOR(getVirtualBaseOffset)
270 MOCK_SYMBOL_ACCESSOR(getVirtualTableShapeId)
271 MOCK_SYMBOL_ACCESSOR(getDataKind)
272 MOCK_SYMBOL_ACCESSOR(getGuid)
273 MOCK_SYMBOL_ACCESSOR(getOffset)
274 MOCK_SYMBOL_ACCESSOR(getThisAdjust)
275 MOCK_SYMBOL_ACCESSOR(getVirtualBasePointerOffset)
276 MOCK_SYMBOL_ACCESSOR(getLocationType)
277 MOCK_SYMBOL_ACCESSOR(getMachineType)
278 MOCK_SYMBOL_ACCESSOR(getThunkOrdinal)
279 MOCK_SYMBOL_ACCESSOR(getLength)
Zachary Turnerc883a8c2017-04-12 23:18:21 +0000280 MOCK_SYMBOL_ACCESSOR(getVirtualBaseTableType)
Zachary Turner94269a42015-02-07 01:47:14 +0000281 MOCK_SYMBOL_ACCESSOR(getLiveRangeLength)
282 MOCK_SYMBOL_ACCESSOR(getVirtualAddress)
283 MOCK_SYMBOL_ACCESSOR(getUdtKind)
284 MOCK_SYMBOL_ACCESSOR(hasConstructor)
285 MOCK_SYMBOL_ACCESSOR(hasCustomCallingConvention)
286 MOCK_SYMBOL_ACCESSOR(hasFarReturn)
287 MOCK_SYMBOL_ACCESSOR(isCode)
288 MOCK_SYMBOL_ACCESSOR(isCompilerGenerated)
289 MOCK_SYMBOL_ACCESSOR(isConstType)
290 MOCK_SYMBOL_ACCESSOR(isEditAndContinueEnabled)
291 MOCK_SYMBOL_ACCESSOR(isFunction)
292 MOCK_SYMBOL_ACCESSOR(getAddressTaken)
293 MOCK_SYMBOL_ACCESSOR(getNoStackOrdering)
294 MOCK_SYMBOL_ACCESSOR(hasAlloca)
295 MOCK_SYMBOL_ACCESSOR(hasAssignmentOperator)
296 MOCK_SYMBOL_ACCESSOR(hasCTypes)
297 MOCK_SYMBOL_ACCESSOR(hasCastOperator)
298 MOCK_SYMBOL_ACCESSOR(hasDebugInfo)
299 MOCK_SYMBOL_ACCESSOR(hasEH)
300 MOCK_SYMBOL_ACCESSOR(hasEHa)
Zachary Turnera5549172015-02-10 22:43:25 +0000301 MOCK_SYMBOL_ACCESSOR(hasFramePointer)
Zachary Turner94269a42015-02-07 01:47:14 +0000302 MOCK_SYMBOL_ACCESSOR(hasInlAsm)
303 MOCK_SYMBOL_ACCESSOR(hasInlineAttribute)
304 MOCK_SYMBOL_ACCESSOR(hasInterruptReturn)
305 MOCK_SYMBOL_ACCESSOR(hasLongJump)
306 MOCK_SYMBOL_ACCESSOR(hasManagedCode)
307 MOCK_SYMBOL_ACCESSOR(hasNestedTypes)
308 MOCK_SYMBOL_ACCESSOR(hasNoInlineAttribute)
309 MOCK_SYMBOL_ACCESSOR(hasNoReturnAttribute)
310 MOCK_SYMBOL_ACCESSOR(hasOptimizedCodeDebugInfo)
311 MOCK_SYMBOL_ACCESSOR(hasOverloadedOperator)
312 MOCK_SYMBOL_ACCESSOR(hasSEH)
313 MOCK_SYMBOL_ACCESSOR(hasSecurityChecks)
314 MOCK_SYMBOL_ACCESSOR(hasSetJump)
315 MOCK_SYMBOL_ACCESSOR(hasStrictGSCheck)
316 MOCK_SYMBOL_ACCESSOR(isAcceleratorGroupSharedLocal)
317 MOCK_SYMBOL_ACCESSOR(isAcceleratorPointerTagLiveRange)
318 MOCK_SYMBOL_ACCESSOR(isAcceleratorStubFunction)
319 MOCK_SYMBOL_ACCESSOR(isAggregated)
320 MOCK_SYMBOL_ACCESSOR(isIntroVirtualFunction)
321 MOCK_SYMBOL_ACCESSOR(isCVTCIL)
322 MOCK_SYMBOL_ACCESSOR(isConstructorVirtualBase)
323 MOCK_SYMBOL_ACCESSOR(isCxxReturnUdt)
324 MOCK_SYMBOL_ACCESSOR(isDataAligned)
325 MOCK_SYMBOL_ACCESSOR(isHLSLData)
326 MOCK_SYMBOL_ACCESSOR(isHotpatchable)
327 MOCK_SYMBOL_ACCESSOR(isIndirectVirtualBaseClass)
328 MOCK_SYMBOL_ACCESSOR(isInterfaceUdt)
329 MOCK_SYMBOL_ACCESSOR(isIntrinsic)
330 MOCK_SYMBOL_ACCESSOR(isLTCG)
331 MOCK_SYMBOL_ACCESSOR(isLocationControlFlowDependent)
332 MOCK_SYMBOL_ACCESSOR(isMSILNetmodule)
333 MOCK_SYMBOL_ACCESSOR(isMatrixRowMajor)
334 MOCK_SYMBOL_ACCESSOR(isManagedCode)
335 MOCK_SYMBOL_ACCESSOR(isMSILCode)
336 MOCK_SYMBOL_ACCESSOR(isMultipleInheritance)
337 MOCK_SYMBOL_ACCESSOR(isNaked)
338 MOCK_SYMBOL_ACCESSOR(isNested)
339 MOCK_SYMBOL_ACCESSOR(isOptimizedAway)
340 MOCK_SYMBOL_ACCESSOR(isPacked)
341 MOCK_SYMBOL_ACCESSOR(isPointerBasedOnSymbolValue)
342 MOCK_SYMBOL_ACCESSOR(isPointerToDataMember)
343 MOCK_SYMBOL_ACCESSOR(isPointerToMemberFunction)
344 MOCK_SYMBOL_ACCESSOR(isPureVirtual)
345 MOCK_SYMBOL_ACCESSOR(isRValueReference)
346 MOCK_SYMBOL_ACCESSOR(isRefUdt)
347 MOCK_SYMBOL_ACCESSOR(isReference)
348 MOCK_SYMBOL_ACCESSOR(isRestrictedType)
349 MOCK_SYMBOL_ACCESSOR(isReturnValue)
350 MOCK_SYMBOL_ACCESSOR(isSafeBuffers)
351 MOCK_SYMBOL_ACCESSOR(isScoped)
352 MOCK_SYMBOL_ACCESSOR(isSdl)
353 MOCK_SYMBOL_ACCESSOR(isSingleInheritance)
354 MOCK_SYMBOL_ACCESSOR(isSplitted)
355 MOCK_SYMBOL_ACCESSOR(isStatic)
356 MOCK_SYMBOL_ACCESSOR(hasPrivateSymbols)
357 MOCK_SYMBOL_ACCESSOR(isUnalignedType)
358 MOCK_SYMBOL_ACCESSOR(isUnreached)
359 MOCK_SYMBOL_ACCESSOR(isValueUdt)
360 MOCK_SYMBOL_ACCESSOR(isVirtual)
361 MOCK_SYMBOL_ACCESSOR(isVirtualBaseClass)
362 MOCK_SYMBOL_ACCESSOR(isVirtualInheritance)
363 MOCK_SYMBOL_ACCESSOR(isVolatileType)
Zachary Turner00dbc752015-02-13 01:39:22 +0000364 MOCK_SYMBOL_ACCESSOR(getValue)
365 MOCK_SYMBOL_ACCESSOR(wasInlined)
366 MOCK_SYMBOL_ACCESSOR(getUnused)
Zachary Turner94269a42015-02-07 01:47:14 +0000367
368private:
369 PDB_SymType Type;
370};
371
372class PDBApiTest : public testing::Test {
373public:
374 std::unordered_map<PDB_SymType, std::unique_ptr<PDBSymbol>> SymbolMap;
375
376 void SetUp() override {
Zachary Turnerbae16b32015-02-08 20:58:09 +0000377 Session.reset(new MockSession());
378
Zachary Turner94269a42015-02-07 01:47:14 +0000379 InsertItemWithTag(PDB_SymType::None);
380 InsertItemWithTag(PDB_SymType::Exe);
381 InsertItemWithTag(PDB_SymType::Compiland);
382 InsertItemWithTag(PDB_SymType::CompilandDetails);
383 InsertItemWithTag(PDB_SymType::CompilandEnv);
384 InsertItemWithTag(PDB_SymType::Function);
385 InsertItemWithTag(PDB_SymType::Block);
386 InsertItemWithTag(PDB_SymType::Data);
387 InsertItemWithTag(PDB_SymType::Annotation);
388 InsertItemWithTag(PDB_SymType::Label);
389 InsertItemWithTag(PDB_SymType::PublicSymbol);
390 InsertItemWithTag(PDB_SymType::UDT);
391 InsertItemWithTag(PDB_SymType::Enum);
392 InsertItemWithTag(PDB_SymType::FunctionSig);
393 InsertItemWithTag(PDB_SymType::PointerType);
394 InsertItemWithTag(PDB_SymType::ArrayType);
395 InsertItemWithTag(PDB_SymType::BuiltinType);
396 InsertItemWithTag(PDB_SymType::Typedef);
397 InsertItemWithTag(PDB_SymType::BaseClass);
398 InsertItemWithTag(PDB_SymType::Friend);
399 InsertItemWithTag(PDB_SymType::FunctionArg);
400 InsertItemWithTag(PDB_SymType::FuncDebugStart);
401 InsertItemWithTag(PDB_SymType::FuncDebugEnd);
402 InsertItemWithTag(PDB_SymType::UsingNamespace);
403 InsertItemWithTag(PDB_SymType::VTableShape);
404 InsertItemWithTag(PDB_SymType::VTable);
405 InsertItemWithTag(PDB_SymType::Custom);
406 InsertItemWithTag(PDB_SymType::Thunk);
407 InsertItemWithTag(PDB_SymType::CustomType);
408 InsertItemWithTag(PDB_SymType::ManagedType);
409 InsertItemWithTag(PDB_SymType::Dimension);
410 InsertItemWithTag(PDB_SymType::Max);
411 }
412
Zachary Turner94269a42015-02-07 01:47:14 +0000413 template <class ExpectedType> void VerifyDyncast(PDB_SymType Tag) {
414 for (auto item = SymbolMap.begin(); item != SymbolMap.end(); ++item) {
415 EXPECT_EQ(item->first == Tag, llvm::isa<ExpectedType>(*item->second));
416 }
417 }
418
419 void VerifyUnknownDyncasts() {
420 for (auto item = SymbolMap.begin(); item != SymbolMap.end(); ++item) {
421 bool should_match = false;
422 if (item->first == PDB_SymType::None || item->first >= PDB_SymType::Max)
423 should_match = true;
424
425 EXPECT_EQ(should_match, llvm::isa<PDBSymbolUnknown>(*item->second));
426 }
427 }
Zachary Turnerbae16b32015-02-08 20:58:09 +0000428
429private:
430 std::unique_ptr<IPDBSession> Session;
431
432 void InsertItemWithTag(PDB_SymType Tag) {
Zachary Turnerf07ef222015-02-11 00:33:00 +0000433 auto RawSymbol = llvm::make_unique<MockRawSymbol>(Tag);
Zachary Turnerbae16b32015-02-08 20:58:09 +0000434 auto Symbol = PDBSymbol::create(*Session, std::move(RawSymbol));
435 SymbolMap.insert(std::make_pair(Tag, std::move(Symbol)));
436 }
Zachary Turner94269a42015-02-07 01:47:14 +0000437};
438
439TEST_F(PDBApiTest, Dyncast) {
440
441 // Most of the types have a one-to-one mapping between Tag and concrete type.
442 VerifyDyncast<PDBSymbolExe>(PDB_SymType::Exe);
443 VerifyDyncast<PDBSymbolCompiland>(PDB_SymType::Compiland);
444 VerifyDyncast<PDBSymbolCompilandDetails>(PDB_SymType::CompilandDetails);
445 VerifyDyncast<PDBSymbolCompilandEnv>(PDB_SymType::CompilandEnv);
446 VerifyDyncast<PDBSymbolFunc>(PDB_SymType::Function);
447 VerifyDyncast<PDBSymbolBlock>(PDB_SymType::Block);
448 VerifyDyncast<PDBSymbolData>(PDB_SymType::Data);
449 VerifyDyncast<PDBSymbolAnnotation>(PDB_SymType::Annotation);
450 VerifyDyncast<PDBSymbolLabel>(PDB_SymType::Label);
451 VerifyDyncast<PDBSymbolPublicSymbol>(PDB_SymType::PublicSymbol);
452 VerifyDyncast<PDBSymbolTypeUDT>(PDB_SymType::UDT);
453 VerifyDyncast<PDBSymbolTypeEnum>(PDB_SymType::Enum);
454 VerifyDyncast<PDBSymbolTypeFunctionSig>(PDB_SymType::FunctionSig);
455 VerifyDyncast<PDBSymbolTypePointer>(PDB_SymType::PointerType);
456 VerifyDyncast<PDBSymbolTypeArray>(PDB_SymType::ArrayType);
457 VerifyDyncast<PDBSymbolTypeBuiltin>(PDB_SymType::BuiltinType);
458 VerifyDyncast<PDBSymbolTypeTypedef>(PDB_SymType::Typedef);
459 VerifyDyncast<PDBSymbolTypeBaseClass>(PDB_SymType::BaseClass);
460 VerifyDyncast<PDBSymbolTypeFriend>(PDB_SymType::Friend);
461 VerifyDyncast<PDBSymbolTypeFunctionArg>(PDB_SymType::FunctionArg);
462 VerifyDyncast<PDBSymbolFuncDebugStart>(PDB_SymType::FuncDebugStart);
463 VerifyDyncast<PDBSymbolFuncDebugEnd>(PDB_SymType::FuncDebugEnd);
464 VerifyDyncast<PDBSymbolUsingNamespace>(PDB_SymType::UsingNamespace);
465 VerifyDyncast<PDBSymbolTypeVTableShape>(PDB_SymType::VTableShape);
466 VerifyDyncast<PDBSymbolTypeVTable>(PDB_SymType::VTable);
467 VerifyDyncast<PDBSymbolCustom>(PDB_SymType::Custom);
468 VerifyDyncast<PDBSymbolThunk>(PDB_SymType::Thunk);
469 VerifyDyncast<PDBSymbolTypeCustom>(PDB_SymType::CustomType);
470 VerifyDyncast<PDBSymbolTypeManaged>(PDB_SymType::ManagedType);
471 VerifyDyncast<PDBSymbolTypeDimension>(PDB_SymType::Dimension);
472
473 VerifyUnknownDyncasts();
474}
475
476} // end anonymous namespace