Zachary Turner | cffff26 | 2015-02-10 21:17:52 +0000 | [diff] [blame] | 1 | //===- DIASession.cpp - DIA implementation of IPDBSession -------*- C++ -*-===// |
| 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 | //===----------------------------------------------------------------------===// |
Zachary Turner | 819e77d | 2016-05-06 20:51:57 +0000 | [diff] [blame] | 9 | #include "llvm/DebugInfo/PDB/DIA/DIASession.h" |
Zachary Turner | be6d1e4 | 2015-02-10 23:46:48 +0000 | [diff] [blame] | 10 | #include "llvm/ADT/STLExtras.h" |
Zachary Turner | cffff26 | 2015-02-10 21:17:52 +0000 | [diff] [blame] | 11 | #include "llvm/DebugInfo/PDB/DIA/DIAEnumDebugStreams.h" |
Zachary Turner | 4b08354 | 2015-04-17 22:40:36 +0000 | [diff] [blame] | 12 | #include "llvm/DebugInfo/PDB/DIA/DIAEnumLineNumbers.h" |
Zachary Turner | a554917 | 2015-02-10 22:43:25 +0000 | [diff] [blame] | 13 | #include "llvm/DebugInfo/PDB/DIA/DIAEnumSourceFiles.h" |
Aaron Smith | 89bca9e | 2017-11-16 14:33:09 +0000 | [diff] [blame] | 14 | #include "llvm/DebugInfo/PDB/DIA/DIAEnumTables.h" |
Zachary Turner | 819e77d | 2016-05-06 20:51:57 +0000 | [diff] [blame] | 15 | #include "llvm/DebugInfo/PDB/DIA/DIAError.h" |
Zachary Turner | cffff26 | 2015-02-10 21:17:52 +0000 | [diff] [blame] | 16 | #include "llvm/DebugInfo/PDB/DIA/DIARawSymbol.h" |
Zachary Turner | cffff26 | 2015-02-10 21:17:52 +0000 | [diff] [blame] | 17 | #include "llvm/DebugInfo/PDB/DIA/DIASourceFile.h" |
Zachary Turner | 819e77d | 2016-05-06 20:51:57 +0000 | [diff] [blame] | 18 | #include "llvm/DebugInfo/PDB/DIA/DIASupport.h" |
| 19 | #include "llvm/DebugInfo/PDB/GenericError.h" |
| 20 | #include "llvm/DebugInfo/PDB/PDB.h" |
Chandler Carruth | 71f308a | 2015-02-13 09:09:03 +0000 | [diff] [blame] | 21 | #include "llvm/DebugInfo/PDB/PDBSymbolCompiland.h" |
| 22 | #include "llvm/DebugInfo/PDB/PDBSymbolExe.h" |
Zachary Turner | cffff26 | 2015-02-10 21:17:52 +0000 | [diff] [blame] | 23 | #include "llvm/Support/ConvertUTF.h" |
Zachary Turner | 3838032 | 2016-10-19 16:42:20 +0000 | [diff] [blame] | 24 | #include "llvm/Support/Format.h" |
Zachary Turner | 1690164 | 2017-04-24 17:47:24 +0000 | [diff] [blame] | 25 | #include "llvm/Support/FormatVariadic.h" |
Zachary Turner | 3838032 | 2016-10-19 16:42:20 +0000 | [diff] [blame] | 26 | #include "llvm/Support/raw_ostream.h" |
Zachary Turner | cffff26 | 2015-02-10 21:17:52 +0000 | [diff] [blame] | 27 | |
| 28 | using namespace llvm; |
Zachary Turner | ec28fc3 | 2016-05-04 20:32:13 +0000 | [diff] [blame] | 29 | using namespace llvm::pdb; |
Zachary Turner | cffff26 | 2015-02-10 21:17:52 +0000 | [diff] [blame] | 30 | |
Zachary Turner | 1690164 | 2017-04-24 17:47:24 +0000 | [diff] [blame] | 31 | template <typename... Ts> |
| 32 | static Error ErrorFromHResult(HRESULT Result, const char *Str, Ts &&... Args) { |
| 33 | SmallString<64> MessageStorage; |
| 34 | StringRef Context; |
| 35 | if (sizeof...(Args) > 0) { |
| 36 | MessageStorage = formatv(Str, std::forward<Ts>(Args)...).str(); |
| 37 | Context = MessageStorage; |
| 38 | } else |
| 39 | Context = Str; |
| 40 | |
Zachary Turner | 819e77d | 2016-05-06 20:51:57 +0000 | [diff] [blame] | 41 | switch (Result) { |
| 42 | case E_PDB_NOT_FOUND: |
Zachary Turner | 3838032 | 2016-10-19 16:42:20 +0000 | [diff] [blame] | 43 | return make_error<GenericError>(generic_error_code::invalid_path, Context); |
Zachary Turner | 819e77d | 2016-05-06 20:51:57 +0000 | [diff] [blame] | 44 | case E_PDB_FORMAT: |
Zachary Turner | 3838032 | 2016-10-19 16:42:20 +0000 | [diff] [blame] | 45 | return make_error<DIAError>(dia_error_code::invalid_file_format, Context); |
Zachary Turner | 819e77d | 2016-05-06 20:51:57 +0000 | [diff] [blame] | 46 | case E_INVALIDARG: |
Zachary Turner | 3838032 | 2016-10-19 16:42:20 +0000 | [diff] [blame] | 47 | return make_error<DIAError>(dia_error_code::invalid_parameter, Context); |
Zachary Turner | 819e77d | 2016-05-06 20:51:57 +0000 | [diff] [blame] | 48 | case E_UNEXPECTED: |
Zachary Turner | 3838032 | 2016-10-19 16:42:20 +0000 | [diff] [blame] | 49 | return make_error<DIAError>(dia_error_code::already_loaded, Context); |
Zachary Turner | 819e77d | 2016-05-06 20:51:57 +0000 | [diff] [blame] | 50 | case E_PDB_INVALID_SIG: |
| 51 | case E_PDB_INVALID_AGE: |
Zachary Turner | 3838032 | 2016-10-19 16:42:20 +0000 | [diff] [blame] | 52 | return make_error<DIAError>(dia_error_code::debug_info_mismatch, Context); |
| 53 | default: { |
| 54 | std::string S; |
| 55 | raw_string_ostream OS(S); |
| 56 | OS << "HRESULT: " << format_hex(static_cast<DWORD>(Result), 10, true) |
| 57 | << ": " << Context; |
| 58 | return make_error<DIAError>(dia_error_code::unspecified, OS.str()); |
| 59 | } |
Zachary Turner | 819e77d | 2016-05-06 20:51:57 +0000 | [diff] [blame] | 60 | } |
| 61 | } |
| 62 | |
Reid Kleckner | fb58be8 | 2016-10-12 21:51:14 +0000 | [diff] [blame] | 63 | static Error LoadDIA(CComPtr<IDiaDataSource> &DiaDataSource) { |
Nico Weber | 73853ab | 2016-04-01 22:21:51 +0000 | [diff] [blame] | 64 | if (SUCCEEDED(CoCreateInstance(CLSID_DiaSource, nullptr, CLSCTX_INPROC_SERVER, |
| 65 | IID_IDiaDataSource, |
| 66 | reinterpret_cast<LPVOID *>(&DiaDataSource)))) |
Zachary Turner | 819e77d | 2016-05-06 20:51:57 +0000 | [diff] [blame] | 67 | return Error::success(); |
Nico Weber | 73853ab | 2016-04-01 22:21:51 +0000 | [diff] [blame] | 68 | |
Zachary Turner | 819e77d | 2016-05-06 20:51:57 +0000 | [diff] [blame] | 69 | // If the CoCreateInstance call above failed, msdia*.dll is not registered. |
| 70 | // Try loading the DLL corresponding to the #included DIA SDK. |
Nico Weber | 73853ab | 2016-04-01 22:21:51 +0000 | [diff] [blame] | 71 | #if !defined(_MSC_VER) |
Zachary Turner | 819e77d | 2016-05-06 20:51:57 +0000 | [diff] [blame] | 72 | return llvm::make_error<GenericError>( |
| 73 | "DIA is only supported when using MSVC."); |
Reid Kleckner | fb58be8 | 2016-10-12 21:51:14 +0000 | [diff] [blame] | 74 | #else |
Nico Weber | 73853ab | 2016-04-01 22:21:51 +0000 | [diff] [blame] | 75 | const wchar_t *msdia_dll = nullptr; |
Reid Kleckner | fb58be8 | 2016-10-12 21:51:14 +0000 | [diff] [blame] | 76 | #if _MSC_VER >= 1900 && _MSC_VER < 2000 |
Nico Weber | 73853ab | 2016-04-01 22:21:51 +0000 | [diff] [blame] | 77 | msdia_dll = L"msdia140.dll"; // VS2015 |
Reid Kleckner | fb58be8 | 2016-10-12 21:51:14 +0000 | [diff] [blame] | 78 | #elif _MSC_VER >= 1800 |
Nico Weber | 73853ab | 2016-04-01 22:21:51 +0000 | [diff] [blame] | 79 | msdia_dll = L"msdia120.dll"; // VS2013 |
| 80 | #else |
| 81 | #error "Unknown Visual Studio version." |
| 82 | #endif |
Zachary Turner | 23ee87b | 2016-04-19 17:36:58 +0000 | [diff] [blame] | 83 | |
Zachary Turner | 819e77d | 2016-05-06 20:51:57 +0000 | [diff] [blame] | 84 | HRESULT HR; |
| 85 | if (FAILED(HR = NoRegCoCreate(msdia_dll, CLSID_DiaSource, IID_IDiaDataSource, |
| 86 | reinterpret_cast<LPVOID *>(&DiaDataSource)))) |
Zachary Turner | 3838032 | 2016-10-19 16:42:20 +0000 | [diff] [blame] | 87 | return ErrorFromHResult(HR, "Calling NoRegCoCreate"); |
Zachary Turner | 819e77d | 2016-05-06 20:51:57 +0000 | [diff] [blame] | 88 | return Error::success(); |
Reid Kleckner | fb58be8 | 2016-10-12 21:51:14 +0000 | [diff] [blame] | 89 | #endif |
Nico Weber | 73853ab | 2016-04-01 22:21:51 +0000 | [diff] [blame] | 90 | } |
Zachary Turner | cffff26 | 2015-02-10 21:17:52 +0000 | [diff] [blame] | 91 | |
| 92 | DIASession::DIASession(CComPtr<IDiaSession> DiaSession) : Session(DiaSession) {} |
| 93 | |
Zachary Turner | 819e77d | 2016-05-06 20:51:57 +0000 | [diff] [blame] | 94 | Error DIASession::createFromPdb(StringRef Path, |
| 95 | std::unique_ptr<IPDBSession> &Session) { |
Zachary Turner | ccf0415 | 2015-02-28 20:23:18 +0000 | [diff] [blame] | 96 | CComPtr<IDiaDataSource> DiaDataSource; |
| 97 | CComPtr<IDiaSession> DiaSession; |
Zachary Turner | cffff26 | 2015-02-10 21:17:52 +0000 | [diff] [blame] | 98 | |
| 99 | // We assume that CoInitializeEx has already been called by the executable. |
Zachary Turner | 819e77d | 2016-05-06 20:51:57 +0000 | [diff] [blame] | 100 | if (auto E = LoadDIA(DiaDataSource)) |
| 101 | return E; |
Zachary Turner | cffff26 | 2015-02-10 21:17:52 +0000 | [diff] [blame] | 102 | |
| 103 | llvm::SmallVector<UTF16, 128> Path16; |
| 104 | if (!llvm::convertUTF8ToUTF16String(Path, Path16)) |
Zachary Turner | 819e77d | 2016-05-06 20:51:57 +0000 | [diff] [blame] | 105 | return make_error<GenericError>(generic_error_code::invalid_path); |
Zachary Turner | cffff26 | 2015-02-10 21:17:52 +0000 | [diff] [blame] | 106 | |
| 107 | const wchar_t *Path16Str = reinterpret_cast<const wchar_t*>(Path16.data()); |
Zachary Turner | 819e77d | 2016-05-06 20:51:57 +0000 | [diff] [blame] | 108 | HRESULT HR; |
Zachary Turner | 1690164 | 2017-04-24 17:47:24 +0000 | [diff] [blame] | 109 | if (FAILED(HR = DiaDataSource->loadDataFromPdb(Path16Str))) { |
| 110 | return ErrorFromHResult(HR, "Calling loadDataFromPdb {0}", Path); |
| 111 | } |
Zachary Turner | cffff26 | 2015-02-10 21:17:52 +0000 | [diff] [blame] | 112 | |
Zachary Turner | 819e77d | 2016-05-06 20:51:57 +0000 | [diff] [blame] | 113 | if (FAILED(HR = DiaDataSource->openSession(&DiaSession))) |
Zachary Turner | 3838032 | 2016-10-19 16:42:20 +0000 | [diff] [blame] | 114 | return ErrorFromHResult(HR, "Calling openSession"); |
Zachary Turner | ccf0415 | 2015-02-28 20:23:18 +0000 | [diff] [blame] | 115 | |
| 116 | Session.reset(new DIASession(DiaSession)); |
Zachary Turner | 819e77d | 2016-05-06 20:51:57 +0000 | [diff] [blame] | 117 | return Error::success(); |
Zachary Turner | cffff26 | 2015-02-10 21:17:52 +0000 | [diff] [blame] | 118 | } |
| 119 | |
Zachary Turner | 819e77d | 2016-05-06 20:51:57 +0000 | [diff] [blame] | 120 | Error DIASession::createFromExe(StringRef Path, |
| 121 | std::unique_ptr<IPDBSession> &Session) { |
Zachary Turner | 4b08354 | 2015-04-17 22:40:36 +0000 | [diff] [blame] | 122 | CComPtr<IDiaDataSource> DiaDataSource; |
| 123 | CComPtr<IDiaSession> DiaSession; |
| 124 | |
| 125 | // We assume that CoInitializeEx has already been called by the executable. |
Zachary Turner | 819e77d | 2016-05-06 20:51:57 +0000 | [diff] [blame] | 126 | if (auto EC = LoadDIA(DiaDataSource)) |
| 127 | return EC; |
Zachary Turner | 4b08354 | 2015-04-17 22:40:36 +0000 | [diff] [blame] | 128 | |
| 129 | llvm::SmallVector<UTF16, 128> Path16; |
| 130 | if (!llvm::convertUTF8ToUTF16String(Path, Path16)) |
Zachary Turner | 819e77d | 2016-05-06 20:51:57 +0000 | [diff] [blame] | 131 | return make_error<GenericError>(generic_error_code::invalid_path, Path); |
Zachary Turner | 4b08354 | 2015-04-17 22:40:36 +0000 | [diff] [blame] | 132 | |
| 133 | const wchar_t *Path16Str = reinterpret_cast<const wchar_t *>(Path16.data()); |
Zachary Turner | 819e77d | 2016-05-06 20:51:57 +0000 | [diff] [blame] | 134 | HRESULT HR; |
| 135 | if (FAILED(HR = DiaDataSource->loadDataForExe(Path16Str, nullptr, nullptr))) |
Zachary Turner | 3838032 | 2016-10-19 16:42:20 +0000 | [diff] [blame] | 136 | return ErrorFromHResult(HR, "Calling loadDataForExe"); |
Zachary Turner | 4b08354 | 2015-04-17 22:40:36 +0000 | [diff] [blame] | 137 | |
Zachary Turner | 819e77d | 2016-05-06 20:51:57 +0000 | [diff] [blame] | 138 | if (FAILED(HR = DiaDataSource->openSession(&DiaSession))) |
Zachary Turner | 3838032 | 2016-10-19 16:42:20 +0000 | [diff] [blame] | 139 | return ErrorFromHResult(HR, "Calling openSession"); |
Zachary Turner | 4b08354 | 2015-04-17 22:40:36 +0000 | [diff] [blame] | 140 | |
| 141 | Session.reset(new DIASession(DiaSession)); |
Zachary Turner | 819e77d | 2016-05-06 20:51:57 +0000 | [diff] [blame] | 142 | return Error::success(); |
Zachary Turner | 4b08354 | 2015-04-17 22:40:36 +0000 | [diff] [blame] | 143 | } |
| 144 | |
Zachary Turner | cffff26 | 2015-02-10 21:17:52 +0000 | [diff] [blame] | 145 | uint64_t DIASession::getLoadAddress() const { |
| 146 | uint64_t LoadAddress; |
| 147 | bool success = (S_OK == Session->get_loadAddress(&LoadAddress)); |
| 148 | return (success) ? LoadAddress : 0; |
| 149 | } |
| 150 | |
Aaron Smith | 89a19ac | 2018-02-23 00:02:27 +0000 | [diff] [blame^] | 151 | bool DIASession::setLoadAddress(uint64_t Address) { |
| 152 | return (S_OK == Session->put_loadAddress(Address)); |
Zachary Turner | cffff26 | 2015-02-10 21:17:52 +0000 | [diff] [blame] | 153 | } |
| 154 | |
Adrian McCarthy | 6a4b080 | 2017-06-22 18:42:23 +0000 | [diff] [blame] | 155 | std::unique_ptr<PDBSymbolExe> DIASession::getGlobalScope() { |
Zachary Turner | cffff26 | 2015-02-10 21:17:52 +0000 | [diff] [blame] | 156 | CComPtr<IDiaSymbol> GlobalScope; |
| 157 | if (S_OK != Session->get_globalScope(&GlobalScope)) |
| 158 | return nullptr; |
| 159 | |
Zachary Turner | be6d1e4 | 2015-02-10 23:46:48 +0000 | [diff] [blame] | 160 | auto RawSymbol = llvm::make_unique<DIARawSymbol>(*this, GlobalScope); |
Zachary Turner | cffff26 | 2015-02-10 21:17:52 +0000 | [diff] [blame] | 161 | auto PdbSymbol(PDBSymbol::create(*this, std::move(RawSymbol))); |
| 162 | std::unique_ptr<PDBSymbolExe> ExeSymbol( |
| 163 | static_cast<PDBSymbolExe *>(PdbSymbol.release())); |
| 164 | return ExeSymbol; |
| 165 | } |
| 166 | |
| 167 | std::unique_ptr<PDBSymbol> DIASession::getSymbolById(uint32_t SymbolId) const { |
| 168 | CComPtr<IDiaSymbol> LocatedSymbol; |
| 169 | if (S_OK != Session->symbolById(SymbolId, &LocatedSymbol)) |
| 170 | return nullptr; |
| 171 | |
Zachary Turner | be6d1e4 | 2015-02-10 23:46:48 +0000 | [diff] [blame] | 172 | auto RawSymbol = llvm::make_unique<DIARawSymbol>(*this, LocatedSymbol); |
Zachary Turner | cffff26 | 2015-02-10 21:17:52 +0000 | [diff] [blame] | 173 | return PDBSymbol::create(*this, std::move(RawSymbol)); |
| 174 | } |
| 175 | |
Zachary Turner | 4b08354 | 2015-04-17 22:40:36 +0000 | [diff] [blame] | 176 | std::unique_ptr<PDBSymbol> |
Zachary Turner | e5cb269 | 2015-05-01 20:24:26 +0000 | [diff] [blame] | 177 | DIASession::findSymbolByAddress(uint64_t Address, PDB_SymType Type) const { |
| 178 | enum SymTagEnum EnumVal = static_cast<enum SymTagEnum>(Type); |
| 179 | |
Zachary Turner | 4b08354 | 2015-04-17 22:40:36 +0000 | [diff] [blame] | 180 | CComPtr<IDiaSymbol> Symbol; |
Zachary Turner | e5cb269 | 2015-05-01 20:24:26 +0000 | [diff] [blame] | 181 | if (S_OK != Session->findSymbolByVA(Address, EnumVal, &Symbol)) { |
| 182 | ULONGLONG LoadAddr = 0; |
| 183 | if (S_OK != Session->get_loadAddress(&LoadAddr)) |
| 184 | return nullptr; |
| 185 | DWORD RVA = static_cast<DWORD>(Address - LoadAddr); |
| 186 | if (S_OK != Session->findSymbolByRVA(RVA, EnumVal, &Symbol)) |
| 187 | return nullptr; |
| 188 | } |
Zachary Turner | 4b08354 | 2015-04-17 22:40:36 +0000 | [diff] [blame] | 189 | auto RawSymbol = llvm::make_unique<DIARawSymbol>(*this, Symbol); |
| 190 | return PDBSymbol::create(*this, std::move(RawSymbol)); |
| 191 | } |
| 192 | |
| 193 | std::unique_ptr<IPDBEnumLineNumbers> |
Zachary Turner | 43ec3af | 2016-02-18 18:47:29 +0000 | [diff] [blame] | 194 | DIASession::findLineNumbers(const PDBSymbolCompiland &Compiland, |
| 195 | const IPDBSourceFile &File) const { |
| 196 | const DIARawSymbol &RawCompiland = |
| 197 | static_cast<const DIARawSymbol &>(Compiland.getRawSymbol()); |
| 198 | const DIASourceFile &RawFile = static_cast<const DIASourceFile &>(File); |
| 199 | |
| 200 | CComPtr<IDiaEnumLineNumbers> LineNumbers; |
| 201 | if (S_OK != |
| 202 | Session->findLines(RawCompiland.getDiaSymbol(), RawFile.getDiaFile(), |
| 203 | &LineNumbers)) |
| 204 | return nullptr; |
| 205 | |
| 206 | return llvm::make_unique<DIAEnumLineNumbers>(LineNumbers); |
| 207 | } |
| 208 | |
| 209 | std::unique_ptr<IPDBEnumLineNumbers> |
Zachary Turner | 4b08354 | 2015-04-17 22:40:36 +0000 | [diff] [blame] | 210 | DIASession::findLineNumbersByAddress(uint64_t Address, uint32_t Length) const { |
| 211 | CComPtr<IDiaEnumLineNumbers> LineNumbers; |
| 212 | if (S_OK != Session->findLinesByVA(Address, Length, &LineNumbers)) |
| 213 | return nullptr; |
| 214 | |
| 215 | return llvm::make_unique<DIAEnumLineNumbers>(LineNumbers); |
| 216 | } |
| 217 | |
Zachary Turner | 43ec3af | 2016-02-18 18:47:29 +0000 | [diff] [blame] | 218 | std::unique_ptr<IPDBEnumSourceFiles> |
| 219 | DIASession::findSourceFiles(const PDBSymbolCompiland *Compiland, |
| 220 | llvm::StringRef Pattern, |
| 221 | PDB_NameSearchFlags Flags) const { |
| 222 | IDiaSymbol *DiaCompiland = nullptr; |
| 223 | CComBSTR Utf16Pattern; |
| 224 | if (!Pattern.empty()) |
| 225 | Utf16Pattern = CComBSTR(Pattern.data()); |
| 226 | |
| 227 | if (Compiland) |
| 228 | DiaCompiland = static_cast<const DIARawSymbol &>(Compiland->getRawSymbol()) |
| 229 | .getDiaSymbol(); |
| 230 | |
| 231 | Flags = static_cast<PDB_NameSearchFlags>( |
| 232 | Flags | PDB_NameSearchFlags::NS_FileNameExtMatch); |
| 233 | CComPtr<IDiaEnumSourceFiles> SourceFiles; |
| 234 | if (S_OK != |
| 235 | Session->findFile(DiaCompiland, Utf16Pattern.m_str, Flags, &SourceFiles)) |
| 236 | return nullptr; |
| 237 | return llvm::make_unique<DIAEnumSourceFiles>(*this, SourceFiles); |
| 238 | } |
| 239 | |
| 240 | std::unique_ptr<IPDBSourceFile> |
| 241 | DIASession::findOneSourceFile(const PDBSymbolCompiland *Compiland, |
| 242 | llvm::StringRef Pattern, |
| 243 | PDB_NameSearchFlags Flags) const { |
| 244 | auto SourceFiles = findSourceFiles(Compiland, Pattern, Flags); |
| 245 | if (!SourceFiles || SourceFiles->getChildCount() == 0) |
| 246 | return nullptr; |
| 247 | return SourceFiles->getNext(); |
| 248 | } |
| 249 | |
| 250 | std::unique_ptr<IPDBEnumChildren<PDBSymbolCompiland>> |
| 251 | DIASession::findCompilandsForSourceFile(llvm::StringRef Pattern, |
| 252 | PDB_NameSearchFlags Flags) const { |
| 253 | auto File = findOneSourceFile(nullptr, Pattern, Flags); |
| 254 | if (!File) |
| 255 | return nullptr; |
| 256 | return File->getCompilands(); |
| 257 | } |
| 258 | |
| 259 | std::unique_ptr<PDBSymbolCompiland> |
| 260 | DIASession::findOneCompilandForSourceFile(llvm::StringRef Pattern, |
| 261 | PDB_NameSearchFlags Flags) const { |
| 262 | auto Compilands = findCompilandsForSourceFile(Pattern, Flags); |
| 263 | if (!Compilands || Compilands->getChildCount() == 0) |
| 264 | return nullptr; |
| 265 | return Compilands->getNext(); |
| 266 | } |
| 267 | |
Zachary Turner | a554917 | 2015-02-10 22:43:25 +0000 | [diff] [blame] | 268 | std::unique_ptr<IPDBEnumSourceFiles> DIASession::getAllSourceFiles() const { |
| 269 | CComPtr<IDiaEnumSourceFiles> Files; |
| 270 | if (S_OK != Session->findFile(nullptr, nullptr, nsNone, &Files)) |
| 271 | return nullptr; |
| 272 | |
Zachary Turner | be6d1e4 | 2015-02-10 23:46:48 +0000 | [diff] [blame] | 273 | return llvm::make_unique<DIAEnumSourceFiles>(*this, Files); |
Zachary Turner | a554917 | 2015-02-10 22:43:25 +0000 | [diff] [blame] | 274 | } |
| 275 | |
| 276 | std::unique_ptr<IPDBEnumSourceFiles> DIASession::getSourceFilesForCompiland( |
| 277 | const PDBSymbolCompiland &Compiland) const { |
| 278 | CComPtr<IDiaEnumSourceFiles> Files; |
| 279 | |
| 280 | const DIARawSymbol &RawSymbol = |
| 281 | static_cast<const DIARawSymbol &>(Compiland.getRawSymbol()); |
| 282 | if (S_OK != |
| 283 | Session->findFile(RawSymbol.getDiaSymbol(), nullptr, nsNone, &Files)) |
| 284 | return nullptr; |
| 285 | |
Zachary Turner | be6d1e4 | 2015-02-10 23:46:48 +0000 | [diff] [blame] | 286 | return llvm::make_unique<DIAEnumSourceFiles>(*this, Files); |
Zachary Turner | a554917 | 2015-02-10 22:43:25 +0000 | [diff] [blame] | 287 | } |
| 288 | |
Zachary Turner | cffff26 | 2015-02-10 21:17:52 +0000 | [diff] [blame] | 289 | std::unique_ptr<IPDBSourceFile> |
| 290 | DIASession::getSourceFileById(uint32_t FileId) const { |
| 291 | CComPtr<IDiaSourceFile> LocatedFile; |
| 292 | if (S_OK != Session->findFileById(FileId, &LocatedFile)) |
| 293 | return nullptr; |
| 294 | |
Zachary Turner | be6d1e4 | 2015-02-10 23:46:48 +0000 | [diff] [blame] | 295 | return llvm::make_unique<DIASourceFile>(*this, LocatedFile); |
Zachary Turner | cffff26 | 2015-02-10 21:17:52 +0000 | [diff] [blame] | 296 | } |
| 297 | |
| 298 | std::unique_ptr<IPDBEnumDataStreams> DIASession::getDebugStreams() const { |
| 299 | CComPtr<IDiaEnumDebugStreams> DiaEnumerator; |
| 300 | if (S_OK != Session->getEnumDebugStreams(&DiaEnumerator)) |
| 301 | return nullptr; |
| 302 | |
Zachary Turner | be6d1e4 | 2015-02-10 23:46:48 +0000 | [diff] [blame] | 303 | return llvm::make_unique<DIAEnumDebugStreams>(DiaEnumerator); |
Zachary Turner | cffff26 | 2015-02-10 21:17:52 +0000 | [diff] [blame] | 304 | } |
Aaron Smith | 89bca9e | 2017-11-16 14:33:09 +0000 | [diff] [blame] | 305 | |
| 306 | std::unique_ptr<IPDBEnumTables> DIASession::getEnumTables() const { |
| 307 | CComPtr<IDiaEnumTables> DiaEnumerator; |
| 308 | if (S_OK != Session->getEnumTables(&DiaEnumerator)) |
| 309 | return nullptr; |
| 310 | |
| 311 | return llvm::make_unique<DIAEnumTables>(DiaEnumerator); |
| 312 | } |