27 using namespace llvm::pdb;
39 case E_PDB_INVALID_SIG:
40 case E_PDB_INVALID_AGE:
45 OS <<
"HRESULT: " <<
format_hex(static_cast<DWORD>(Result), 10,
true)
53 if (SUCCEEDED(CoCreateInstance(CLSID_DiaSource,
nullptr, CLSCTX_INPROC_SERVER,
55 reinterpret_cast<LPVOID *>(&DiaDataSource))))
60 #if !defined(_MSC_VER)
61 return llvm::make_error<GenericError>(
62 "DIA is only supported when using MSVC.");
64 const wchar_t *msdia_dll =
nullptr;
65 #if _MSC_VER >= 1900 && _MSC_VER < 2000
66 msdia_dll =
L"msdia140.dll";
67 #elif _MSC_VER >= 1800
68 msdia_dll =
L"msdia120.dll";
70 #error "Unknown Visual Studio version."
74 if (FAILED(HR = NoRegCoCreate(msdia_dll, CLSID_DiaSource, IID_IDiaDataSource,
75 reinterpret_cast<LPVOID *>(&DiaDataSource))))
84 std::unique_ptr<IPDBSession> &Session) {
85 CComPtr<IDiaDataSource> DiaDataSource;
86 CComPtr<IDiaSession> DiaSession;
96 const wchar_t *Path16Str =
reinterpret_cast<const wchar_t*
>(Path16.
data());
98 if (FAILED(HR = DiaDataSource->loadDataFromPdb(Path16Str)))
101 if (FAILED(HR = DiaDataSource->openSession(&DiaSession)))
109 std::unique_ptr<IPDBSession> &Session) {
110 CComPtr<IDiaDataSource> DiaDataSource;
111 CComPtr<IDiaSession> DiaSession;
114 if (
auto EC =
LoadDIA(DiaDataSource))
121 const wchar_t *Path16Str =
reinterpret_cast<const wchar_t *
>(Path16.
data());
123 if (FAILED(HR = DiaDataSource->loadDataForExe(Path16Str,
nullptr,
nullptr)))
126 if (FAILED(HR = DiaDataSource->openSession(&DiaSession)))
134 uint64_t LoadAddress;
135 bool success = (S_OK == Session->get_loadAddress(&LoadAddress));
136 return (success) ? LoadAddress : 0;
140 Session->put_loadAddress(Address);
144 CComPtr<IDiaSymbol> GlobalScope;
145 if (S_OK != Session->get_globalScope(&GlobalScope))
148 auto RawSymbol = llvm::make_unique<DIARawSymbol>(*
this, GlobalScope);
150 std::unique_ptr<PDBSymbolExe> ExeSymbol(
151 static_cast<PDBSymbolExe *>(PdbSymbol.release()));
156 CComPtr<IDiaSymbol> LocatedSymbol;
157 if (S_OK != Session->symbolById(SymbolId, &LocatedSymbol))
160 auto RawSymbol = llvm::make_unique<DIARawSymbol>(*
this, LocatedSymbol);
164 std::unique_ptr<PDBSymbol>
166 enum SymTagEnum EnumVal =
static_cast<enum SymTagEnum
>(
Type);
168 CComPtr<IDiaSymbol>
Symbol;
169 if (S_OK != Session->findSymbolByVA(Address, EnumVal, &Symbol)) {
170 ULONGLONG LoadAddr = 0;
171 if (S_OK != Session->get_loadAddress(&LoadAddr))
173 DWORD RVA =
static_cast<DWORD>(Address - LoadAddr);
174 if (S_OK != Session->findSymbolByRVA(RVA, EnumVal, &Symbol))
177 auto RawSymbol = llvm::make_unique<DIARawSymbol>(*
this,
Symbol);
181 std::unique_ptr<IPDBEnumLineNumbers>
194 return llvm::make_unique<DIAEnumLineNumbers>(
LineNumbers);
197 std::unique_ptr<IPDBEnumLineNumbers>
200 if (S_OK != Session->findLinesByVA(Address, Length, &LineNumbers))
203 return llvm::make_unique<DIAEnumLineNumbers>(
LineNumbers);
206 std::unique_ptr<IPDBEnumSourceFiles>
210 IDiaSymbol *DiaCompiland =
nullptr;
211 CComBSTR Utf16Pattern;
212 if (!Pattern.
empty())
213 Utf16Pattern = CComBSTR(Pattern.
data());
223 Session->findFile(DiaCompiland, Utf16Pattern.m_str, Flags, &SourceFiles))
225 return llvm::make_unique<DIAEnumSourceFiles>(*
this,
SourceFiles);
228 std::unique_ptr<IPDBSourceFile>
238 std::unique_ptr<IPDBEnumChildren<PDBSymbolCompiland>>
244 return File->getCompilands();
247 std::unique_ptr<PDBSymbolCompiland>
251 if (!Compilands || Compilands->getChildCount() == 0)
253 return Compilands->getNext();
257 CComPtr<IDiaEnumSourceFiles> Files;
258 if (S_OK != Session->findFile(
nullptr,
nullptr, nsNone, &Files))
261 return llvm::make_unique<DIAEnumSourceFiles>(*
this, Files);
266 CComPtr<IDiaEnumSourceFiles> Files;
271 Session->findFile(RawSymbol.
getDiaSymbol(),
nullptr, nsNone, &Files))
274 return llvm::make_unique<DIAEnumSourceFiles>(*
this, Files);
277 std::unique_ptr<IPDBSourceFile>
279 CComPtr<IDiaSourceFile> LocatedFile;
280 if (S_OK != Session->findFileById(FileId, &LocatedFile))
283 return llvm::make_unique<DIASourceFile>(*
this, LocatedFile);
287 CComPtr<IDiaEnumDebugStreams> DiaEnumerator;
288 if (S_OK != Session->getEnumDebugStreams(&DiaEnumerator))
291 return llvm::make_unique<DIAEnumDebugStreams>(DiaEnumerator);
FormattedNumber format_hex(uint64_t N, unsigned Width, bool Upper=false)
format_hex - Output N as a fixed width hexadecimal.
PDB_NameSearchFlags
Defines flags used for enumerating child symbols.
std::unique_ptr< PDBSymbol > findSymbolByAddress(uint64_t Address, PDB_SymType Type) const override
std::unique_ptr< IPDBEnumChildren< PDBSymbolCompiland > > findCompilandsForSourceFile(llvm::StringRef Pattern, PDB_NameSearchFlags Flags) const override
CComPtr< IDiaSourceFile > getDiaFile() const
IPDBSourceFile defines an interface used to represent source files whose information are stored in th...
std::unique_ptr< IPDBSourceFile > getSourceFileById(uint32_t FileId) const override
struct fuzzer::@269 Flags
static std::unique_ptr< PDBSymbol > create(const IPDBSession &PDBSession, std::unique_ptr< IPDBRawSymbol > Symbol)
std::unique_ptr< IPDBEnumSourceFiles > findSourceFiles(const PDBSymbolCompiland *Compiland, llvm::StringRef Pattern, PDB_NameSearchFlags Flags) const override
static Error createFromPdb(StringRef Path, std::unique_ptr< IPDBSession > &Session)
std::unique_ptr< IPDBSourceFile > findOneSourceFile(const PDBSymbolCompiland *Compiland, llvm::StringRef Pattern, PDB_NameSearchFlags Flags) const override
std::unique_ptr< IPDBEnumLineNumbers > findLineNumbersByAddress(uint64_t Address, uint32_t Length) const override
bool convertUTF8ToUTF16String(StringRef SrcUTF8, SmallVectorImpl< UTF16 > &DstUTF16)
Converts a UTF-8 string into a UTF-16 string with native endianness.
static GCRegistry::Add< CoreCLRGC > E("coreclr","CoreCLR-compatible GC")
PDB_SymType
These values correspond to the SymTagEnum enumeration, and are documented here: https://msdn.microsoft.com/en-us/library/bkedss5f.aspx.
std::unique_ptr< IPDBEnumSourceFiles > getSourceFilesForCompiland(const PDBSymbolCompiland &Compiland) const override
The instances of the Type class are immutable: once they are created, they are never changed...
std::unique_ptr< IPDBEnumSourceFiles > getAllSourceFiles() const override
DIASession(CComPtr< IDiaSession > DiaSession)
std::unique_ptr< IPDBEnumLineNumbers > findLineNumbers(const PDBSymbolCompiland &Compiland, const IPDBSourceFile &File) const override
std::string & str()
Flushes the stream contents to the target string and returns the string's reference.
CComPtr< IDiaSymbol > getDiaSymbol() const
std::unique_ptr< IPDBEnumDataStreams > getDebugStreams() const override
static ErrorSuccess success()
Create a success value.
std::unique_ptr< PDBSymbolCompiland > findOneCompilandForSourceFile(llvm::StringRef Pattern, PDB_NameSearchFlags Flags) const override
static Error LoadDIA(CComPtr< IDiaDataSource > &DiaDataSource)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
success
Parameters (see the expansion example below): (the builder, addr, loaded, new_val, ordering, /* OUT.
static Error ErrorFromHResult(HRESULT Result, StringRef Context)
pointer data()
Return a pointer to the vector's buffer, even if empty().
std::unique_ptr< PDBSymbol > getSymbolById(uint32_t SymbolId) const override
const IPDBRawSymbol & getRawSymbol() const
static Error createFromExe(StringRef Path, std::unique_ptr< IPDBSession > &Session)
A raw_ostream that writes to an std::string.
Lightweight error class with error context and mandatory checking.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
StringRef - Represent a constant reference to a string, i.e.
void setLoadAddress(uint64_t Address) override
std::unique_ptr< PDBSymbolExe > getGlobalScope() const override
uint64_t getLoadAddress() const override