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