66 std::unique_ptr<BumpPtrAllocator>
Allocator)
68 Cache(*this,
getDbiStreamPtr(*Pdb)), AddrToModuleIndex(IMapAllocator) {}
73 std::unique_ptr<IPDBSession> &Session) {
75 auto Stream = std::make_unique<MemoryBufferByteStream>(
78 auto Allocator = std::make_unique<BumpPtrAllocator>();
79 auto File = std::make_unique<PDBFile>(
Path, std::move(Stream), *
Allocator);
80 if (
auto EC = File->parseFileHeaders())
82 if (
auto EC = File->parseStreamData())
86 std::make_unique<NativeSession>(std::move(File), std::move(
Allocator));
97 return make_error<RawError>(ErrorOrBuffer.
getError());
98 std::unique_ptr<llvm::MemoryBuffer> Buffer = std::move(*ErrorOrBuffer);
100 PdbPath = Buffer->getBufferIdentifier();
104 return make_error<RawError>(EC);
106 auto Stream = std::make_unique<MemoryBufferByteStream>(std::move(Buffer),
109 auto File = std::make_unique<PDBFile>(PdbPath, std::move(Stream), *
Allocator);
110 if (
auto EC = File->parseFileHeaders())
111 return std::move(EC);
113 if (
auto EC = File->parseStreamData())
114 return std::move(EC);
116 return std::move(File);
120 std::unique_ptr<IPDBSession> &Session) {
121 auto Allocator = std::make_unique<BumpPtrAllocator>();
124 return PdbFile.takeError();
126 Session = std::make_unique<NativeSession>(std::move(PdbFile.get()),
138 dyn_cast<object::COFFObjectFile>(BinaryFile->getBinary());
147 return std::string(PdbPath);
151 std::unique_ptr<IPDBSession> &Session) {
159 return make_error<RawError>(EC);
161 auto Allocator = std::make_unique<BumpPtrAllocator>();
164 return File.takeError();
166 Session = std::make_unique<NativeSession>(std::move(File.get()),
188 auto Allocator = std::make_unique<BumpPtrAllocator>();
191 return std::string(PdbPath);
197 return std::string(PathFromExe);
199 return File.takeError();
201 return make_error<RawError>(
"PDB not found");
215std::unique_ptr<PDBSymbol>
231 auto Dbi = Pdb->getPDBDbiStream();
235 if ((int32_t)RVA < 0)
239 for (; Section < Dbi->getSectionHeaders().
size(); ++Section) {
240 auto &Sec = Dbi->getSectionHeaders()[Section];
241 if (RVA < Sec.VirtualAddress)
243 Offset = RVA - Sec.VirtualAddress;
248std::unique_ptr<PDBSymbol>
264std::unique_ptr<PDBSymbol>
267 if (AddrToModuleIndex.
empty())
268 parseSectionContribs();
273std::unique_ptr<IPDBEnumLineNumbers>
279std::unique_ptr<IPDBEnumLineNumbers>
285std::unique_ptr<IPDBEnumLineNumbers>
290std::unique_ptr<IPDBEnumLineNumbers>
297std::unique_ptr<IPDBEnumSourceFiles>
304std::unique_ptr<IPDBSourceFile>
311std::unique_ptr<IPDBEnumChildren<PDBSymbolCompiland>>
317std::unique_ptr<PDBSymbolCompiland>
332std::unique_ptr<IPDBSourceFile>
345std::unique_ptr<IPDBEnumInjectedSources>
347 auto ISS = Pdb->getInjectedSourceStream();
352 auto Strings = Pdb->getStringTable();
357 return std::make_unique<NativeEnumInjectedSources>(*Pdb, *ISS, *Strings);
360std::unique_ptr<IPDBEnumSectionContribs>
365std::unique_ptr<IPDBEnumFrameData>
370void NativeSession::initializeExeSymbol() {
390 uint32_t MaxSection = Dbi->getSectionHeaders().size();
391 if (Section > MaxSection + 1)
392 Section = MaxSection + 1;
393 auto &Sec = Dbi->getSectionHeaders()[Section - 1];
394 return Sec.VirtualAddress +
Offset;
404 auto Iter = AddrToModuleIndex.
find(VA);
405 if (Iter == AddrToModuleIndex.
end())
407 ModuleIndex = Iter.value();
415 if (Iter == AddrToModuleIndex.
end())
417 ModuleIndex = Iter.value();
421void NativeSession::parseSectionContribs() {
422 auto Dbi = Pdb->getPDBDbiStream();
432 : Session(Session), AddrMap(AddrMap) {}
442 if (!AddrMap.overlaps(VA,
End))
443 AddrMap.insert(VA,
End,
C.Imod);
448 Visitor
V(*
this, AddrToModuleIndex);
449 Dbi->visitSectionContributions(V);
455 assert(Dbi &&
"Dbi stream not present");
461 return make_error<RawError>(
"Module stream not present");
463 std::unique_ptr<msf::MappedBlockStream> ModStreamData =
464 Pdb->createIndexedStream(ModiStream);
467 if (
auto EC = ModS.
reload())
468 return std::move(EC);
470 return std::move(ModS);
This file defines the BumpPtrAllocator interface.
Lightweight arrays that are backed by an arbitrary BinaryStream.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
Provides ErrorOr<T> smart pointer.
static DbiStream * getDbiStreamPtr(NativeSession &Session)
static DbiStream * getDbiStreamPtr(PDBFile &File)
static Expected< std::string > getPdbPathFromExe(StringRef ExePath)
static Expected< std::unique_ptr< PDBFile > > loadPdbFile(StringRef PdbPath, std::unique_ptr< BumpPtrAllocator > &Allocator)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Represents either an error or a value T.
std::error_code getError() const
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
Tagged union holding either a T or a Error.
Error takeError()
Take ownership of the stored error.
reference get()
Returns a reference to the stored T value.
const_iterator find(KeyT x) const
find - Return an iterator pointing to the first interval ending at or after x, or end().
bool empty() const
empty - Return true when no intervals are mapped.
const_iterator end() const
static ErrorOr< std::unique_ptr< MemoryBuffer > > getFile(const Twine &Filename, bool IsText=false, bool RequiresNullTerminator=true, bool IsVolatile=false, std::optional< Align > Alignment=std::nullopt)
Open the specified file as a MemoryBuffer, returning a new MemoryBuffer if successful,...
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
StringRef - Represent a constant reference to a string, i.e.
bool startswith(StringRef Prefix) const
The instances of the Type class are immutable: once they are created, they are never changed.
Error getDebugPDBInfo(const debug_directory *DebugDir, const codeview::DebugInfo *&Info, StringRef &PDBFileName) const
Get PDB information out of a codeview debug directory entry.
uint16_t getModuleStreamIndex() const
IPDBSourceFile defines an interface used to represent source files whose information are stored in th...
std::unique_ptr< IPDBEnumFrameData > getFrameData() const override
std::unique_ptr< IPDBEnumSourceFiles > getSourceFilesForCompiland(const PDBSymbolCompiland &Compiland) const override
static Expected< std::string > searchForPdb(const PdbSearchOptions &Opts)
std::unique_ptr< PDBSymbolExe > getGlobalScope() override
bool addressForVA(uint64_t VA, uint32_t &Section, uint32_t &Offset) const override
std::unique_ptr< IPDBEnumSourceFiles > findSourceFiles(const PDBSymbolCompiland *Compiland, llvm::StringRef Pattern, PDB_NameSearchFlags Flags) const override
bool addressForRVA(uint32_t RVA, uint32_t &Section, uint32_t &Offset) const override
std::unique_ptr< IPDBEnumLineNumbers > findLineNumbersByRVA(uint32_t RVA, uint32_t Length) const override
bool moduleIndexForSectOffset(uint32_t Sect, uint32_t Offset, uint16_t &ModuleIndex) const
uint64_t getVAFromSectOffset(uint32_t Section, uint32_t Offset) const
std::unique_ptr< IPDBEnumLineNumbers > findLineNumbersBySectOffset(uint32_t Section, uint32_t Offset, uint32_t Length) const override
static Error createFromPdb(std::unique_ptr< MemoryBuffer > MB, std::unique_ptr< IPDBSession > &Session)
static Error createFromExe(StringRef Path, std::unique_ptr< IPDBSession > &Session)
std::unique_ptr< PDBSymbol > findSymbolBySectOffset(uint32_t Sect, uint32_t Offset, PDB_SymType Type) override
std::unique_ptr< PDBSymbolCompiland > findOneCompilandForSourceFile(llvm::StringRef Pattern, PDB_NameSearchFlags Flags) const override
uint32_t getRVAFromSectOffset(uint32_t Section, uint32_t Offset) const
~NativeSession() override
std::unique_ptr< IPDBEnumInjectedSources > getInjectedSources() const override
std::unique_ptr< IPDBEnumTables > getEnumTables() const override
static Error createFromPdbPath(StringRef PdbPath, std::unique_ptr< IPDBSession > &Session)
bool setLoadAddress(uint64_t Address) override
std::unique_ptr< IPDBSourceFile > getSourceFileById(uint32_t FileId) const override
std::unique_ptr< IPDBEnumSectionContribs > getSectionContribs() const override
NativeSession(std::unique_ptr< PDBFile > PdbFile, std::unique_ptr< BumpPtrAllocator > Allocator)
NativeExeSymbol & getNativeGlobalScope() const
std::unique_ptr< IPDBEnumChildren< PDBSymbolCompiland > > findCompilandsForSourceFile(llvm::StringRef Pattern, PDB_NameSearchFlags Flags) const override
std::unique_ptr< IPDBEnumLineNumbers > findLineNumbersByAddress(uint64_t Address, uint32_t Length) const override
std::unique_ptr< PDBSymbol > findSymbolByAddress(uint64_t Address, PDB_SymType Type) override
Expected< ModuleDebugStreamRef > getModuleDebugStream(uint32_t Index) const
std::unique_ptr< IPDBEnumSourceFiles > getAllSourceFiles() const override
bool moduleIndexForVA(uint64_t VA, uint16_t &ModuleIndex) const
std::unique_ptr< IPDBEnumDataStreams > getDebugStreams() const override
std::unique_ptr< IPDBEnumLineNumbers > findLineNumbers(const PDBSymbolCompiland &Compiland, const IPDBSourceFile &File) const override
std::unique_ptr< PDBSymbol > getSymbolById(SymIndexId SymbolId) const override
std::unique_ptr< IPDBSourceFile > findOneSourceFile(const PDBSymbolCompiland *Compiland, llvm::StringRef Pattern, PDB_NameSearchFlags Flags) const override
std::unique_ptr< PDBSymbol > findSymbolByRVA(uint32_t RVA, PDB_SymType Type) override
uint64_t getLoadAddress() const override
std::unique_ptr< PDBSymbol > getSymbolById(SymIndexId SymbolId) const
NativeRawSymbol & getNativeSymbolById(SymIndexId SymbolId) const
std::unique_ptr< IPDBSourceFile > getSourceFileById(SymIndexId FileId) const
std::unique_ptr< IPDBEnumLineNumbers > findLineNumbersByVA(uint64_t VA, uint32_t Length) const
SymIndexId createSymbol(Args &&...ConstructorArgs) const
std::unique_ptr< PDBSymbol > findSymbolBySectOffset(uint32_t Sect, uint32_t Offset, PDB_SymType Type)
@ C
The default llvm calling convention, compatible with C.
static const char Magic[]
Expected< std::unique_ptr< Binary > > createBinary(MemoryBufferRef Source, LLVMContext *Context=nullptr, bool InitContent=true)
Create a Binary from Source, autodetecting the file type.
const uint16_t kInvalidStreamIndex
PDB_NameSearchFlags
Defines flags used for enumerating child symbols.
PDB_SymType
These values correspond to the SymTagEnum enumeration, and are documented here: https://msdn....
void remove_filename(SmallVectorImpl< char > &path, Style style=Style::native)
Remove the last component from path unless it is the root dir.
StringRef filename(StringRef path, Style style=Style::native)
Get filename.
void append(SmallVectorImpl< char > &path, const Twine &a, const Twine &b="", const Twine &c="", const Twine &d="")
Append to path.
This is an optimization pass for GlobalISel generic memory operations.
file_magic identify_magic(StringRef magic)
Identify the type of a binary file based on how magical it is.
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
void consumeError(Error Err)
Consume a Error without doing anything.
file_magic - An "enum class" enumeration of file types based on magic (the first N bytes of the file)...
@ pdb
Windows PDB debug info file.