65 std::unique_ptr<BumpPtrAllocator> Allocator)
67 Cache(*this,
getDbiStreamPtr(*Pdb)), AddrToModuleIndex(IMapAllocator) {}
72 std::unique_ptr<IPDBSession> &Session) {
74 auto Stream = std::make_unique<MemoryBufferByteStream>(
77 auto Allocator = std::make_unique<BumpPtrAllocator>();
78 auto File = std::make_unique<PDBFile>(
Path, std::move(Stream), *
Allocator);
79 if (
auto EC = File->parseFileHeaders())
81 if (
auto EC = File->parseStreamData())
85 std::make_unique<NativeSession>(std::move(File), std::move(
Allocator));
96 return make_error<RawError>(ErrorOrBuffer.
getError());
97 std::unique_ptr<llvm::MemoryBuffer> Buffer = std::move(*ErrorOrBuffer);
99 PdbPath = Buffer->getBufferIdentifier();
103 return make_error<RawError>(EC);
105 auto Stream = std::make_unique<MemoryBufferByteStream>(
108 auto File = std::make_unique<PDBFile>(PdbPath, std::move(Stream), *
Allocator);
109 if (
auto EC = File->parseFileHeaders())
110 return std::move(EC);
112 if (
auto EC = File->parseStreamData())
113 return std::move(EC);
115 return std::move(File);
119 std::unique_ptr<IPDBSession> &Session) {
120 auto Allocator = std::make_unique<BumpPtrAllocator>();
123 return PdbFile.takeError();
125 Session = std::make_unique<NativeSession>(std::move(PdbFile.get()),
137 dyn_cast<object::COFFObjectFile>(BinaryFile->getBinary());
146 return std::string(PdbPath);
150 std::unique_ptr<IPDBSession> &Session) {
158 return make_error<RawError>(EC);
160 auto Allocator = std::make_unique<BumpPtrAllocator>();
163 return File.takeError();
165 Session = std::make_unique<NativeSession>(std::move(File.get()),
187 auto Allocator = std::make_unique<BumpPtrAllocator>();
190 return std::string(PdbPath);
196 return std::string(PathFromExe);
198 return File.takeError();
200 return make_error<RawError>(
"PDB not found");
214std::unique_ptr<PDBSymbol>
230 auto Dbi = Pdb->getPDBDbiStream();
234 if ((int32_t)RVA < 0)
238 for (; Section < Dbi->getSectionHeaders().
size(); ++Section) {
239 auto &Sec = Dbi->getSectionHeaders()[Section];
240 if (RVA < Sec.VirtualAddress)
242 Offset = RVA - Sec.VirtualAddress;
247std::unique_ptr<PDBSymbol>
263std::unique_ptr<PDBSymbol>
266 if (AddrToModuleIndex.
empty())
267 parseSectionContribs();
272std::unique_ptr<IPDBEnumLineNumbers>
278std::unique_ptr<IPDBEnumLineNumbers>
284std::unique_ptr<IPDBEnumLineNumbers>
289std::unique_ptr<IPDBEnumLineNumbers>
296std::unique_ptr<IPDBEnumSourceFiles>
303std::unique_ptr<IPDBSourceFile>
310std::unique_ptr<IPDBEnumChildren<PDBSymbolCompiland>>
316std::unique_ptr<PDBSymbolCompiland>
331std::unique_ptr<IPDBSourceFile>
344std::unique_ptr<IPDBEnumInjectedSources>
346 auto ISS = Pdb->getInjectedSourceStream();
351 auto Strings = Pdb->getStringTable();
356 return std::make_unique<NativeEnumInjectedSources>(*Pdb, *ISS, *Strings);
359std::unique_ptr<IPDBEnumSectionContribs>
364std::unique_ptr<IPDBEnumFrameData>
369void NativeSession::initializeExeSymbol() {
389 uint32_t MaxSection = Dbi->getSectionHeaders().size();
390 if (Section > MaxSection + 1)
391 Section = MaxSection + 1;
392 auto &Sec = Dbi->getSectionHeaders()[Section - 1];
393 return Sec.VirtualAddress +
Offset;
403 auto Iter = AddrToModuleIndex.
find(VA);
404 if (Iter == AddrToModuleIndex.
end())
406 ModuleIndex = Iter.value();
414 if (Iter == AddrToModuleIndex.
end())
416 ModuleIndex = Iter.value();
420void NativeSession::parseSectionContribs() {
421 auto Dbi = Pdb->getPDBDbiStream();
431 : Session(Session), AddrMap(AddrMap) {}
441 if (!AddrMap.overlaps(VA,
End))
442 AddrMap.insert(VA,
End,
C.Imod);
447 Visitor
V(*
this, AddrToModuleIndex);
448 Dbi->visitSectionContributions(V);
454 assert(Dbi &&
"Dbi stream not present");
460 return make_error<RawError>(
"Module stream not present");
462 std::unique_ptr<msf::MappedBlockStream> ModStreamData =
463 Pdb->createIndexedStream(ModiStream);
466 if (
auto EC = ModS.
reload())
467 return std::move(EC);
469 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())
void visit(MachineFunction &MF, MachineBasicBlock &Start, std::function< void(MachineBasicBlock *)> op)
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.