67 std::unique_ptr<BumpPtrAllocator> Allocator)
69 Cache(*this,
getDbiStreamPtr(*Pdb)), AddrToModuleIndex(IMapAllocator) {}
74 std::unique_ptr<IPDBSession> &Session) {
76 auto Stream = std::make_unique<MemoryBufferByteStream>(
79 auto Allocator = std::make_unique<BumpPtrAllocator>();
80 auto File = std::make_unique<PDBFile>(
Path, std::move(Stream), *
Allocator);
81 if (
auto EC = File->parseFileHeaders())
83 if (
auto EC = File->parseStreamData())
87 std::make_unique<NativeSession>(std::move(File), std::move(
Allocator));
98 return make_error<RawError>(ErrorOrBuffer.
getError());
99 std::unique_ptr<llvm::MemoryBuffer> Buffer = std::move(*ErrorOrBuffer);
101 PdbPath = Buffer->getBufferIdentifier();
105 return make_error<RawError>(EC);
107 auto Stream = std::make_unique<MemoryBufferByteStream>(
110 auto File = std::make_unique<PDBFile>(PdbPath, std::move(Stream), *
Allocator);
111 if (
auto EC = File->parseFileHeaders())
112 return std::move(EC);
114 if (
auto EC = File->parseStreamData())
115 return std::move(EC);
117 return std::move(File);
121 std::unique_ptr<IPDBSession> &Session) {
122 auto Allocator = std::make_unique<BumpPtrAllocator>();
125 return PdbFile.takeError();
127 Session = std::make_unique<NativeSession>(std::move(PdbFile.get()),
139 dyn_cast<object::COFFObjectFile>(BinaryFile->getBinary());
148 return std::string(PdbPath);
152 std::unique_ptr<IPDBSession> &Session) {
160 return make_error<RawError>(EC);
162 auto Allocator = std::make_unique<BumpPtrAllocator>();
165 return File.takeError();
167 Session = std::make_unique<NativeSession>(std::move(File.get()),
189 auto Allocator = std::make_unique<BumpPtrAllocator>();
192 return std::string(PdbPath);
198 return std::string(PathFromExe);
200 return File.takeError();
202 return make_error<RawError>(
"PDB not found");
216std::unique_ptr<PDBSymbol>
232 auto Dbi = Pdb->getPDBDbiStream();
236 if ((int32_t)RVA < 0)
240 for (; Section < Dbi->getSectionHeaders().
size(); ++Section) {
241 auto &Sec = Dbi->getSectionHeaders()[Section];
242 if (RVA < Sec.VirtualAddress)
244 Offset = RVA - Sec.VirtualAddress;
249std::unique_ptr<PDBSymbol>
265std::unique_ptr<PDBSymbol>
268 if (AddrToModuleIndex.
empty())
269 parseSectionContribs();
274std::unique_ptr<IPDBEnumLineNumbers>
280std::unique_ptr<IPDBEnumLineNumbers>
286std::unique_ptr<IPDBEnumLineNumbers>
291std::unique_ptr<IPDBEnumLineNumbers>
298std::unique_ptr<IPDBEnumSourceFiles>
305std::unique_ptr<IPDBSourceFile>
312std::unique_ptr<IPDBEnumChildren<PDBSymbolCompiland>>
318std::unique_ptr<PDBSymbolCompiland>
333std::unique_ptr<IPDBSourceFile>
346std::unique_ptr<IPDBEnumInjectedSources>
348 auto ISS = Pdb->getInjectedSourceStream();
353 auto Strings = Pdb->getStringTable();
358 return std::make_unique<NativeEnumInjectedSources>(*Pdb, *ISS, *Strings);
361std::unique_ptr<IPDBEnumSectionContribs>
366std::unique_ptr<IPDBEnumFrameData>
371void NativeSession::initializeExeSymbol() {
391 uint32_t MaxSection = Dbi->getSectionHeaders().size();
392 if (Section > MaxSection + 1)
393 Section = MaxSection + 1;
394 auto &Sec = Dbi->getSectionHeaders()[Section - 1];
395 return Sec.VirtualAddress +
Offset;
405 auto Iter = AddrToModuleIndex.
find(VA);
406 if (Iter == AddrToModuleIndex.
end())
408 ModuleIndex = Iter.value();
416 if (Iter == AddrToModuleIndex.
end())
418 ModuleIndex = Iter.value();
422void NativeSession::parseSectionContribs() {
423 auto Dbi = Pdb->getPDBDbiStream();
433 : Session(Session), AddrMap(AddrMap) {}
443 if (!AddrMap.overlaps(VA,
End))
444 AddrMap.insert(VA,
End,
C.Imod);
449 Visitor
V(*
this, AddrToModuleIndex);
450 Dbi->visitSectionContributions(V);
456 assert(Dbi &&
"Dbi stream not present");
462 return make_error<RawError>(
"Module stream not present");
464 std::unique_ptr<msf::MappedBlockStream> ModStreamData =
465 Pdb->createIndexedStream(ModiStream);
468 if (
auto EC = ModS.
reload())
469 return std::move(EC);
471 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())
This file defines the SmallString class.
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 starts_with(StringRef Prefix) const
Check if this string starts with the given Prefix.
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.
Implement std::hash so that hash_code can be used in STL containers.
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.