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" |
Zachary Turner | a389c84 | 2018-03-13 17:58:28 +0000 | [diff] [blame] | 14 | #include "llvm/DebugInfo/PDB/IPDBInjectedSource.h" |
Aaron Smith | 25409dd | 2018-03-07 00:33:09 +0000 | [diff] [blame] | 15 | #include "llvm/DebugInfo/PDB/IPDBLineNumber.h" |
Zachary Turner | 94269a4 | 2015-02-07 01:47:14 +0000 | [diff] [blame] | 16 | #include "llvm/DebugInfo/PDB/IPDBRawSymbol.h" |
Aaron Smith | 523de05 | 2018-03-22 04:08:15 +0000 | [diff] [blame] | 17 | #include "llvm/DebugInfo/PDB/IPDBSectionContrib.h" |
Zachary Turner | bae16b3 | 2015-02-08 20:58:09 +0000 | [diff] [blame] | 18 | #include "llvm/DebugInfo/PDB/IPDBSession.h" |
| 19 | #include "llvm/DebugInfo/PDB/IPDBSourceFile.h" |
Aaron Smith | 89bca9e | 2017-11-16 14:33:09 +0000 | [diff] [blame] | 20 | #include "llvm/DebugInfo/PDB/IPDBTable.h" |
Zachary Turner | bae16b3 | 2015-02-08 20:58:09 +0000 | [diff] [blame] | 21 | |
Zachary Turner | 94269a4 | 2015-02-07 01:47:14 +0000 | [diff] [blame] | 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" |
| 56 | using namespace llvm; |
Zachary Turner | e13787e | 2016-05-04 21:06:12 +0000 | [diff] [blame] | 57 | using namespace llvm::pdb; |
Zachary Turner | 94269a4 | 2015-02-07 01:47:14 +0000 | [diff] [blame] | 58 | |
Zachary Turner | 94269a4 | 2015-02-07 01:47:14 +0000 | [diff] [blame] | 59 | namespace { |
| 60 | |
| 61 | #define MOCK_SYMBOL_ACCESSOR(Func) \ |
Zachary Turner | 635c2c4 | 2015-02-07 02:02:23 +0000 | [diff] [blame] | 62 | decltype(std::declval<IPDBRawSymbol>().Func()) Func() const override { \ |
Zachary Turner | 94269a4 | 2015-02-07 01:47:14 +0000 | [diff] [blame] | 63 | typedef decltype(IPDBRawSymbol::Func()) ReturnType; \ |
| 64 | return ReturnType(); \ |
| 65 | } |
| 66 | |
Zachary Turner | bae16b3 | 2015-02-08 20:58:09 +0000 | [diff] [blame] | 67 | class MockSession : public IPDBSession { |
| 68 | uint64_t getLoadAddress() const override { return 0; } |
Aaron Smith | 89a19ac | 2018-02-23 00:02:27 +0000 | [diff] [blame] | 69 | bool setLoadAddress(uint64_t Address) override { return false; } |
Adrian McCarthy | 6a4b080 | 2017-06-22 18:42:23 +0000 | [diff] [blame] | 70 | std::unique_ptr<PDBSymbolExe> getGlobalScope() override { return nullptr; } |
Zachary Turner | 0ca2bde | 2015-02-10 21:40:29 +0000 | [diff] [blame] | 71 | std::unique_ptr<PDBSymbol> getSymbolById(uint32_t SymbolId) const override { |
| 72 | return nullptr; |
| 73 | } |
| 74 | std::unique_ptr<IPDBSourceFile> |
| 75 | getSourceFileById(uint32_t SymbolId) const override { |
Zachary Turner | bae16b3 | 2015-02-08 20:58:09 +0000 | [diff] [blame] | 76 | return nullptr; |
| 77 | } |
Aaron Smith | 53708a5 | 2018-03-26 22:10:02 +0000 | [diff] [blame] | 78 | bool addressForVA(uint64_t VA, uint32_t &Section, |
| 79 | uint32_t &Offset) const override { |
| 80 | return false; |
| 81 | } |
| 82 | bool addressForRVA(uint32_t RVA, uint32_t &Section, |
| 83 | uint32_t &Offset) const override { |
| 84 | return false; |
| 85 | } |
Zachary Turner | 4b08354 | 2015-04-17 22:40:36 +0000 | [diff] [blame] | 86 | std::unique_ptr<PDBSymbol> |
Zachary Turner | 292e92d | 2015-05-01 20:51:49 +0000 | [diff] [blame] | 87 | findSymbolByAddress(uint64_t Address, PDB_SymType Type) const override { |
Zachary Turner | 4b08354 | 2015-04-17 22:40:36 +0000 | [diff] [blame] | 88 | return nullptr; |
| 89 | } |
Aaron Smith | 860f0a5 | 2018-04-10 18:12:49 +0000 | [diff] [blame] | 90 | std::unique_ptr<PDBSymbol> findSymbolByRVA(uint32_t RVA, |
| 91 | PDB_SymType Type) const override { |
| 92 | return nullptr; |
| 93 | } |
| 94 | std::unique_ptr<PDBSymbol> |
| 95 | findSymbolBySectOffset(uint32_t Sect, uint32_t Offset, |
| 96 | PDB_SymType Type) const override { |
| 97 | return nullptr; |
| 98 | } |
Zachary Turner | 4b08354 | 2015-04-17 22:40:36 +0000 | [diff] [blame] | 99 | std::unique_ptr<IPDBEnumLineNumbers> |
Zachary Turner | 43ec3af | 2016-02-18 18:47:29 +0000 | [diff] [blame] | 100 | findLineNumbers(const PDBSymbolCompiland &Compiland, |
| 101 | const IPDBSourceFile &File) const override { |
| 102 | return nullptr; |
| 103 | } |
| 104 | std::unique_ptr<IPDBEnumLineNumbers> |
Zachary Turner | 4b08354 | 2015-04-17 22:40:36 +0000 | [diff] [blame] | 105 | findLineNumbersByAddress(uint64_t Address, uint32_t Length) const override { |
| 106 | return nullptr; |
| 107 | } |
Aaron Smith | 40198f5 | 2018-03-15 06:04:51 +0000 | [diff] [blame] | 108 | std::unique_ptr<IPDBEnumLineNumbers> |
Aaron Smith | ed81a9d | 2018-03-26 22:13:22 +0000 | [diff] [blame] | 109 | findLineNumbersByRVA(uint32_t RVA, uint32_t Length) const override { |
| 110 | return nullptr; |
| 111 | } |
| 112 | std::unique_ptr<IPDBEnumLineNumbers> |
Aaron Smith | 40198f5 | 2018-03-15 06:04:51 +0000 | [diff] [blame] | 113 | findLineNumbersBySectOffset(uint32_t Section, uint32_t Offset, |
| 114 | uint32_t Length) const override { |
| 115 | return nullptr; |
| 116 | } |
Zachary Turner | 43ec3af | 2016-02-18 18:47:29 +0000 | [diff] [blame] | 117 | std::unique_ptr<IPDBEnumSourceFiles> |
| 118 | findSourceFiles(const PDBSymbolCompiland *Compiland, llvm::StringRef Pattern, |
| 119 | PDB_NameSearchFlags Flags) const override { |
| 120 | return nullptr; |
| 121 | } |
| 122 | std::unique_ptr<IPDBSourceFile> |
| 123 | findOneSourceFile(const PDBSymbolCompiland *Compiland, |
| 124 | llvm::StringRef Pattern, |
| 125 | PDB_NameSearchFlags Flags) const override { |
| 126 | return nullptr; |
| 127 | } |
| 128 | std::unique_ptr<IPDBEnumChildren<PDBSymbolCompiland>> |
| 129 | findCompilandsForSourceFile(llvm::StringRef Pattern, |
| 130 | PDB_NameSearchFlags Flags) const override { |
| 131 | return nullptr; |
| 132 | } |
| 133 | std::unique_ptr<PDBSymbolCompiland> |
| 134 | findOneCompilandForSourceFile(llvm::StringRef Pattern, |
| 135 | PDB_NameSearchFlags Flags) const override { |
| 136 | return nullptr; |
| 137 | } |
Zachary Turner | 4b08354 | 2015-04-17 22:40:36 +0000 | [diff] [blame] | 138 | |
Zachary Turner | a554917 | 2015-02-10 22:43:25 +0000 | [diff] [blame] | 139 | std::unique_ptr<IPDBEnumSourceFiles> getAllSourceFiles() const override { |
| 140 | return nullptr; |
| 141 | } |
| 142 | std::unique_ptr<IPDBEnumSourceFiles> getSourceFilesForCompiland( |
| 143 | const PDBSymbolCompiland &Compiland) const override { |
Zachary Turner | bae16b3 | 2015-02-08 20:58:09 +0000 | [diff] [blame] | 144 | return nullptr; |
| 145 | } |
Zachary Turner | c9c9c34 | 2015-02-10 22:56:21 +0000 | [diff] [blame] | 146 | |
| 147 | std::unique_ptr<IPDBEnumDataStreams> getDebugStreams() const override { |
| 148 | return nullptr; |
| 149 | } |
Aaron Smith | 89bca9e | 2017-11-16 14:33:09 +0000 | [diff] [blame] | 150 | |
| 151 | std::unique_ptr<IPDBEnumTables> getEnumTables() const override { |
| 152 | return nullptr; |
| 153 | } |
Zachary Turner | a389c84 | 2018-03-13 17:58:28 +0000 | [diff] [blame] | 154 | |
| 155 | std::unique_ptr<IPDBEnumInjectedSources> getInjectedSources() const override { |
| 156 | return nullptr; |
| 157 | } |
Aaron Smith | 523de05 | 2018-03-22 04:08:15 +0000 | [diff] [blame] | 158 | |
| 159 | std::unique_ptr<IPDBEnumSectionContribs> getSectionContribs() const override { |
| 160 | return nullptr; |
| 161 | } |
Zachary Turner | bae16b3 | 2015-02-08 20:58:09 +0000 | [diff] [blame] | 162 | }; |
| 163 | |
Zachary Turner | 94269a4 | 2015-02-07 01:47:14 +0000 | [diff] [blame] | 164 | class MockRawSymbol : public IPDBRawSymbol { |
| 165 | public: |
Zachary Turner | f07ef22 | 2015-02-11 00:33:00 +0000 | [diff] [blame] | 166 | MockRawSymbol(PDB_SymType SymType) |
| 167 | : Type(SymType) {} |
Zachary Turner | 94269a4 | 2015-02-07 01:47:14 +0000 | [diff] [blame] | 168 | |
Zachary Turner | bc42da0 | 2015-02-23 05:59:14 +0000 | [diff] [blame] | 169 | void dump(raw_ostream &OS, int Indent) const override {} |
Zachary Turner | 94269a4 | 2015-02-07 01:47:14 +0000 | [diff] [blame] | 170 | |
Chandler Carruth | c94234c | 2015-02-07 08:12:22 +0000 | [diff] [blame] | 171 | std::unique_ptr<IPDBEnumSymbols> |
Zachary Turner | a554917 | 2015-02-10 22:43:25 +0000 | [diff] [blame] | 172 | findChildren(PDB_SymType Type) const override { |
| 173 | return nullptr; |
| 174 | } |
| 175 | std::unique_ptr<IPDBEnumSymbols> |
Zachary Turner | 94269a4 | 2015-02-07 01:47:14 +0000 | [diff] [blame] | 176 | findChildren(PDB_SymType Type, StringRef Name, |
Chandler Carruth | c94234c | 2015-02-07 08:12:22 +0000 | [diff] [blame] | 177 | PDB_NameSearchFlags Flags) const override { |
Zachary Turner | 94269a4 | 2015-02-07 01:47:14 +0000 | [diff] [blame] | 178 | return nullptr; |
| 179 | } |
Chandler Carruth | c94234c | 2015-02-07 08:12:22 +0000 | [diff] [blame] | 180 | std::unique_ptr<IPDBEnumSymbols> |
Aaron Smith | fbe6540 | 2018-02-22 19:47:43 +0000 | [diff] [blame] | 181 | findChildrenByAddr(PDB_SymType Type, StringRef Name, PDB_NameSearchFlags Flags, |
Aaron Smith | 9930e90 | 2018-02-22 20:28:40 +0000 | [diff] [blame] | 182 | uint32_t Section, uint32_t Offset) const override { |
Aaron Smith | fbe6540 | 2018-02-22 19:47:43 +0000 | [diff] [blame] | 183 | return nullptr; |
| 184 | } |
| 185 | std::unique_ptr<IPDBEnumSymbols> |
| 186 | findChildrenByVA(PDB_SymType Type, StringRef Name, PDB_NameSearchFlags Flags, |
| 187 | uint64_t VA) const override { |
| 188 | return nullptr; |
| 189 | } |
| 190 | std::unique_ptr<IPDBEnumSymbols> |
Zachary Turner | 94269a4 | 2015-02-07 01:47:14 +0000 | [diff] [blame] | 191 | findChildrenByRVA(PDB_SymType Type, StringRef Name, PDB_NameSearchFlags Flags, |
Chandler Carruth | c94234c | 2015-02-07 08:12:22 +0000 | [diff] [blame] | 192 | uint32_t RVA) const override { |
Zachary Turner | 94269a4 | 2015-02-07 01:47:14 +0000 | [diff] [blame] | 193 | return nullptr; |
| 194 | } |
Chandler Carruth | c94234c | 2015-02-07 08:12:22 +0000 | [diff] [blame] | 195 | std::unique_ptr<IPDBEnumSymbols> |
Aaron Smith | fbe6540 | 2018-02-22 19:47:43 +0000 | [diff] [blame] | 196 | findInlineFramesByAddr(uint32_t Section, uint32_t Offset) const override { |
| 197 | return nullptr; |
| 198 | } |
| 199 | std::unique_ptr<IPDBEnumSymbols> |
Chandler Carruth | c94234c | 2015-02-07 08:12:22 +0000 | [diff] [blame] | 200 | findInlineFramesByRVA(uint32_t RVA) const override { |
Zachary Turner | 94269a4 | 2015-02-07 01:47:14 +0000 | [diff] [blame] | 201 | return nullptr; |
| 202 | } |
Aaron Smith | fbe6540 | 2018-02-22 19:47:43 +0000 | [diff] [blame] | 203 | std::unique_ptr<IPDBEnumSymbols> |
| 204 | findInlineFramesByVA(uint64_t VA) const override { |
| 205 | return nullptr; |
| 206 | } |
| 207 | std::unique_ptr<IPDBEnumLineNumbers> findInlineeLines() const override { |
| 208 | return nullptr; |
| 209 | } |
| 210 | std::unique_ptr<IPDBEnumLineNumbers> |
| 211 | findInlineeLinesByAddr(uint32_t Section, uint32_t Offset, |
| 212 | uint32_t Length) const override { |
| 213 | return nullptr; |
| 214 | } |
| 215 | std::unique_ptr<IPDBEnumLineNumbers> |
| 216 | findInlineeLinesByRVA(uint32_t RVA, uint32_t Length) const override { |
| 217 | return nullptr; |
| 218 | } |
| 219 | std::unique_ptr<IPDBEnumLineNumbers> |
| 220 | findInlineeLinesByVA(uint64_t VA, uint32_t Length) const override { |
| 221 | return nullptr; |
| 222 | } |
Zachary Turner | 94269a4 | 2015-02-07 01:47:14 +0000 | [diff] [blame] | 223 | |
Chandler Carruth | c94234c | 2015-02-07 08:12:22 +0000 | [diff] [blame] | 224 | void getDataBytes(llvm::SmallVector<uint8_t, 32> &bytes) const override {} |
Zachary Turner | 21473f7 | 2015-02-08 00:29:29 +0000 | [diff] [blame] | 225 | void getFrontEndVersion(VersionInfo &Version) const override {} |
| 226 | void getBackEndVersion(VersionInfo &Version) const override {} |
Zachary Turner | 94269a4 | 2015-02-07 01:47:14 +0000 | [diff] [blame] | 227 | |
| 228 | PDB_SymType getSymTag() const override { return Type; } |
| 229 | |
Aaron Smith | 89bca9e | 2017-11-16 14:33:09 +0000 | [diff] [blame] | 230 | std::string getUndecoratedNameEx(PDB_UndnameFlags Flags) const override { |
| 231 | return {}; |
| 232 | } |
| 233 | |
Aaron Smith | 25409dd | 2018-03-07 00:33:09 +0000 | [diff] [blame] | 234 | std::unique_ptr<IPDBLineNumber> getSrcLineOnTypeDefn() const override { |
| 235 | return nullptr; |
| 236 | } |
| 237 | |
Zachary Turner | 94269a4 | 2015-02-07 01:47:14 +0000 | [diff] [blame] | 238 | MOCK_SYMBOL_ACCESSOR(getAccess) |
| 239 | MOCK_SYMBOL_ACCESSOR(getAddressOffset) |
| 240 | MOCK_SYMBOL_ACCESSOR(getAddressSection) |
| 241 | MOCK_SYMBOL_ACCESSOR(getAge) |
| 242 | MOCK_SYMBOL_ACCESSOR(getArrayIndexTypeId) |
Zachary Turner | 94269a4 | 2015-02-07 01:47:14 +0000 | [diff] [blame] | 243 | MOCK_SYMBOL_ACCESSOR(getBaseDataOffset) |
| 244 | MOCK_SYMBOL_ACCESSOR(getBaseDataSlot) |
| 245 | MOCK_SYMBOL_ACCESSOR(getBaseSymbolId) |
| 246 | MOCK_SYMBOL_ACCESSOR(getBuiltinType) |
| 247 | MOCK_SYMBOL_ACCESSOR(getBitPosition) |
| 248 | MOCK_SYMBOL_ACCESSOR(getCallingConvention) |
| 249 | MOCK_SYMBOL_ACCESSOR(getClassParentId) |
| 250 | MOCK_SYMBOL_ACCESSOR(getCompilerName) |
| 251 | MOCK_SYMBOL_ACCESSOR(getCount) |
| 252 | MOCK_SYMBOL_ACCESSOR(getCountLiveRanges) |
Zachary Turner | 94269a4 | 2015-02-07 01:47:14 +0000 | [diff] [blame] | 253 | MOCK_SYMBOL_ACCESSOR(getLanguage) |
| 254 | MOCK_SYMBOL_ACCESSOR(getLexicalParentId) |
| 255 | MOCK_SYMBOL_ACCESSOR(getLibraryName) |
| 256 | MOCK_SYMBOL_ACCESSOR(getLiveRangeStartAddressOffset) |
| 257 | MOCK_SYMBOL_ACCESSOR(getLiveRangeStartAddressSection) |
| 258 | MOCK_SYMBOL_ACCESSOR(getLiveRangeStartRelativeVirtualAddress) |
| 259 | MOCK_SYMBOL_ACCESSOR(getLocalBasePointerRegisterId) |
| 260 | MOCK_SYMBOL_ACCESSOR(getLowerBoundId) |
| 261 | MOCK_SYMBOL_ACCESSOR(getMemorySpaceKind) |
| 262 | MOCK_SYMBOL_ACCESSOR(getName) |
| 263 | MOCK_SYMBOL_ACCESSOR(getNumberOfAcceleratorPointerTags) |
| 264 | MOCK_SYMBOL_ACCESSOR(getNumberOfColumns) |
| 265 | MOCK_SYMBOL_ACCESSOR(getNumberOfModifiers) |
| 266 | MOCK_SYMBOL_ACCESSOR(getNumberOfRegisterIndices) |
| 267 | MOCK_SYMBOL_ACCESSOR(getNumberOfRows) |
| 268 | MOCK_SYMBOL_ACCESSOR(getObjectFileName) |
| 269 | MOCK_SYMBOL_ACCESSOR(getOemId) |
| 270 | MOCK_SYMBOL_ACCESSOR(getOemSymbolId) |
| 271 | MOCK_SYMBOL_ACCESSOR(getOffsetInUdt) |
| 272 | MOCK_SYMBOL_ACCESSOR(getPlatform) |
| 273 | MOCK_SYMBOL_ACCESSOR(getRank) |
| 274 | MOCK_SYMBOL_ACCESSOR(getRegisterId) |
| 275 | MOCK_SYMBOL_ACCESSOR(getRegisterType) |
| 276 | MOCK_SYMBOL_ACCESSOR(getRelativeVirtualAddress) |
| 277 | MOCK_SYMBOL_ACCESSOR(getSamplerSlot) |
| 278 | MOCK_SYMBOL_ACCESSOR(getSignature) |
| 279 | MOCK_SYMBOL_ACCESSOR(getSizeInUdt) |
| 280 | MOCK_SYMBOL_ACCESSOR(getSlot) |
| 281 | MOCK_SYMBOL_ACCESSOR(getSourceFileName) |
| 282 | MOCK_SYMBOL_ACCESSOR(getStride) |
| 283 | MOCK_SYMBOL_ACCESSOR(getSubTypeId) |
| 284 | MOCK_SYMBOL_ACCESSOR(getSymbolsFileName) |
| 285 | MOCK_SYMBOL_ACCESSOR(getSymIndexId) |
| 286 | MOCK_SYMBOL_ACCESSOR(getTargetOffset) |
| 287 | MOCK_SYMBOL_ACCESSOR(getTargetRelativeVirtualAddress) |
| 288 | MOCK_SYMBOL_ACCESSOR(getTargetVirtualAddress) |
| 289 | MOCK_SYMBOL_ACCESSOR(getTargetSection) |
| 290 | MOCK_SYMBOL_ACCESSOR(getTextureSlot) |
| 291 | MOCK_SYMBOL_ACCESSOR(getTimeStamp) |
| 292 | MOCK_SYMBOL_ACCESSOR(getToken) |
| 293 | MOCK_SYMBOL_ACCESSOR(getTypeId) |
| 294 | MOCK_SYMBOL_ACCESSOR(getUavSlot) |
| 295 | MOCK_SYMBOL_ACCESSOR(getUndecoratedName) |
| 296 | MOCK_SYMBOL_ACCESSOR(getUnmodifiedTypeId) |
| 297 | MOCK_SYMBOL_ACCESSOR(getUpperBoundId) |
| 298 | MOCK_SYMBOL_ACCESSOR(getVirtualBaseDispIndex) |
| 299 | MOCK_SYMBOL_ACCESSOR(getVirtualBaseOffset) |
| 300 | MOCK_SYMBOL_ACCESSOR(getVirtualTableShapeId) |
| 301 | MOCK_SYMBOL_ACCESSOR(getDataKind) |
| 302 | MOCK_SYMBOL_ACCESSOR(getGuid) |
| 303 | MOCK_SYMBOL_ACCESSOR(getOffset) |
| 304 | MOCK_SYMBOL_ACCESSOR(getThisAdjust) |
| 305 | MOCK_SYMBOL_ACCESSOR(getVirtualBasePointerOffset) |
| 306 | MOCK_SYMBOL_ACCESSOR(getLocationType) |
| 307 | MOCK_SYMBOL_ACCESSOR(getMachineType) |
| 308 | MOCK_SYMBOL_ACCESSOR(getThunkOrdinal) |
| 309 | MOCK_SYMBOL_ACCESSOR(getLength) |
Zachary Turner | c883a8c | 2017-04-12 23:18:21 +0000 | [diff] [blame] | 310 | MOCK_SYMBOL_ACCESSOR(getVirtualBaseTableType) |
Zachary Turner | 94269a4 | 2015-02-07 01:47:14 +0000 | [diff] [blame] | 311 | MOCK_SYMBOL_ACCESSOR(getLiveRangeLength) |
| 312 | MOCK_SYMBOL_ACCESSOR(getVirtualAddress) |
| 313 | MOCK_SYMBOL_ACCESSOR(getUdtKind) |
| 314 | MOCK_SYMBOL_ACCESSOR(hasConstructor) |
| 315 | MOCK_SYMBOL_ACCESSOR(hasCustomCallingConvention) |
| 316 | MOCK_SYMBOL_ACCESSOR(hasFarReturn) |
| 317 | MOCK_SYMBOL_ACCESSOR(isCode) |
| 318 | MOCK_SYMBOL_ACCESSOR(isCompilerGenerated) |
| 319 | MOCK_SYMBOL_ACCESSOR(isConstType) |
| 320 | MOCK_SYMBOL_ACCESSOR(isEditAndContinueEnabled) |
| 321 | MOCK_SYMBOL_ACCESSOR(isFunction) |
| 322 | MOCK_SYMBOL_ACCESSOR(getAddressTaken) |
| 323 | MOCK_SYMBOL_ACCESSOR(getNoStackOrdering) |
| 324 | MOCK_SYMBOL_ACCESSOR(hasAlloca) |
| 325 | MOCK_SYMBOL_ACCESSOR(hasAssignmentOperator) |
| 326 | MOCK_SYMBOL_ACCESSOR(hasCTypes) |
| 327 | MOCK_SYMBOL_ACCESSOR(hasCastOperator) |
| 328 | MOCK_SYMBOL_ACCESSOR(hasDebugInfo) |
| 329 | MOCK_SYMBOL_ACCESSOR(hasEH) |
| 330 | MOCK_SYMBOL_ACCESSOR(hasEHa) |
Zachary Turner | a554917 | 2015-02-10 22:43:25 +0000 | [diff] [blame] | 331 | MOCK_SYMBOL_ACCESSOR(hasFramePointer) |
Zachary Turner | 94269a4 | 2015-02-07 01:47:14 +0000 | [diff] [blame] | 332 | MOCK_SYMBOL_ACCESSOR(hasInlAsm) |
| 333 | MOCK_SYMBOL_ACCESSOR(hasInlineAttribute) |
| 334 | MOCK_SYMBOL_ACCESSOR(hasInterruptReturn) |
| 335 | MOCK_SYMBOL_ACCESSOR(hasLongJump) |
| 336 | MOCK_SYMBOL_ACCESSOR(hasManagedCode) |
| 337 | MOCK_SYMBOL_ACCESSOR(hasNestedTypes) |
| 338 | MOCK_SYMBOL_ACCESSOR(hasNoInlineAttribute) |
| 339 | MOCK_SYMBOL_ACCESSOR(hasNoReturnAttribute) |
| 340 | MOCK_SYMBOL_ACCESSOR(hasOptimizedCodeDebugInfo) |
| 341 | MOCK_SYMBOL_ACCESSOR(hasOverloadedOperator) |
| 342 | MOCK_SYMBOL_ACCESSOR(hasSEH) |
| 343 | MOCK_SYMBOL_ACCESSOR(hasSecurityChecks) |
| 344 | MOCK_SYMBOL_ACCESSOR(hasSetJump) |
| 345 | MOCK_SYMBOL_ACCESSOR(hasStrictGSCheck) |
| 346 | MOCK_SYMBOL_ACCESSOR(isAcceleratorGroupSharedLocal) |
| 347 | MOCK_SYMBOL_ACCESSOR(isAcceleratorPointerTagLiveRange) |
| 348 | MOCK_SYMBOL_ACCESSOR(isAcceleratorStubFunction) |
| 349 | MOCK_SYMBOL_ACCESSOR(isAggregated) |
| 350 | MOCK_SYMBOL_ACCESSOR(isIntroVirtualFunction) |
| 351 | MOCK_SYMBOL_ACCESSOR(isCVTCIL) |
| 352 | MOCK_SYMBOL_ACCESSOR(isConstructorVirtualBase) |
| 353 | MOCK_SYMBOL_ACCESSOR(isCxxReturnUdt) |
| 354 | MOCK_SYMBOL_ACCESSOR(isDataAligned) |
| 355 | MOCK_SYMBOL_ACCESSOR(isHLSLData) |
| 356 | MOCK_SYMBOL_ACCESSOR(isHotpatchable) |
| 357 | MOCK_SYMBOL_ACCESSOR(isIndirectVirtualBaseClass) |
| 358 | MOCK_SYMBOL_ACCESSOR(isInterfaceUdt) |
| 359 | MOCK_SYMBOL_ACCESSOR(isIntrinsic) |
| 360 | MOCK_SYMBOL_ACCESSOR(isLTCG) |
| 361 | MOCK_SYMBOL_ACCESSOR(isLocationControlFlowDependent) |
| 362 | MOCK_SYMBOL_ACCESSOR(isMSILNetmodule) |
| 363 | MOCK_SYMBOL_ACCESSOR(isMatrixRowMajor) |
| 364 | MOCK_SYMBOL_ACCESSOR(isManagedCode) |
| 365 | MOCK_SYMBOL_ACCESSOR(isMSILCode) |
| 366 | MOCK_SYMBOL_ACCESSOR(isMultipleInheritance) |
| 367 | MOCK_SYMBOL_ACCESSOR(isNaked) |
| 368 | MOCK_SYMBOL_ACCESSOR(isNested) |
| 369 | MOCK_SYMBOL_ACCESSOR(isOptimizedAway) |
| 370 | MOCK_SYMBOL_ACCESSOR(isPacked) |
| 371 | MOCK_SYMBOL_ACCESSOR(isPointerBasedOnSymbolValue) |
| 372 | MOCK_SYMBOL_ACCESSOR(isPointerToDataMember) |
| 373 | MOCK_SYMBOL_ACCESSOR(isPointerToMemberFunction) |
| 374 | MOCK_SYMBOL_ACCESSOR(isPureVirtual) |
| 375 | MOCK_SYMBOL_ACCESSOR(isRValueReference) |
| 376 | MOCK_SYMBOL_ACCESSOR(isRefUdt) |
| 377 | MOCK_SYMBOL_ACCESSOR(isReference) |
| 378 | MOCK_SYMBOL_ACCESSOR(isRestrictedType) |
| 379 | MOCK_SYMBOL_ACCESSOR(isReturnValue) |
| 380 | MOCK_SYMBOL_ACCESSOR(isSafeBuffers) |
| 381 | MOCK_SYMBOL_ACCESSOR(isScoped) |
| 382 | MOCK_SYMBOL_ACCESSOR(isSdl) |
| 383 | MOCK_SYMBOL_ACCESSOR(isSingleInheritance) |
| 384 | MOCK_SYMBOL_ACCESSOR(isSplitted) |
| 385 | MOCK_SYMBOL_ACCESSOR(isStatic) |
| 386 | MOCK_SYMBOL_ACCESSOR(hasPrivateSymbols) |
| 387 | MOCK_SYMBOL_ACCESSOR(isUnalignedType) |
| 388 | MOCK_SYMBOL_ACCESSOR(isUnreached) |
| 389 | MOCK_SYMBOL_ACCESSOR(isValueUdt) |
| 390 | MOCK_SYMBOL_ACCESSOR(isVirtual) |
| 391 | MOCK_SYMBOL_ACCESSOR(isVirtualBaseClass) |
| 392 | MOCK_SYMBOL_ACCESSOR(isVirtualInheritance) |
| 393 | MOCK_SYMBOL_ACCESSOR(isVolatileType) |
Zachary Turner | 00dbc75 | 2015-02-13 01:39:22 +0000 | [diff] [blame] | 394 | MOCK_SYMBOL_ACCESSOR(getValue) |
| 395 | MOCK_SYMBOL_ACCESSOR(wasInlined) |
| 396 | MOCK_SYMBOL_ACCESSOR(getUnused) |
Zachary Turner | 94269a4 | 2015-02-07 01:47:14 +0000 | [diff] [blame] | 397 | |
| 398 | private: |
| 399 | PDB_SymType Type; |
| 400 | }; |
| 401 | |
| 402 | class PDBApiTest : public testing::Test { |
| 403 | public: |
| 404 | std::unordered_map<PDB_SymType, std::unique_ptr<PDBSymbol>> SymbolMap; |
| 405 | |
| 406 | void SetUp() override { |
Zachary Turner | bae16b3 | 2015-02-08 20:58:09 +0000 | [diff] [blame] | 407 | Session.reset(new MockSession()); |
| 408 | |
Zachary Turner | 94269a4 | 2015-02-07 01:47:14 +0000 | [diff] [blame] | 409 | InsertItemWithTag(PDB_SymType::None); |
| 410 | InsertItemWithTag(PDB_SymType::Exe); |
| 411 | InsertItemWithTag(PDB_SymType::Compiland); |
| 412 | InsertItemWithTag(PDB_SymType::CompilandDetails); |
| 413 | InsertItemWithTag(PDB_SymType::CompilandEnv); |
| 414 | InsertItemWithTag(PDB_SymType::Function); |
| 415 | InsertItemWithTag(PDB_SymType::Block); |
| 416 | InsertItemWithTag(PDB_SymType::Data); |
| 417 | InsertItemWithTag(PDB_SymType::Annotation); |
| 418 | InsertItemWithTag(PDB_SymType::Label); |
| 419 | InsertItemWithTag(PDB_SymType::PublicSymbol); |
| 420 | InsertItemWithTag(PDB_SymType::UDT); |
| 421 | InsertItemWithTag(PDB_SymType::Enum); |
| 422 | InsertItemWithTag(PDB_SymType::FunctionSig); |
| 423 | InsertItemWithTag(PDB_SymType::PointerType); |
| 424 | InsertItemWithTag(PDB_SymType::ArrayType); |
| 425 | InsertItemWithTag(PDB_SymType::BuiltinType); |
| 426 | InsertItemWithTag(PDB_SymType::Typedef); |
| 427 | InsertItemWithTag(PDB_SymType::BaseClass); |
| 428 | InsertItemWithTag(PDB_SymType::Friend); |
| 429 | InsertItemWithTag(PDB_SymType::FunctionArg); |
| 430 | InsertItemWithTag(PDB_SymType::FuncDebugStart); |
| 431 | InsertItemWithTag(PDB_SymType::FuncDebugEnd); |
| 432 | InsertItemWithTag(PDB_SymType::UsingNamespace); |
| 433 | InsertItemWithTag(PDB_SymType::VTableShape); |
| 434 | InsertItemWithTag(PDB_SymType::VTable); |
| 435 | InsertItemWithTag(PDB_SymType::Custom); |
| 436 | InsertItemWithTag(PDB_SymType::Thunk); |
| 437 | InsertItemWithTag(PDB_SymType::CustomType); |
| 438 | InsertItemWithTag(PDB_SymType::ManagedType); |
| 439 | InsertItemWithTag(PDB_SymType::Dimension); |
| 440 | InsertItemWithTag(PDB_SymType::Max); |
| 441 | } |
| 442 | |
Zachary Turner | 94269a4 | 2015-02-07 01:47:14 +0000 | [diff] [blame] | 443 | template <class ExpectedType> void VerifyDyncast(PDB_SymType Tag) { |
| 444 | for (auto item = SymbolMap.begin(); item != SymbolMap.end(); ++item) { |
| 445 | EXPECT_EQ(item->first == Tag, llvm::isa<ExpectedType>(*item->second)); |
| 446 | } |
| 447 | } |
| 448 | |
| 449 | void VerifyUnknownDyncasts() { |
| 450 | for (auto item = SymbolMap.begin(); item != SymbolMap.end(); ++item) { |
| 451 | bool should_match = false; |
| 452 | if (item->first == PDB_SymType::None || item->first >= PDB_SymType::Max) |
| 453 | should_match = true; |
| 454 | |
| 455 | EXPECT_EQ(should_match, llvm::isa<PDBSymbolUnknown>(*item->second)); |
| 456 | } |
| 457 | } |
Zachary Turner | bae16b3 | 2015-02-08 20:58:09 +0000 | [diff] [blame] | 458 | |
| 459 | private: |
| 460 | std::unique_ptr<IPDBSession> Session; |
| 461 | |
| 462 | void InsertItemWithTag(PDB_SymType Tag) { |
Zachary Turner | f07ef22 | 2015-02-11 00:33:00 +0000 | [diff] [blame] | 463 | auto RawSymbol = llvm::make_unique<MockRawSymbol>(Tag); |
Zachary Turner | bae16b3 | 2015-02-08 20:58:09 +0000 | [diff] [blame] | 464 | auto Symbol = PDBSymbol::create(*Session, std::move(RawSymbol)); |
| 465 | SymbolMap.insert(std::make_pair(Tag, std::move(Symbol))); |
| 466 | } |
Zachary Turner | 94269a4 | 2015-02-07 01:47:14 +0000 | [diff] [blame] | 467 | }; |
| 468 | |
| 469 | TEST_F(PDBApiTest, Dyncast) { |
| 470 | |
| 471 | // Most of the types have a one-to-one mapping between Tag and concrete type. |
| 472 | VerifyDyncast<PDBSymbolExe>(PDB_SymType::Exe); |
| 473 | VerifyDyncast<PDBSymbolCompiland>(PDB_SymType::Compiland); |
| 474 | VerifyDyncast<PDBSymbolCompilandDetails>(PDB_SymType::CompilandDetails); |
| 475 | VerifyDyncast<PDBSymbolCompilandEnv>(PDB_SymType::CompilandEnv); |
| 476 | VerifyDyncast<PDBSymbolFunc>(PDB_SymType::Function); |
| 477 | VerifyDyncast<PDBSymbolBlock>(PDB_SymType::Block); |
| 478 | VerifyDyncast<PDBSymbolData>(PDB_SymType::Data); |
| 479 | VerifyDyncast<PDBSymbolAnnotation>(PDB_SymType::Annotation); |
| 480 | VerifyDyncast<PDBSymbolLabel>(PDB_SymType::Label); |
| 481 | VerifyDyncast<PDBSymbolPublicSymbol>(PDB_SymType::PublicSymbol); |
| 482 | VerifyDyncast<PDBSymbolTypeUDT>(PDB_SymType::UDT); |
| 483 | VerifyDyncast<PDBSymbolTypeEnum>(PDB_SymType::Enum); |
| 484 | VerifyDyncast<PDBSymbolTypeFunctionSig>(PDB_SymType::FunctionSig); |
| 485 | VerifyDyncast<PDBSymbolTypePointer>(PDB_SymType::PointerType); |
| 486 | VerifyDyncast<PDBSymbolTypeArray>(PDB_SymType::ArrayType); |
| 487 | VerifyDyncast<PDBSymbolTypeBuiltin>(PDB_SymType::BuiltinType); |
| 488 | VerifyDyncast<PDBSymbolTypeTypedef>(PDB_SymType::Typedef); |
| 489 | VerifyDyncast<PDBSymbolTypeBaseClass>(PDB_SymType::BaseClass); |
| 490 | VerifyDyncast<PDBSymbolTypeFriend>(PDB_SymType::Friend); |
| 491 | VerifyDyncast<PDBSymbolTypeFunctionArg>(PDB_SymType::FunctionArg); |
| 492 | VerifyDyncast<PDBSymbolFuncDebugStart>(PDB_SymType::FuncDebugStart); |
| 493 | VerifyDyncast<PDBSymbolFuncDebugEnd>(PDB_SymType::FuncDebugEnd); |
| 494 | VerifyDyncast<PDBSymbolUsingNamespace>(PDB_SymType::UsingNamespace); |
| 495 | VerifyDyncast<PDBSymbolTypeVTableShape>(PDB_SymType::VTableShape); |
| 496 | VerifyDyncast<PDBSymbolTypeVTable>(PDB_SymType::VTable); |
| 497 | VerifyDyncast<PDBSymbolCustom>(PDB_SymType::Custom); |
| 498 | VerifyDyncast<PDBSymbolThunk>(PDB_SymType::Thunk); |
| 499 | VerifyDyncast<PDBSymbolTypeCustom>(PDB_SymType::CustomType); |
| 500 | VerifyDyncast<PDBSymbolTypeManaged>(PDB_SymType::ManagedType); |
| 501 | VerifyDyncast<PDBSymbolTypeDimension>(PDB_SymType::Dimension); |
| 502 | |
| 503 | VerifyUnknownDyncasts(); |
| 504 | } |
Zachary Turner | 94269a4 | 2015-02-07 01:47:14 +0000 | [diff] [blame] | 505 | } // end anonymous namespace |