Zachary Turner | 94269a4 | 2015-02-07 01:47:14 +0000 | [diff] [blame] | 1 | //===- 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 Turner | be6d1e4 | 2015-02-10 23:46:48 +0000 | [diff] [blame] | 12 | #include "llvm/ADT/STLExtras.h" |
Zachary Turner | 94269a4 | 2015-02-07 01:47:14 +0000 | [diff] [blame] | 13 | #include "llvm/DebugInfo/PDB/IPDBEnumChildren.h" |
| 14 | #include "llvm/DebugInfo/PDB/IPDBRawSymbol.h" |
Zachary Turner | bae16b3 | 2015-02-08 20:58:09 +0000 | [diff] [blame] | 15 | #include "llvm/DebugInfo/PDB/IPDBSession.h" |
| 16 | #include "llvm/DebugInfo/PDB/IPDBSourceFile.h" |
| 17 | |
Zachary Turner | 94269a4 | 2015-02-07 01:47:14 +0000 | [diff] [blame] | 18 | #include "llvm/DebugInfo/PDB/PDBSymbol.h" |
| 19 | #include "llvm/DebugInfo/PDB/PDBSymbolAnnotation.h" |
| 20 | #include "llvm/DebugInfo/PDB/PDBSymbolBlock.h" |
| 21 | #include "llvm/DebugInfo/PDB/PDBSymbolCompiland.h" |
| 22 | #include "llvm/DebugInfo/PDB/PDBSymbolCompilandDetails.h" |
| 23 | #include "llvm/DebugInfo/PDB/PDBSymbolCompilandEnv.h" |
| 24 | #include "llvm/DebugInfo/PDB/PDBSymbolCustom.h" |
| 25 | #include "llvm/DebugInfo/PDB/PDBSymbolData.h" |
| 26 | #include "llvm/DebugInfo/PDB/PDBSymbolExe.h" |
| 27 | #include "llvm/DebugInfo/PDB/PDBSymbolFunc.h" |
| 28 | #include "llvm/DebugInfo/PDB/PDBSymbolFuncDebugEnd.h" |
| 29 | #include "llvm/DebugInfo/PDB/PDBSymbolFuncDebugStart.h" |
| 30 | #include "llvm/DebugInfo/PDB/PDBSymbolLabel.h" |
| 31 | #include "llvm/DebugInfo/PDB/PDBSymbolPublicSymbol.h" |
| 32 | #include "llvm/DebugInfo/PDB/PDBSymbolThunk.h" |
| 33 | #include "llvm/DebugInfo/PDB/PDBSymbolTypeArray.h" |
| 34 | #include "llvm/DebugInfo/PDB/PDBSymbolTypeBaseClass.h" |
| 35 | #include "llvm/DebugInfo/PDB/PDBSymbolTypeBuiltin.h" |
| 36 | #include "llvm/DebugInfo/PDB/PDBSymbolTypeCustom.h" |
| 37 | #include "llvm/DebugInfo/PDB/PDBSymbolTypeDimension.h" |
| 38 | #include "llvm/DebugInfo/PDB/PDBSymbolTypeEnum.h" |
| 39 | #include "llvm/DebugInfo/PDB/PDBSymbolTypeFriend.h" |
| 40 | #include "llvm/DebugInfo/PDB/PDBSymbolTypeFunctionArg.h" |
| 41 | #include "llvm/DebugInfo/PDB/PDBSymbolTypeFunctionSig.h" |
| 42 | #include "llvm/DebugInfo/PDB/PDBSymbolTypeManaged.h" |
| 43 | #include "llvm/DebugInfo/PDB/PDBSymbolTypePointer.h" |
| 44 | #include "llvm/DebugInfo/PDB/PDBSymbolTypeTypedef.h" |
| 45 | #include "llvm/DebugInfo/PDB/PDBSymbolTypeUDT.h" |
| 46 | #include "llvm/DebugInfo/PDB/PDBSymbolTypeVTable.h" |
| 47 | #include "llvm/DebugInfo/PDB/PDBSymbolTypeVTableShape.h" |
| 48 | #include "llvm/DebugInfo/PDB/PDBSymbolUnknown.h" |
| 49 | #include "llvm/DebugInfo/PDB/PDBSymbolUsingNamespace.h" |
| 50 | #include "llvm/DebugInfo/PDB/PDBTypes.h" |
| 51 | #include "gtest/gtest.h" |
| 52 | using namespace llvm; |
| 53 | |
Zachary Turner | 94269a4 | 2015-02-07 01:47:14 +0000 | [diff] [blame] | 54 | namespace { |
| 55 | |
| 56 | #define MOCK_SYMBOL_ACCESSOR(Func) \ |
Zachary Turner | 635c2c4 | 2015-02-07 02:02:23 +0000 | [diff] [blame] | 57 | decltype(std::declval<IPDBRawSymbol>().Func()) Func() const override { \ |
Zachary Turner | 94269a4 | 2015-02-07 01:47:14 +0000 | [diff] [blame] | 58 | typedef decltype(IPDBRawSymbol::Func()) ReturnType; \ |
| 59 | return ReturnType(); \ |
| 60 | } |
| 61 | |
Zachary Turner | bae16b3 | 2015-02-08 20:58:09 +0000 | [diff] [blame] | 62 | class MockSession : public IPDBSession { |
| 63 | uint64_t getLoadAddress() const override { return 0; } |
| 64 | void setLoadAddress(uint64_t Address) override {} |
| 65 | std::unique_ptr<PDBSymbolExe> getGlobalScope() const override { |
| 66 | return nullptr; |
| 67 | } |
Zachary Turner | 0ca2bde | 2015-02-10 21:40:29 +0000 | [diff] [blame] | 68 | std::unique_ptr<PDBSymbol> getSymbolById(uint32_t SymbolId) const override { |
| 69 | return nullptr; |
| 70 | } |
| 71 | std::unique_ptr<IPDBSourceFile> |
| 72 | getSourceFileById(uint32_t SymbolId) const override { |
Zachary Turner | bae16b3 | 2015-02-08 20:58:09 +0000 | [diff] [blame] | 73 | return nullptr; |
| 74 | } |
Zachary Turner | 4b08354 | 2015-04-17 22:40:36 +0000 | [diff] [blame] | 75 | |
| 76 | std::unique_ptr<PDBSymbol> |
Zachary Turner | 292e92d | 2015-05-01 20:51:49 +0000 | [diff] [blame] | 77 | findSymbolByAddress(uint64_t Address, PDB_SymType Type) const override { |
Zachary Turner | 4b08354 | 2015-04-17 22:40:36 +0000 | [diff] [blame] | 78 | return nullptr; |
| 79 | } |
| 80 | std::unique_ptr<IPDBEnumLineNumbers> |
| 81 | findLineNumbersByAddress(uint64_t Address, uint32_t Length) const override { |
| 82 | return nullptr; |
| 83 | } |
| 84 | |
Zachary Turner | a554917 | 2015-02-10 22:43:25 +0000 | [diff] [blame] | 85 | std::unique_ptr<IPDBEnumSourceFiles> getAllSourceFiles() const override { |
| 86 | return nullptr; |
| 87 | } |
| 88 | std::unique_ptr<IPDBEnumSourceFiles> getSourceFilesForCompiland( |
| 89 | const PDBSymbolCompiland &Compiland) const override { |
Zachary Turner | bae16b3 | 2015-02-08 20:58:09 +0000 | [diff] [blame] | 90 | return nullptr; |
| 91 | } |
Zachary Turner | c9c9c34 | 2015-02-10 22:56:21 +0000 | [diff] [blame] | 92 | |
| 93 | std::unique_ptr<IPDBEnumDataStreams> getDebugStreams() const override { |
| 94 | return nullptr; |
| 95 | } |
Zachary Turner | bae16b3 | 2015-02-08 20:58:09 +0000 | [diff] [blame] | 96 | }; |
| 97 | |
Zachary Turner | 94269a4 | 2015-02-07 01:47:14 +0000 | [diff] [blame] | 98 | class MockRawSymbol : public IPDBRawSymbol { |
| 99 | public: |
Zachary Turner | f07ef22 | 2015-02-11 00:33:00 +0000 | [diff] [blame] | 100 | MockRawSymbol(PDB_SymType SymType) |
| 101 | : Type(SymType) {} |
Zachary Turner | 94269a4 | 2015-02-07 01:47:14 +0000 | [diff] [blame] | 102 | |
Zachary Turner | bc42da0 | 2015-02-23 05:59:14 +0000 | [diff] [blame] | 103 | void dump(raw_ostream &OS, int Indent) const override {} |
Zachary Turner | 94269a4 | 2015-02-07 01:47:14 +0000 | [diff] [blame] | 104 | |
Chandler Carruth | c94234c | 2015-02-07 08:12:22 +0000 | [diff] [blame] | 105 | std::unique_ptr<IPDBEnumSymbols> |
Zachary Turner | a554917 | 2015-02-10 22:43:25 +0000 | [diff] [blame] | 106 | findChildren(PDB_SymType Type) const override { |
| 107 | return nullptr; |
| 108 | } |
| 109 | std::unique_ptr<IPDBEnumSymbols> |
Zachary Turner | 94269a4 | 2015-02-07 01:47:14 +0000 | [diff] [blame] | 110 | findChildren(PDB_SymType Type, StringRef Name, |
Chandler Carruth | c94234c | 2015-02-07 08:12:22 +0000 | [diff] [blame] | 111 | PDB_NameSearchFlags Flags) const override { |
Zachary Turner | 94269a4 | 2015-02-07 01:47:14 +0000 | [diff] [blame] | 112 | return nullptr; |
| 113 | } |
Chandler Carruth | c94234c | 2015-02-07 08:12:22 +0000 | [diff] [blame] | 114 | std::unique_ptr<IPDBEnumSymbols> |
Zachary Turner | 94269a4 | 2015-02-07 01:47:14 +0000 | [diff] [blame] | 115 | findChildrenByRVA(PDB_SymType Type, StringRef Name, PDB_NameSearchFlags Flags, |
Chandler Carruth | c94234c | 2015-02-07 08:12:22 +0000 | [diff] [blame] | 116 | uint32_t RVA) const override { |
Zachary Turner | 94269a4 | 2015-02-07 01:47:14 +0000 | [diff] [blame] | 117 | return nullptr; |
| 118 | } |
Chandler Carruth | c94234c | 2015-02-07 08:12:22 +0000 | [diff] [blame] | 119 | std::unique_ptr<IPDBEnumSymbols> |
| 120 | findInlineFramesByRVA(uint32_t RVA) const override { |
Zachary Turner | 94269a4 | 2015-02-07 01:47:14 +0000 | [diff] [blame] | 121 | return nullptr; |
| 122 | } |
| 123 | |
Chandler Carruth | c94234c | 2015-02-07 08:12:22 +0000 | [diff] [blame] | 124 | void getDataBytes(llvm::SmallVector<uint8_t, 32> &bytes) const override {} |
Zachary Turner | 21473f7 | 2015-02-08 00:29:29 +0000 | [diff] [blame] | 125 | void getFrontEndVersion(VersionInfo &Version) const override {} |
| 126 | void getBackEndVersion(VersionInfo &Version) const override {} |
Zachary Turner | 94269a4 | 2015-02-07 01:47:14 +0000 | [diff] [blame] | 127 | |
| 128 | PDB_SymType getSymTag() const override { return Type; } |
| 129 | |
| 130 | MOCK_SYMBOL_ACCESSOR(getAccess) |
| 131 | MOCK_SYMBOL_ACCESSOR(getAddressOffset) |
| 132 | MOCK_SYMBOL_ACCESSOR(getAddressSection) |
| 133 | MOCK_SYMBOL_ACCESSOR(getAge) |
| 134 | MOCK_SYMBOL_ACCESSOR(getArrayIndexTypeId) |
Zachary Turner | 94269a4 | 2015-02-07 01:47:14 +0000 | [diff] [blame] | 135 | MOCK_SYMBOL_ACCESSOR(getBaseDataOffset) |
| 136 | MOCK_SYMBOL_ACCESSOR(getBaseDataSlot) |
| 137 | MOCK_SYMBOL_ACCESSOR(getBaseSymbolId) |
| 138 | MOCK_SYMBOL_ACCESSOR(getBuiltinType) |
| 139 | MOCK_SYMBOL_ACCESSOR(getBitPosition) |
| 140 | MOCK_SYMBOL_ACCESSOR(getCallingConvention) |
| 141 | MOCK_SYMBOL_ACCESSOR(getClassParentId) |
| 142 | MOCK_SYMBOL_ACCESSOR(getCompilerName) |
| 143 | MOCK_SYMBOL_ACCESSOR(getCount) |
| 144 | MOCK_SYMBOL_ACCESSOR(getCountLiveRanges) |
Zachary Turner | 94269a4 | 2015-02-07 01:47:14 +0000 | [diff] [blame] | 145 | MOCK_SYMBOL_ACCESSOR(getLanguage) |
| 146 | MOCK_SYMBOL_ACCESSOR(getLexicalParentId) |
| 147 | MOCK_SYMBOL_ACCESSOR(getLibraryName) |
| 148 | MOCK_SYMBOL_ACCESSOR(getLiveRangeStartAddressOffset) |
| 149 | MOCK_SYMBOL_ACCESSOR(getLiveRangeStartAddressSection) |
| 150 | MOCK_SYMBOL_ACCESSOR(getLiveRangeStartRelativeVirtualAddress) |
| 151 | MOCK_SYMBOL_ACCESSOR(getLocalBasePointerRegisterId) |
| 152 | MOCK_SYMBOL_ACCESSOR(getLowerBoundId) |
| 153 | MOCK_SYMBOL_ACCESSOR(getMemorySpaceKind) |
| 154 | MOCK_SYMBOL_ACCESSOR(getName) |
| 155 | MOCK_SYMBOL_ACCESSOR(getNumberOfAcceleratorPointerTags) |
| 156 | MOCK_SYMBOL_ACCESSOR(getNumberOfColumns) |
| 157 | MOCK_SYMBOL_ACCESSOR(getNumberOfModifiers) |
| 158 | MOCK_SYMBOL_ACCESSOR(getNumberOfRegisterIndices) |
| 159 | MOCK_SYMBOL_ACCESSOR(getNumberOfRows) |
| 160 | MOCK_SYMBOL_ACCESSOR(getObjectFileName) |
| 161 | MOCK_SYMBOL_ACCESSOR(getOemId) |
| 162 | MOCK_SYMBOL_ACCESSOR(getOemSymbolId) |
| 163 | MOCK_SYMBOL_ACCESSOR(getOffsetInUdt) |
| 164 | MOCK_SYMBOL_ACCESSOR(getPlatform) |
| 165 | MOCK_SYMBOL_ACCESSOR(getRank) |
| 166 | MOCK_SYMBOL_ACCESSOR(getRegisterId) |
| 167 | MOCK_SYMBOL_ACCESSOR(getRegisterType) |
| 168 | MOCK_SYMBOL_ACCESSOR(getRelativeVirtualAddress) |
| 169 | MOCK_SYMBOL_ACCESSOR(getSamplerSlot) |
| 170 | MOCK_SYMBOL_ACCESSOR(getSignature) |
| 171 | MOCK_SYMBOL_ACCESSOR(getSizeInUdt) |
| 172 | MOCK_SYMBOL_ACCESSOR(getSlot) |
| 173 | MOCK_SYMBOL_ACCESSOR(getSourceFileName) |
| 174 | MOCK_SYMBOL_ACCESSOR(getStride) |
| 175 | MOCK_SYMBOL_ACCESSOR(getSubTypeId) |
| 176 | MOCK_SYMBOL_ACCESSOR(getSymbolsFileName) |
| 177 | MOCK_SYMBOL_ACCESSOR(getSymIndexId) |
| 178 | MOCK_SYMBOL_ACCESSOR(getTargetOffset) |
| 179 | MOCK_SYMBOL_ACCESSOR(getTargetRelativeVirtualAddress) |
| 180 | MOCK_SYMBOL_ACCESSOR(getTargetVirtualAddress) |
| 181 | MOCK_SYMBOL_ACCESSOR(getTargetSection) |
| 182 | MOCK_SYMBOL_ACCESSOR(getTextureSlot) |
| 183 | MOCK_SYMBOL_ACCESSOR(getTimeStamp) |
| 184 | MOCK_SYMBOL_ACCESSOR(getToken) |
| 185 | MOCK_SYMBOL_ACCESSOR(getTypeId) |
| 186 | MOCK_SYMBOL_ACCESSOR(getUavSlot) |
| 187 | MOCK_SYMBOL_ACCESSOR(getUndecoratedName) |
| 188 | MOCK_SYMBOL_ACCESSOR(getUnmodifiedTypeId) |
| 189 | MOCK_SYMBOL_ACCESSOR(getUpperBoundId) |
| 190 | MOCK_SYMBOL_ACCESSOR(getVirtualBaseDispIndex) |
| 191 | MOCK_SYMBOL_ACCESSOR(getVirtualBaseOffset) |
| 192 | MOCK_SYMBOL_ACCESSOR(getVirtualTableShapeId) |
| 193 | MOCK_SYMBOL_ACCESSOR(getDataKind) |
| 194 | MOCK_SYMBOL_ACCESSOR(getGuid) |
| 195 | MOCK_SYMBOL_ACCESSOR(getOffset) |
| 196 | MOCK_SYMBOL_ACCESSOR(getThisAdjust) |
| 197 | MOCK_SYMBOL_ACCESSOR(getVirtualBasePointerOffset) |
| 198 | MOCK_SYMBOL_ACCESSOR(getLocationType) |
| 199 | MOCK_SYMBOL_ACCESSOR(getMachineType) |
| 200 | MOCK_SYMBOL_ACCESSOR(getThunkOrdinal) |
| 201 | MOCK_SYMBOL_ACCESSOR(getLength) |
| 202 | MOCK_SYMBOL_ACCESSOR(getLiveRangeLength) |
| 203 | MOCK_SYMBOL_ACCESSOR(getVirtualAddress) |
| 204 | MOCK_SYMBOL_ACCESSOR(getUdtKind) |
| 205 | MOCK_SYMBOL_ACCESSOR(hasConstructor) |
| 206 | MOCK_SYMBOL_ACCESSOR(hasCustomCallingConvention) |
| 207 | MOCK_SYMBOL_ACCESSOR(hasFarReturn) |
| 208 | MOCK_SYMBOL_ACCESSOR(isCode) |
| 209 | MOCK_SYMBOL_ACCESSOR(isCompilerGenerated) |
| 210 | MOCK_SYMBOL_ACCESSOR(isConstType) |
| 211 | MOCK_SYMBOL_ACCESSOR(isEditAndContinueEnabled) |
| 212 | MOCK_SYMBOL_ACCESSOR(isFunction) |
| 213 | MOCK_SYMBOL_ACCESSOR(getAddressTaken) |
| 214 | MOCK_SYMBOL_ACCESSOR(getNoStackOrdering) |
| 215 | MOCK_SYMBOL_ACCESSOR(hasAlloca) |
| 216 | MOCK_SYMBOL_ACCESSOR(hasAssignmentOperator) |
| 217 | MOCK_SYMBOL_ACCESSOR(hasCTypes) |
| 218 | MOCK_SYMBOL_ACCESSOR(hasCastOperator) |
| 219 | MOCK_SYMBOL_ACCESSOR(hasDebugInfo) |
| 220 | MOCK_SYMBOL_ACCESSOR(hasEH) |
| 221 | MOCK_SYMBOL_ACCESSOR(hasEHa) |
Zachary Turner | a554917 | 2015-02-10 22:43:25 +0000 | [diff] [blame] | 222 | MOCK_SYMBOL_ACCESSOR(hasFramePointer) |
Zachary Turner | 94269a4 | 2015-02-07 01:47:14 +0000 | [diff] [blame] | 223 | MOCK_SYMBOL_ACCESSOR(hasInlAsm) |
| 224 | MOCK_SYMBOL_ACCESSOR(hasInlineAttribute) |
| 225 | MOCK_SYMBOL_ACCESSOR(hasInterruptReturn) |
| 226 | MOCK_SYMBOL_ACCESSOR(hasLongJump) |
| 227 | MOCK_SYMBOL_ACCESSOR(hasManagedCode) |
| 228 | MOCK_SYMBOL_ACCESSOR(hasNestedTypes) |
| 229 | MOCK_SYMBOL_ACCESSOR(hasNoInlineAttribute) |
| 230 | MOCK_SYMBOL_ACCESSOR(hasNoReturnAttribute) |
| 231 | MOCK_SYMBOL_ACCESSOR(hasOptimizedCodeDebugInfo) |
| 232 | MOCK_SYMBOL_ACCESSOR(hasOverloadedOperator) |
| 233 | MOCK_SYMBOL_ACCESSOR(hasSEH) |
| 234 | MOCK_SYMBOL_ACCESSOR(hasSecurityChecks) |
| 235 | MOCK_SYMBOL_ACCESSOR(hasSetJump) |
| 236 | MOCK_SYMBOL_ACCESSOR(hasStrictGSCheck) |
| 237 | MOCK_SYMBOL_ACCESSOR(isAcceleratorGroupSharedLocal) |
| 238 | MOCK_SYMBOL_ACCESSOR(isAcceleratorPointerTagLiveRange) |
| 239 | MOCK_SYMBOL_ACCESSOR(isAcceleratorStubFunction) |
| 240 | MOCK_SYMBOL_ACCESSOR(isAggregated) |
| 241 | MOCK_SYMBOL_ACCESSOR(isIntroVirtualFunction) |
| 242 | MOCK_SYMBOL_ACCESSOR(isCVTCIL) |
| 243 | MOCK_SYMBOL_ACCESSOR(isConstructorVirtualBase) |
| 244 | MOCK_SYMBOL_ACCESSOR(isCxxReturnUdt) |
| 245 | MOCK_SYMBOL_ACCESSOR(isDataAligned) |
| 246 | MOCK_SYMBOL_ACCESSOR(isHLSLData) |
| 247 | MOCK_SYMBOL_ACCESSOR(isHotpatchable) |
| 248 | MOCK_SYMBOL_ACCESSOR(isIndirectVirtualBaseClass) |
| 249 | MOCK_SYMBOL_ACCESSOR(isInterfaceUdt) |
| 250 | MOCK_SYMBOL_ACCESSOR(isIntrinsic) |
| 251 | MOCK_SYMBOL_ACCESSOR(isLTCG) |
| 252 | MOCK_SYMBOL_ACCESSOR(isLocationControlFlowDependent) |
| 253 | MOCK_SYMBOL_ACCESSOR(isMSILNetmodule) |
| 254 | MOCK_SYMBOL_ACCESSOR(isMatrixRowMajor) |
| 255 | MOCK_SYMBOL_ACCESSOR(isManagedCode) |
| 256 | MOCK_SYMBOL_ACCESSOR(isMSILCode) |
| 257 | MOCK_SYMBOL_ACCESSOR(isMultipleInheritance) |
| 258 | MOCK_SYMBOL_ACCESSOR(isNaked) |
| 259 | MOCK_SYMBOL_ACCESSOR(isNested) |
| 260 | MOCK_SYMBOL_ACCESSOR(isOptimizedAway) |
| 261 | MOCK_SYMBOL_ACCESSOR(isPacked) |
| 262 | MOCK_SYMBOL_ACCESSOR(isPointerBasedOnSymbolValue) |
| 263 | MOCK_SYMBOL_ACCESSOR(isPointerToDataMember) |
| 264 | MOCK_SYMBOL_ACCESSOR(isPointerToMemberFunction) |
| 265 | MOCK_SYMBOL_ACCESSOR(isPureVirtual) |
| 266 | MOCK_SYMBOL_ACCESSOR(isRValueReference) |
| 267 | MOCK_SYMBOL_ACCESSOR(isRefUdt) |
| 268 | MOCK_SYMBOL_ACCESSOR(isReference) |
| 269 | MOCK_SYMBOL_ACCESSOR(isRestrictedType) |
| 270 | MOCK_SYMBOL_ACCESSOR(isReturnValue) |
| 271 | MOCK_SYMBOL_ACCESSOR(isSafeBuffers) |
| 272 | MOCK_SYMBOL_ACCESSOR(isScoped) |
| 273 | MOCK_SYMBOL_ACCESSOR(isSdl) |
| 274 | MOCK_SYMBOL_ACCESSOR(isSingleInheritance) |
| 275 | MOCK_SYMBOL_ACCESSOR(isSplitted) |
| 276 | MOCK_SYMBOL_ACCESSOR(isStatic) |
| 277 | MOCK_SYMBOL_ACCESSOR(hasPrivateSymbols) |
| 278 | MOCK_SYMBOL_ACCESSOR(isUnalignedType) |
| 279 | MOCK_SYMBOL_ACCESSOR(isUnreached) |
| 280 | MOCK_SYMBOL_ACCESSOR(isValueUdt) |
| 281 | MOCK_SYMBOL_ACCESSOR(isVirtual) |
| 282 | MOCK_SYMBOL_ACCESSOR(isVirtualBaseClass) |
| 283 | MOCK_SYMBOL_ACCESSOR(isVirtualInheritance) |
| 284 | MOCK_SYMBOL_ACCESSOR(isVolatileType) |
Zachary Turner | 00dbc75 | 2015-02-13 01:39:22 +0000 | [diff] [blame] | 285 | MOCK_SYMBOL_ACCESSOR(getValue) |
| 286 | MOCK_SYMBOL_ACCESSOR(wasInlined) |
| 287 | MOCK_SYMBOL_ACCESSOR(getUnused) |
Zachary Turner | 94269a4 | 2015-02-07 01:47:14 +0000 | [diff] [blame] | 288 | |
| 289 | private: |
| 290 | PDB_SymType Type; |
| 291 | }; |
| 292 | |
| 293 | class PDBApiTest : public testing::Test { |
| 294 | public: |
| 295 | std::unordered_map<PDB_SymType, std::unique_ptr<PDBSymbol>> SymbolMap; |
| 296 | |
| 297 | void SetUp() override { |
Zachary Turner | bae16b3 | 2015-02-08 20:58:09 +0000 | [diff] [blame] | 298 | Session.reset(new MockSession()); |
| 299 | |
Zachary Turner | 94269a4 | 2015-02-07 01:47:14 +0000 | [diff] [blame] | 300 | InsertItemWithTag(PDB_SymType::None); |
| 301 | InsertItemWithTag(PDB_SymType::Exe); |
| 302 | InsertItemWithTag(PDB_SymType::Compiland); |
| 303 | InsertItemWithTag(PDB_SymType::CompilandDetails); |
| 304 | InsertItemWithTag(PDB_SymType::CompilandEnv); |
| 305 | InsertItemWithTag(PDB_SymType::Function); |
| 306 | InsertItemWithTag(PDB_SymType::Block); |
| 307 | InsertItemWithTag(PDB_SymType::Data); |
| 308 | InsertItemWithTag(PDB_SymType::Annotation); |
| 309 | InsertItemWithTag(PDB_SymType::Label); |
| 310 | InsertItemWithTag(PDB_SymType::PublicSymbol); |
| 311 | InsertItemWithTag(PDB_SymType::UDT); |
| 312 | InsertItemWithTag(PDB_SymType::Enum); |
| 313 | InsertItemWithTag(PDB_SymType::FunctionSig); |
| 314 | InsertItemWithTag(PDB_SymType::PointerType); |
| 315 | InsertItemWithTag(PDB_SymType::ArrayType); |
| 316 | InsertItemWithTag(PDB_SymType::BuiltinType); |
| 317 | InsertItemWithTag(PDB_SymType::Typedef); |
| 318 | InsertItemWithTag(PDB_SymType::BaseClass); |
| 319 | InsertItemWithTag(PDB_SymType::Friend); |
| 320 | InsertItemWithTag(PDB_SymType::FunctionArg); |
| 321 | InsertItemWithTag(PDB_SymType::FuncDebugStart); |
| 322 | InsertItemWithTag(PDB_SymType::FuncDebugEnd); |
| 323 | InsertItemWithTag(PDB_SymType::UsingNamespace); |
| 324 | InsertItemWithTag(PDB_SymType::VTableShape); |
| 325 | InsertItemWithTag(PDB_SymType::VTable); |
| 326 | InsertItemWithTag(PDB_SymType::Custom); |
| 327 | InsertItemWithTag(PDB_SymType::Thunk); |
| 328 | InsertItemWithTag(PDB_SymType::CustomType); |
| 329 | InsertItemWithTag(PDB_SymType::ManagedType); |
| 330 | InsertItemWithTag(PDB_SymType::Dimension); |
| 331 | InsertItemWithTag(PDB_SymType::Max); |
| 332 | } |
| 333 | |
Zachary Turner | 94269a4 | 2015-02-07 01:47:14 +0000 | [diff] [blame] | 334 | template <class ExpectedType> void VerifyDyncast(PDB_SymType Tag) { |
| 335 | for (auto item = SymbolMap.begin(); item != SymbolMap.end(); ++item) { |
| 336 | EXPECT_EQ(item->first == Tag, llvm::isa<ExpectedType>(*item->second)); |
| 337 | } |
| 338 | } |
| 339 | |
| 340 | void VerifyUnknownDyncasts() { |
| 341 | for (auto item = SymbolMap.begin(); item != SymbolMap.end(); ++item) { |
| 342 | bool should_match = false; |
| 343 | if (item->first == PDB_SymType::None || item->first >= PDB_SymType::Max) |
| 344 | should_match = true; |
| 345 | |
| 346 | EXPECT_EQ(should_match, llvm::isa<PDBSymbolUnknown>(*item->second)); |
| 347 | } |
| 348 | } |
Zachary Turner | bae16b3 | 2015-02-08 20:58:09 +0000 | [diff] [blame] | 349 | |
| 350 | private: |
| 351 | std::unique_ptr<IPDBSession> Session; |
| 352 | |
| 353 | void InsertItemWithTag(PDB_SymType Tag) { |
Zachary Turner | f07ef22 | 2015-02-11 00:33:00 +0000 | [diff] [blame] | 354 | auto RawSymbol = llvm::make_unique<MockRawSymbol>(Tag); |
Zachary Turner | bae16b3 | 2015-02-08 20:58:09 +0000 | [diff] [blame] | 355 | auto Symbol = PDBSymbol::create(*Session, std::move(RawSymbol)); |
| 356 | SymbolMap.insert(std::make_pair(Tag, std::move(Symbol))); |
| 357 | } |
Zachary Turner | 94269a4 | 2015-02-07 01:47:14 +0000 | [diff] [blame] | 358 | }; |
| 359 | |
| 360 | TEST_F(PDBApiTest, Dyncast) { |
| 361 | |
| 362 | // Most of the types have a one-to-one mapping between Tag and concrete type. |
| 363 | VerifyDyncast<PDBSymbolExe>(PDB_SymType::Exe); |
| 364 | VerifyDyncast<PDBSymbolCompiland>(PDB_SymType::Compiland); |
| 365 | VerifyDyncast<PDBSymbolCompilandDetails>(PDB_SymType::CompilandDetails); |
| 366 | VerifyDyncast<PDBSymbolCompilandEnv>(PDB_SymType::CompilandEnv); |
| 367 | VerifyDyncast<PDBSymbolFunc>(PDB_SymType::Function); |
| 368 | VerifyDyncast<PDBSymbolBlock>(PDB_SymType::Block); |
| 369 | VerifyDyncast<PDBSymbolData>(PDB_SymType::Data); |
| 370 | VerifyDyncast<PDBSymbolAnnotation>(PDB_SymType::Annotation); |
| 371 | VerifyDyncast<PDBSymbolLabel>(PDB_SymType::Label); |
| 372 | VerifyDyncast<PDBSymbolPublicSymbol>(PDB_SymType::PublicSymbol); |
| 373 | VerifyDyncast<PDBSymbolTypeUDT>(PDB_SymType::UDT); |
| 374 | VerifyDyncast<PDBSymbolTypeEnum>(PDB_SymType::Enum); |
| 375 | VerifyDyncast<PDBSymbolTypeFunctionSig>(PDB_SymType::FunctionSig); |
| 376 | VerifyDyncast<PDBSymbolTypePointer>(PDB_SymType::PointerType); |
| 377 | VerifyDyncast<PDBSymbolTypeArray>(PDB_SymType::ArrayType); |
| 378 | VerifyDyncast<PDBSymbolTypeBuiltin>(PDB_SymType::BuiltinType); |
| 379 | VerifyDyncast<PDBSymbolTypeTypedef>(PDB_SymType::Typedef); |
| 380 | VerifyDyncast<PDBSymbolTypeBaseClass>(PDB_SymType::BaseClass); |
| 381 | VerifyDyncast<PDBSymbolTypeFriend>(PDB_SymType::Friend); |
| 382 | VerifyDyncast<PDBSymbolTypeFunctionArg>(PDB_SymType::FunctionArg); |
| 383 | VerifyDyncast<PDBSymbolFuncDebugStart>(PDB_SymType::FuncDebugStart); |
| 384 | VerifyDyncast<PDBSymbolFuncDebugEnd>(PDB_SymType::FuncDebugEnd); |
| 385 | VerifyDyncast<PDBSymbolUsingNamespace>(PDB_SymType::UsingNamespace); |
| 386 | VerifyDyncast<PDBSymbolTypeVTableShape>(PDB_SymType::VTableShape); |
| 387 | VerifyDyncast<PDBSymbolTypeVTable>(PDB_SymType::VTable); |
| 388 | VerifyDyncast<PDBSymbolCustom>(PDB_SymType::Custom); |
| 389 | VerifyDyncast<PDBSymbolThunk>(PDB_SymType::Thunk); |
| 390 | VerifyDyncast<PDBSymbolTypeCustom>(PDB_SymType::CustomType); |
| 391 | VerifyDyncast<PDBSymbolTypeManaged>(PDB_SymType::ManagedType); |
| 392 | VerifyDyncast<PDBSymbolTypeDimension>(PDB_SymType::Dimension); |
| 393 | |
| 394 | VerifyUnknownDyncasts(); |
| 395 | } |
| 396 | |
| 397 | } // end anonymous namespace |