28 std::unique_ptr<IPDBSession> &Session) {
29 CComPtr<IDiaDataSource> DiaDataSource;
30 CComPtr<IDiaSession> DiaSession;
33 HRESULT Result = ::CoCreateInstance(
34 CLSID_DiaSource,
nullptr, CLSCTX_INPROC_SERVER, IID_IDiaDataSource,
35 reinterpret_cast<LPVOID *>(&DiaDataSource));
43 const wchar_t *Path16Str =
reinterpret_cast<const wchar_t*
>(Path16.
data());
44 if (FAILED(Result = DiaDataSource->loadDataFromPdb(Path16Str))) {
45 if (Result == E_PDB_NOT_FOUND)
47 else if (Result == E_PDB_FORMAT)
49 else if (Result == E_INVALIDARG)
51 else if (Result == E_UNEXPECTED)
57 if (FAILED(Result = DiaDataSource->openSession(&DiaSession))) {
58 if (Result == E_OUTOFMEMORY)
69 std::unique_ptr<IPDBSession> &Session) {
70 CComPtr<IDiaDataSource> DiaDataSource;
71 CComPtr<IDiaSession> DiaSession;
74 HRESULT Result = ::CoCreateInstance(
75 CLSID_DiaSource,
nullptr, CLSCTX_INPROC_SERVER, IID_IDiaDataSource,
76 reinterpret_cast<LPVOID *>(&DiaDataSource));
84 const wchar_t *Path16Str =
reinterpret_cast<const wchar_t *
>(Path16.
data());
86 DiaDataSource->loadDataForExe(Path16Str,
nullptr,
nullptr))) {
87 if (Result == E_PDB_NOT_FOUND)
89 else if (Result == E_PDB_FORMAT)
91 else if (Result == E_PDB_INVALID_SIG || Result == E_PDB_INVALID_AGE)
93 else if (Result == E_INVALIDARG)
95 else if (Result == E_UNEXPECTED)
101 if (FAILED(Result = DiaDataSource->openSession(&DiaSession))) {
102 if (Result == E_OUTOFMEMORY)
113 uint64_t LoadAddress;
114 bool success = (S_OK == Session->get_loadAddress(&LoadAddress));
115 return (success) ? LoadAddress : 0;
119 Session->put_loadAddress(Address);
123 CComPtr<IDiaSymbol> GlobalScope;
124 if (S_OK != Session->get_globalScope(&GlobalScope))
127 auto RawSymbol = llvm::make_unique<DIARawSymbol>(*
this, GlobalScope);
129 std::unique_ptr<PDBSymbolExe> ExeSymbol(
130 static_cast<PDBSymbolExe *>(PdbSymbol.release()));
135 CComPtr<IDiaSymbol> LocatedSymbol;
136 if (S_OK != Session->symbolById(SymbolId, &LocatedSymbol))
139 auto RawSymbol = llvm::make_unique<DIARawSymbol>(*
this, LocatedSymbol);
143 std::unique_ptr<PDBSymbol>
145 enum SymTagEnum EnumVal =
static_cast<enum SymTagEnum
>(
Type);
147 CComPtr<IDiaSymbol>
Symbol;
148 if (S_OK != Session->findSymbolByVA(Address, EnumVal, &Symbol)) {
149 ULONGLONG LoadAddr = 0;
150 if (S_OK != Session->get_loadAddress(&LoadAddr))
152 DWORD RVA =
static_cast<DWORD
>(Address - LoadAddr);
153 if (S_OK != Session->findSymbolByRVA(RVA, EnumVal, &Symbol))
156 auto RawSymbol = llvm::make_unique<DIARawSymbol>(*
this,
Symbol);
160 std::unique_ptr<IPDBEnumLineNumbers>
163 if (S_OK != Session->findLinesByVA(Address, Length, &LineNumbers))
166 return llvm::make_unique<DIAEnumLineNumbers>(
LineNumbers);
170 CComPtr<IDiaEnumSourceFiles> Files;
171 if (S_OK != Session->findFile(
nullptr,
nullptr, nsNone, &Files))
174 return llvm::make_unique<DIAEnumSourceFiles>(*
this, Files);
179 CComPtr<IDiaEnumSourceFiles> Files;
184 Session->findFile(RawSymbol.
getDiaSymbol(),
nullptr, nsNone, &Files))
187 return llvm::make_unique<DIAEnumSourceFiles>(*
this, Files);
190 std::unique_ptr<IPDBSourceFile>
192 CComPtr<IDiaSourceFile> LocatedFile;
193 if (S_OK != Session->findFileById(FileId, &LocatedFile))
196 return llvm::make_unique<DIASourceFile>(*
this, LocatedFile);
200 CComPtr<IDiaEnumDebugStreams> DiaEnumerator;
201 if (S_OK != Session->getEnumDebugStreams(&DiaEnumerator))
204 return llvm::make_unique<DIAEnumDebugStreams>(DiaEnumerator);
const IPDBRawSymbol & getRawSymbol() const
std::unique_ptr< IPDBEnumSourceFiles > getAllSourceFiles() const override
std::unique_ptr< PDBSymbol > getSymbolById(uint32_t SymbolId) const override
std::unique_ptr< PDBSymbol > findSymbolByAddress(uint64_t Address, PDB_SymType Type) const override
static std::unique_ptr< PDBSymbol > create(const IPDBSession &PDBSession, std::unique_ptr< IPDBRawSymbol > Symbol)
std::unique_ptr< IPDBSourceFile > getSourceFileById(uint32_t FileId) const override
bool convertUTF8ToUTF16String(StringRef SrcUTF8, SmallVectorImpl< UTF16 > &DstUTF16)
CComPtr< IDiaSymbol > getDiaSymbol() const
The instances of the Type class are immutable: once they are created, they are never changed...
void setLoadAddress(uint64_t Address) override
std::unique_ptr< IPDBEnumLineNumbers > findLineNumbersByAddress(uint64_t Address, uint32_t Length) const override
std::unique_ptr< IPDBEnumSourceFiles > getSourceFilesForCompiland(const PDBSymbolCompiland &Compiland) const override
static PDB_ErrorCode createFromPdb(StringRef Path, std::unique_ptr< IPDBSession > &Session)
std::unique_ptr< IPDBEnumDataStreams > getDebugStreams() const override
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
PDB_SymType
These values correspond to the SymTagEnum enumeration, and are documented here: https://msdn.microsoft.com/en-us/library/bkedss5f.aspx.
uint64_t getLoadAddress() const override
pointer data()
Return a pointer to the vector's buffer, even if empty().
std::unique_ptr< PDBSymbolExe > getGlobalScope() const override
DIASession(CComPtr< IDiaSession > DiaSession)
StringRef - Represent a constant reference to a string, i.e.
static PDB_ErrorCode createFromExe(StringRef Path, std::unique_ptr< IPDBSession > &Session)