llvm.org GIT mirror llvm / d0898f1
Resubmit unittests for DebugInfoPDB. These were originally submitted as part of r228428, but this part caused a build breakage in LLVMConfig. The library portion was resubmitted independently since it was not causing breakage. There were two reasons this was causing the build to fail. The first is that there were no Makefiles added for the PDB tests. And the second is that the DebugInfoPDB library was only being built by CMake behind an "if (MSVC)" check. This is wrong since this the library hides platform specific details, and it was causing LLVM-Config to not find the library when trying to build unittests. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@228482 91177308-0d34-0410-b5e6-96231b3b80d8 Zachary Turner 4 years ago
10 changed file(s) with 468 addition(s) and 65 deletion(s). Raw diff Collapse all Expand all
0
11 add_subdirectory(DWARF)
2 if (MSVC)
3 add_subdirectory(PDB)
4 endif()
2 add_subdirectory(PDB)
3
None set(LLVM_LINK_COMPONENTS
1 DebugInfoDWARF
2 )
3
4 set(DebugInfoSources
5 DWARFFormValueTest.cpp
6 )
7
8 add_llvm_unittest(DebugInfoTests
9 ${DebugInfoSources}
10 )
1 add_subdirectory(DWARF)
2 add_subdirectory(PDB)
0 set(LLVM_LINK_COMPONENTS
1 DebugInfoDWARF
2 )
3
4 set(DebugInfoSources
5 DWARFFormValueTest.cpp
6 )
7
8 add_llvm_unittest(DebugInfoDWARFTests
9 ${DebugInfoSources}
10 )
0 //===- llvm/unittest/DebugInfo/DWARFFormValueTest.cpp ---------------------===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #include "llvm/DebugInfo/DWARF/DWARFFormValue.h"
10 #include "llvm/Support/Dwarf.h"
11 #include "gtest/gtest.h"
12 using namespace llvm;
13 using namespace dwarf;
14
15 namespace {
16
17 TEST(DWARFFormValue, FixedFormSizes) {
18 // Size of DW_FORM_addr and DW_FORM_ref_addr are equal in DWARF2,
19 // DW_FORM_ref_addr is always 4 bytes in DWARF32 starting from DWARF3.
20 ArrayRef sizes = DWARFFormValue::getFixedFormSizes(4, 2);
21 EXPECT_EQ(sizes[DW_FORM_addr], sizes[DW_FORM_ref_addr]);
22 sizes = DWARFFormValue::getFixedFormSizes(8, 2);
23 EXPECT_EQ(sizes[DW_FORM_addr], sizes[DW_FORM_ref_addr]);
24 sizes = DWARFFormValue::getFixedFormSizes(8, 3);
25 EXPECT_EQ(4, sizes[DW_FORM_ref_addr]);
26 // Check that we don't have fixed form sizes for weird address sizes.
27 EXPECT_EQ(0U, DWARFFormValue::getFixedFormSizes(16, 2).size());
28 }
29
30 bool isFormClass(uint16_t Form, DWARFFormValue::FormClass FC) {
31 return DWARFFormValue(Form).isFormClass(FC);
32 }
33
34 TEST(DWARFFormValue, FormClass) {
35 EXPECT_TRUE(isFormClass(DW_FORM_addr, DWARFFormValue::FC_Address));
36 EXPECT_FALSE(isFormClass(DW_FORM_data8, DWARFFormValue::FC_Address));
37 EXPECT_TRUE(isFormClass(DW_FORM_data8, DWARFFormValue::FC_Constant));
38 EXPECT_TRUE(isFormClass(DW_FORM_data8, DWARFFormValue::FC_SectionOffset));
39 EXPECT_TRUE(
40 isFormClass(DW_FORM_sec_offset, DWARFFormValue::FC_SectionOffset));
41 EXPECT_TRUE(isFormClass(DW_FORM_GNU_str_index, DWARFFormValue::FC_String));
42 EXPECT_TRUE(isFormClass(DW_FORM_GNU_addr_index, DWARFFormValue::FC_Address));
43 EXPECT_FALSE(isFormClass(DW_FORM_ref_addr, DWARFFormValue::FC_Address));
44 EXPECT_TRUE(isFormClass(DW_FORM_ref_addr, DWARFFormValue::FC_Reference));
45 EXPECT_TRUE(isFormClass(DW_FORM_ref_sig8, DWARFFormValue::FC_Reference));
46 }
47
48 } // end anonymous namespace
0 ##===- unittests/DebugInfo/Makefile ------------------------*- Makefile -*-===##
1 #
2 # The LLVM Compiler Infrastructure
3 #
4 # This file is distributed under the University of Illinois Open Source
5 # License. See LICENSE.TXT for details.
6 #
7 ##===----------------------------------------------------------------------===##
8
9 LEVEL = ../../..
10 TESTNAME = DebugInfoDWARF
11 LINK_COMPONENTS := DebugInfoDWARF object support
12
13 include $(LEVEL)/Makefile.config
14
15 include $(LLVM_SRC_ROOT)/unittests/Makefile.unittest
+0
-49
unittests/DebugInfo/DWARFFormValueTest.cpp less more
None //===- llvm/unittest/DebugInfo/DWARFFormValueTest.cpp ---------------------===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #include "llvm/DebugInfo/DWARF/DWARFFormValue.h"
10 #include "llvm/Support/Dwarf.h"
11 #include "gtest/gtest.h"
12 using namespace llvm;
13 using namespace dwarf;
14
15 namespace {
16
17 TEST(DWARFFormValue, FixedFormSizes) {
18 // Size of DW_FORM_addr and DW_FORM_ref_addr are equal in DWARF2,
19 // DW_FORM_ref_addr is always 4 bytes in DWARF32 starting from DWARF3.
20 ArrayRef sizes = DWARFFormValue::getFixedFormSizes(4, 2);
21 EXPECT_EQ(sizes[DW_FORM_addr], sizes[DW_FORM_ref_addr]);
22 sizes = DWARFFormValue::getFixedFormSizes(8, 2);
23 EXPECT_EQ(sizes[DW_FORM_addr], sizes[DW_FORM_ref_addr]);
24 sizes = DWARFFormValue::getFixedFormSizes(8, 3);
25 EXPECT_EQ(4, sizes[DW_FORM_ref_addr]);
26 // Check that we don't have fixed form sizes for weird address sizes.
27 EXPECT_EQ(0U, DWARFFormValue::getFixedFormSizes(16, 2).size());
28 }
29
30 bool isFormClass(uint16_t Form, DWARFFormValue::FormClass FC) {
31 return DWARFFormValue(Form).isFormClass(FC);
32 }
33
34 TEST(DWARFFormValue, FormClass) {
35 EXPECT_TRUE(isFormClass(DW_FORM_addr, DWARFFormValue::FC_Address));
36 EXPECT_FALSE(isFormClass(DW_FORM_data8, DWARFFormValue::FC_Address));
37 EXPECT_TRUE(isFormClass(DW_FORM_data8, DWARFFormValue::FC_Constant));
38 EXPECT_TRUE(isFormClass(DW_FORM_data8, DWARFFormValue::FC_SectionOffset));
39 EXPECT_TRUE(
40 isFormClass(DW_FORM_sec_offset, DWARFFormValue::FC_SectionOffset));
41 EXPECT_TRUE(isFormClass(DW_FORM_GNU_str_index, DWARFFormValue::FC_String));
42 EXPECT_TRUE(isFormClass(DW_FORM_GNU_addr_index, DWARFFormValue::FC_Address));
43 EXPECT_FALSE(isFormClass(DW_FORM_ref_addr, DWARFFormValue::FC_Address));
44 EXPECT_TRUE(isFormClass(DW_FORM_ref_addr, DWARFFormValue::FC_Reference));
45 EXPECT_TRUE(isFormClass(DW_FORM_ref_sig8, DWARFFormValue::FC_Reference));
46 }
47
48 } // end anonymous namespace
55 # License. See LICENSE.TXT for details.
66 #
77 ##===----------------------------------------------------------------------===##
8
98 LEVEL = ../..
10 TESTNAME = DebugInfo
11 LINK_COMPONENTS := DebugInfoDWARF object support
129
1310 include $(LEVEL)/Makefile.config
1411
12 PARALLEL_DIRS := DWARF PDB
13
1514 include $(LLVM_SRC_ROOT)/unittests/Makefile.unittest
0 set(LLVM_LINK_COMPONENTS
1 DebugInfoPDB
2 )
3
4 set(DebugInfoPDBSources
5 PDBApiTest.cpp
6 )
7
8 add_llvm_unittest(DebugInfoPDBTests
9 ${DebugInfoPDBSources}
10 )
0 ##===- unittests/DebugInfo/PDB/Makefile -------------------*- Makefile -*-===##
1 #
2 # The LLVM Compiler Infrastructure
3 #
4 # This file is distributed under the University of Illinois Open Source
5 # License. See LICENSE.TXT for details.
6 #
7 ##===----------------------------------------------------------------------===##
8
9 LEVEL = ../../..
10 TESTNAME = DebugInfoPDB
11 LINK_COMPONENTS := DebugInfoPDB support
12
13 include $(LEVEL)/Makefile.config
14
15 include $(LLVM_SRC_ROOT)/unittests/Makefile.unittest
0 //===- llvm/unittest/DebugInfo/PDB/PDBApiTest.cpp -------------------------===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #include
10
11 #include "llvm/DebugInfo/PDB/IPDBEnumChildren.h"
12 #include "llvm/DebugInfo/PDB/IPDBRawSymbol.h"
13 #include "llvm/DebugInfo/PDB/PDBSymbol.h"
14 #include "llvm/DebugInfo/PDB/PDBSymbolAnnotation.h"
15 #include "llvm/DebugInfo/PDB/PDBSymbolBlock.h"
16 #include "llvm/DebugInfo/PDB/PDBSymbolCompiland.h"
17 #include "llvm/DebugInfo/PDB/PDBSymbolCompilandDetails.h"
18 #include "llvm/DebugInfo/PDB/PDBSymbolCompilandEnv.h"
19 #include "llvm/DebugInfo/PDB/PDBSymbolCustom.h"
20 #include "llvm/DebugInfo/PDB/PDBSymbolData.h"
21 #include "llvm/DebugInfo/PDB/PDBSymbolExe.h"
22 #include "llvm/DebugInfo/PDB/PDBSymbolFunc.h"
23 #include "llvm/DebugInfo/PDB/PDBSymbolFuncDebugEnd.h"
24 #include "llvm/DebugInfo/PDB/PDBSymbolFuncDebugStart.h"
25 #include "llvm/DebugInfo/PDB/PDBSymbolLabel.h"
26 #include "llvm/DebugInfo/PDB/PDBSymbolPublicSymbol.h"
27 #include "llvm/DebugInfo/PDB/PDBSymbolThunk.h"
28 #include "llvm/DebugInfo/PDB/PDBSymbolTypeArray.h"
29 #include "llvm/DebugInfo/PDB/PDBSymbolTypeBaseClass.h"
30 #include "llvm/DebugInfo/PDB/PDBSymbolTypeBuiltin.h"
31 #include "llvm/DebugInfo/PDB/PDBSymbolTypeCustom.h"
32 #include "llvm/DebugInfo/PDB/PDBSymbolTypeDimension.h"
33 #include "llvm/DebugInfo/PDB/PDBSymbolTypeEnum.h"
34 #include "llvm/DebugInfo/PDB/PDBSymbolTypeFriend.h"
35 #include "llvm/DebugInfo/PDB/PDBSymbolTypeFunctionArg.h"
36 #include "llvm/DebugInfo/PDB/PDBSymbolTypeFunctionSig.h"
37 #include "llvm/DebugInfo/PDB/PDBSymbolTypeManaged.h"
38 #include "llvm/DebugInfo/PDB/PDBSymbolTypePointer.h"
39 #include "llvm/DebugInfo/PDB/PDBSymbolTypeTypedef.h"
40 #include "llvm/DebugInfo/PDB/PDBSymbolTypeUDT.h"
41 #include "llvm/DebugInfo/PDB/PDBSymbolTypeVTable.h"
42 #include "llvm/DebugInfo/PDB/PDBSymbolTypeVTableShape.h"
43 #include "llvm/DebugInfo/PDB/PDBSymbolUnknown.h"
44 #include "llvm/DebugInfo/PDB/PDBSymbolUsingNamespace.h"
45 #include "llvm/DebugInfo/PDB/PDBTypes.h"
46 #include "gtest/gtest.h"
47 using namespace llvm;
48
49 namespace std {
50 template<>
51 struct hash {
52 public:
53 std::size_t operator()(PDB_SymType Symbol) const {
54 return std::hash()(static_cast(Symbol));
55 }
56 };
57 }
58
59 namespace {
60
61 #define MOCK_SYMBOL_ACCESSOR(Func) \
62 auto Func() const->decltype(((IPDBRawSymbol *)nullptr)->Func()) override { \
63 typedef decltype(IPDBRawSymbol::Func()) ReturnType; \
64 return ReturnType(); \
65 }
66
67 class MockRawSymbol : public IPDBRawSymbol {
68 public:
69 MockRawSymbol(PDB_SymType SymType) : Type(SymType) {}
70
71 virtual void dump(llvm::raw_ostream &OS) const {}
72
73 virtual std::unique_ptr
74 findChildren(PDB_SymType Type, StringRef Name,
75 PDB_NameSearchFlags Flags) const {
76 return nullptr;
77 }
78 virtual std::unique_ptr
79 findChildrenByRVA(PDB_SymType Type, StringRef Name, PDB_NameSearchFlags Flags,
80 uint32_t RVA) const {
81 return nullptr;
82 }
83 virtual std::unique_ptr
84 findInlineFramesByRVA(uint32_t RVA) const {
85 return nullptr;
86 }
87
88 virtual void getDataBytes(llvm::SmallVector &bytes) const {}
89
90 PDB_SymType getSymTag() const override { return Type; }
91
92 MOCK_SYMBOL_ACCESSOR(getAccess)
93 MOCK_SYMBOL_ACCESSOR(getAddressOffset)
94 MOCK_SYMBOL_ACCESSOR(getAddressSection)
95 MOCK_SYMBOL_ACCESSOR(getAge)
96 MOCK_SYMBOL_ACCESSOR(getArrayIndexTypeId)
97 MOCK_SYMBOL_ACCESSOR(getBackEndBuild)
98 MOCK_SYMBOL_ACCESSOR(getBackEndMajor)
99 MOCK_SYMBOL_ACCESSOR(getBackEndMinor)
100 MOCK_SYMBOL_ACCESSOR(getBaseDataOffset)
101 MOCK_SYMBOL_ACCESSOR(getBaseDataSlot)
102 MOCK_SYMBOL_ACCESSOR(getBaseSymbolId)
103 MOCK_SYMBOL_ACCESSOR(getBuiltinType)
104 MOCK_SYMBOL_ACCESSOR(getBitPosition)
105 MOCK_SYMBOL_ACCESSOR(getCallingConvention)
106 MOCK_SYMBOL_ACCESSOR(getClassParentId)
107 MOCK_SYMBOL_ACCESSOR(getCompilerName)
108 MOCK_SYMBOL_ACCESSOR(getCount)
109 MOCK_SYMBOL_ACCESSOR(getCountLiveRanges)
110 MOCK_SYMBOL_ACCESSOR(getFrontEndBuild)
111 MOCK_SYMBOL_ACCESSOR(getFrontEndMajor)
112 MOCK_SYMBOL_ACCESSOR(getFrontEndMinor)
113 MOCK_SYMBOL_ACCESSOR(getLanguage)
114 MOCK_SYMBOL_ACCESSOR(getLexicalParentId)
115 MOCK_SYMBOL_ACCESSOR(getLibraryName)
116 MOCK_SYMBOL_ACCESSOR(getLiveRangeStartAddressOffset)
117 MOCK_SYMBOL_ACCESSOR(getLiveRangeStartAddressSection)
118 MOCK_SYMBOL_ACCESSOR(getLiveRangeStartRelativeVirtualAddress)
119 MOCK_SYMBOL_ACCESSOR(getLocalBasePointerRegisterId)
120 MOCK_SYMBOL_ACCESSOR(getLowerBoundId)
121 MOCK_SYMBOL_ACCESSOR(getMemorySpaceKind)
122 MOCK_SYMBOL_ACCESSOR(getName)
123 MOCK_SYMBOL_ACCESSOR(getNumberOfAcceleratorPointerTags)
124 MOCK_SYMBOL_ACCESSOR(getNumberOfColumns)
125 MOCK_SYMBOL_ACCESSOR(getNumberOfModifiers)
126 MOCK_SYMBOL_ACCESSOR(getNumberOfRegisterIndices)
127 MOCK_SYMBOL_ACCESSOR(getNumberOfRows)
128 MOCK_SYMBOL_ACCESSOR(getObjectFileName)
129 MOCK_SYMBOL_ACCESSOR(getOemId)
130 MOCK_SYMBOL_ACCESSOR(getOemSymbolId)
131 MOCK_SYMBOL_ACCESSOR(getOffsetInUdt)
132 MOCK_SYMBOL_ACCESSOR(getPlatform)
133 MOCK_SYMBOL_ACCESSOR(getRank)
134 MOCK_SYMBOL_ACCESSOR(getRegisterId)
135 MOCK_SYMBOL_ACCESSOR(getRegisterType)
136 MOCK_SYMBOL_ACCESSOR(getRelativeVirtualAddress)
137 MOCK_SYMBOL_ACCESSOR(getSamplerSlot)
138 MOCK_SYMBOL_ACCESSOR(getSignature)
139 MOCK_SYMBOL_ACCESSOR(getSizeInUdt)
140 MOCK_SYMBOL_ACCESSOR(getSlot)
141 MOCK_SYMBOL_ACCESSOR(getSourceFileName)
142 MOCK_SYMBOL_ACCESSOR(getStride)
143 MOCK_SYMBOL_ACCESSOR(getSubTypeId)
144 MOCK_SYMBOL_ACCESSOR(getSymbolsFileName)
145 MOCK_SYMBOL_ACCESSOR(getSymIndexId)
146 MOCK_SYMBOL_ACCESSOR(getTargetOffset)
147 MOCK_SYMBOL_ACCESSOR(getTargetRelativeVirtualAddress)
148 MOCK_SYMBOL_ACCESSOR(getTargetVirtualAddress)
149 MOCK_SYMBOL_ACCESSOR(getTargetSection)
150 MOCK_SYMBOL_ACCESSOR(getTextureSlot)
151 MOCK_SYMBOL_ACCESSOR(getTimeStamp)
152 MOCK_SYMBOL_ACCESSOR(getToken)
153 MOCK_SYMBOL_ACCESSOR(getTypeId)
154 MOCK_SYMBOL_ACCESSOR(getUavSlot)
155 MOCK_SYMBOL_ACCESSOR(getUndecoratedName)
156 MOCK_SYMBOL_ACCESSOR(getUnmodifiedTypeId)
157 MOCK_SYMBOL_ACCESSOR(getUpperBoundId)
158 MOCK_SYMBOL_ACCESSOR(getVirtualBaseDispIndex)
159 MOCK_SYMBOL_ACCESSOR(getVirtualBaseOffset)
160 MOCK_SYMBOL_ACCESSOR(getVirtualTableShapeId)
161 MOCK_SYMBOL_ACCESSOR(getDataKind)
162 MOCK_SYMBOL_ACCESSOR(getGuid)
163 MOCK_SYMBOL_ACCESSOR(getOffset)
164 MOCK_SYMBOL_ACCESSOR(getThisAdjust)
165 MOCK_SYMBOL_ACCESSOR(getVirtualBasePointerOffset)
166 MOCK_SYMBOL_ACCESSOR(getLocationType)
167 MOCK_SYMBOL_ACCESSOR(getMachineType)
168 MOCK_SYMBOL_ACCESSOR(getThunkOrdinal)
169 MOCK_SYMBOL_ACCESSOR(getLength)
170 MOCK_SYMBOL_ACCESSOR(getLiveRangeLength)
171 MOCK_SYMBOL_ACCESSOR(getVirtualAddress)
172 MOCK_SYMBOL_ACCESSOR(getUdtKind)
173 MOCK_SYMBOL_ACCESSOR(hasConstructor)
174 MOCK_SYMBOL_ACCESSOR(hasCustomCallingConvention)
175 MOCK_SYMBOL_ACCESSOR(hasFarReturn)
176 MOCK_SYMBOL_ACCESSOR(isCode)
177 MOCK_SYMBOL_ACCESSOR(isCompilerGenerated)
178 MOCK_SYMBOL_ACCESSOR(isConstType)
179 MOCK_SYMBOL_ACCESSOR(isEditAndContinueEnabled)
180 MOCK_SYMBOL_ACCESSOR(isFunction)
181 MOCK_SYMBOL_ACCESSOR(getAddressTaken)
182 MOCK_SYMBOL_ACCESSOR(getNoStackOrdering)
183 MOCK_SYMBOL_ACCESSOR(hasAlloca)
184 MOCK_SYMBOL_ACCESSOR(hasAssignmentOperator)
185 MOCK_SYMBOL_ACCESSOR(hasCTypes)
186 MOCK_SYMBOL_ACCESSOR(hasCastOperator)
187 MOCK_SYMBOL_ACCESSOR(hasDebugInfo)
188 MOCK_SYMBOL_ACCESSOR(hasEH)
189 MOCK_SYMBOL_ACCESSOR(hasEHa)
190 MOCK_SYMBOL_ACCESSOR(hasInlAsm)
191 MOCK_SYMBOL_ACCESSOR(hasInlineAttribute)
192 MOCK_SYMBOL_ACCESSOR(hasInterruptReturn)
193 MOCK_SYMBOL_ACCESSOR(hasLongJump)
194 MOCK_SYMBOL_ACCESSOR(hasManagedCode)
195 MOCK_SYMBOL_ACCESSOR(hasNestedTypes)
196 MOCK_SYMBOL_ACCESSOR(hasNoInlineAttribute)
197 MOCK_SYMBOL_ACCESSOR(hasNoReturnAttribute)
198 MOCK_SYMBOL_ACCESSOR(hasOptimizedCodeDebugInfo)
199 MOCK_SYMBOL_ACCESSOR(hasOverloadedOperator)
200 MOCK_SYMBOL_ACCESSOR(hasSEH)
201 MOCK_SYMBOL_ACCESSOR(hasSecurityChecks)
202 MOCK_SYMBOL_ACCESSOR(hasSetJump)
203 MOCK_SYMBOL_ACCESSOR(hasStrictGSCheck)
204 MOCK_SYMBOL_ACCESSOR(isAcceleratorGroupSharedLocal)
205 MOCK_SYMBOL_ACCESSOR(isAcceleratorPointerTagLiveRange)
206 MOCK_SYMBOL_ACCESSOR(isAcceleratorStubFunction)
207 MOCK_SYMBOL_ACCESSOR(isAggregated)
208 MOCK_SYMBOL_ACCESSOR(isIntroVirtualFunction)
209 MOCK_SYMBOL_ACCESSOR(isCVTCIL)
210 MOCK_SYMBOL_ACCESSOR(isConstructorVirtualBase)
211 MOCK_SYMBOL_ACCESSOR(isCxxReturnUdt)
212 MOCK_SYMBOL_ACCESSOR(isDataAligned)
213 MOCK_SYMBOL_ACCESSOR(isHLSLData)
214 MOCK_SYMBOL_ACCESSOR(isHotpatchable)
215 MOCK_SYMBOL_ACCESSOR(isIndirectVirtualBaseClass)
216 MOCK_SYMBOL_ACCESSOR(isInterfaceUdt)
217 MOCK_SYMBOL_ACCESSOR(isIntrinsic)
218 MOCK_SYMBOL_ACCESSOR(isLTCG)
219 MOCK_SYMBOL_ACCESSOR(isLocationControlFlowDependent)
220 MOCK_SYMBOL_ACCESSOR(isMSILNetmodule)
221 MOCK_SYMBOL_ACCESSOR(isMatrixRowMajor)
222 MOCK_SYMBOL_ACCESSOR(isManagedCode)
223 MOCK_SYMBOL_ACCESSOR(isMSILCode)
224 MOCK_SYMBOL_ACCESSOR(isMultipleInheritance)
225 MOCK_SYMBOL_ACCESSOR(isNaked)
226 MOCK_SYMBOL_ACCESSOR(isNested)
227 MOCK_SYMBOL_ACCESSOR(isOptimizedAway)
228 MOCK_SYMBOL_ACCESSOR(isPacked)
229 MOCK_SYMBOL_ACCESSOR(isPointerBasedOnSymbolValue)
230 MOCK_SYMBOL_ACCESSOR(isPointerToDataMember)
231 MOCK_SYMBOL_ACCESSOR(isPointerToMemberFunction)
232 MOCK_SYMBOL_ACCESSOR(isPureVirtual)
233 MOCK_SYMBOL_ACCESSOR(isRValueReference)
234 MOCK_SYMBOL_ACCESSOR(isRefUdt)
235 MOCK_SYMBOL_ACCESSOR(isReference)
236 MOCK_SYMBOL_ACCESSOR(isRestrictedType)
237 MOCK_SYMBOL_ACCESSOR(isReturnValue)
238 MOCK_SYMBOL_ACCESSOR(isSafeBuffers)
239 MOCK_SYMBOL_ACCESSOR(isScoped)
240 MOCK_SYMBOL_ACCESSOR(isSdl)
241 MOCK_SYMBOL_ACCESSOR(isSingleInheritance)
242 MOCK_SYMBOL_ACCESSOR(isSplitted)
243 MOCK_SYMBOL_ACCESSOR(isStatic)
244 MOCK_SYMBOL_ACCESSOR(hasPrivateSymbols)
245 MOCK_SYMBOL_ACCESSOR(isUnalignedType)
246 MOCK_SYMBOL_ACCESSOR(isUnreached)
247 MOCK_SYMBOL_ACCESSOR(isValueUdt)
248 MOCK_SYMBOL_ACCESSOR(isVirtual)
249 MOCK_SYMBOL_ACCESSOR(isVirtualBaseClass)
250 MOCK_SYMBOL_ACCESSOR(isVirtualInheritance)
251 MOCK_SYMBOL_ACCESSOR(isVolatileType)
252
253 private:
254 PDB_SymType Type;
255 };
256
257 class PDBApiTest : public testing::Test {
258 public:
259 std::unordered_map> SymbolMap;
260
261 void SetUp() override {
262 InsertItemWithTag(PDB_SymType::None);
263 InsertItemWithTag(PDB_SymType::Exe);
264 InsertItemWithTag(PDB_SymType::Compiland);
265 InsertItemWithTag(PDB_SymType::CompilandDetails);
266 InsertItemWithTag(PDB_SymType::CompilandEnv);
267 InsertItemWithTag(PDB_SymType::Function);
268 InsertItemWithTag(PDB_SymType::Block);
269 InsertItemWithTag(PDB_SymType::Data);
270 InsertItemWithTag(PDB_SymType::Annotation);
271 InsertItemWithTag(PDB_SymType::Label);
272 InsertItemWithTag(PDB_SymType::PublicSymbol);
273 InsertItemWithTag(PDB_SymType::UDT);
274 InsertItemWithTag(PDB_SymType::Enum);
275 InsertItemWithTag(PDB_SymType::FunctionSig);
276 InsertItemWithTag(PDB_SymType::PointerType);
277 InsertItemWithTag(PDB_SymType::ArrayType);
278 InsertItemWithTag(PDB_SymType::BuiltinType);
279 InsertItemWithTag(PDB_SymType::Typedef);
280 InsertItemWithTag(PDB_SymType::BaseClass);
281 InsertItemWithTag(PDB_SymType::Friend);
282 InsertItemWithTag(PDB_SymType::FunctionArg);
283 InsertItemWithTag(PDB_SymType::FuncDebugStart);
284 InsertItemWithTag(PDB_SymType::FuncDebugEnd);
285 InsertItemWithTag(PDB_SymType::UsingNamespace);
286 InsertItemWithTag(PDB_SymType::VTableShape);
287 InsertItemWithTag(PDB_SymType::VTable);
288 InsertItemWithTag(PDB_SymType::Custom);
289 InsertItemWithTag(PDB_SymType::Thunk);
290 InsertItemWithTag(PDB_SymType::CustomType);
291 InsertItemWithTag(PDB_SymType::ManagedType);
292 InsertItemWithTag(PDB_SymType::Dimension);
293 InsertItemWithTag(PDB_SymType::Max);
294 }
295
296 private:
297 void InsertItemWithTag(PDB_SymType Tag) {
298 auto RawSymbol = std::unique_ptr(new MockRawSymbol(Tag));
299 auto Symbol = PDBSymbol::create(std::move(RawSymbol));
300 SymbolMap.insert(std::make_pair(Tag, std::move(Symbol)));
301 }
302
303 public:
304 template void VerifyDyncast(PDB_SymType Tag) {
305 for (auto item = SymbolMap.begin(); item != SymbolMap.end(); ++item) {
306 EXPECT_EQ(item->first == Tag, llvm::isa(*item->second));
307 }
308 }
309
310 void VerifyUnknownDyncasts() {
311 for (auto item = SymbolMap.begin(); item != SymbolMap.end(); ++item) {
312 bool should_match = false;
313 if (item->first == PDB_SymType::None || item->first >= PDB_SymType::Max)
314 should_match = true;
315
316 EXPECT_EQ(should_match, llvm::isa(*item->second));
317 }
318 }
319 };
320
321 TEST_F(PDBApiTest, Dyncast) {
322
323 // Most of the types have a one-to-one mapping between Tag and concrete type.
324 VerifyDyncast(PDB_SymType::Exe);
325 VerifyDyncast(PDB_SymType::Compiland);
326 VerifyDyncast(PDB_SymType::CompilandDetails);
327 VerifyDyncast(PDB_SymType::CompilandEnv);
328 VerifyDyncast(PDB_SymType::Function);
329 VerifyDyncast(PDB_SymType::Block);
330 VerifyDyncast(PDB_SymType::Data);
331 VerifyDyncast(PDB_SymType::Annotation);
332 VerifyDyncast(PDB_SymType::Label);
333 VerifyDyncast(PDB_SymType::PublicSymbol);
334 VerifyDyncast(PDB_SymType::UDT);
335 VerifyDyncast(PDB_SymType::Enum);
336 VerifyDyncast(PDB_SymType::FunctionSig);
337 VerifyDyncast(PDB_SymType::PointerType);
338 VerifyDyncast(PDB_SymType::ArrayType);
339 VerifyDyncast(PDB_SymType::BuiltinType);
340 VerifyDyncast(PDB_SymType::Typedef);
341 VerifyDyncast(PDB_SymType::BaseClass);
342 VerifyDyncast(PDB_SymType::Friend);
343 VerifyDyncast(PDB_SymType::FunctionArg);
344 VerifyDyncast(PDB_SymType::FuncDebugStart);
345 VerifyDyncast(PDB_SymType::FuncDebugEnd);
346 VerifyDyncast(PDB_SymType::UsingNamespace);
347 VerifyDyncast(PDB_SymType::VTableShape);
348 VerifyDyncast(PDB_SymType::VTable);
349 VerifyDyncast(PDB_SymType::Custom);
350 VerifyDyncast(PDB_SymType::Thunk);
351 VerifyDyncast(PDB_SymType::CustomType);
352 VerifyDyncast(PDB_SymType::ManagedType);
353 VerifyDyncast(PDB_SymType::Dimension);
354
355 VerifyUnknownDyncasts();
356 }
357
358 } // end anonymous namespace