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));
98 "The input file did not contain the pdb file magic.");
103static Expected<std::unique_ptr<PDBFile>>
110 std::unique_ptr<llvm::MemoryBuffer> Buffer = std::move(*ErrorOrBuffer);
112 PdbPath = Buffer->getBufferIdentifier();
114 return std::move(EC);
116 auto Stream = std::make_unique<MemoryBufferByteStream>(
119 auto File = std::make_unique<PDBFile>(PdbPath, std::move(Stream), *
Allocator);
120 if (
auto EC = File->parseFileHeaders())
121 return std::move(EC);
123 if (
auto EC = File->parseStreamData())
124 return std::move(EC);
126 return std::move(File);
130 std::unique_ptr<IPDBSession> &Session) {
131 auto Allocator = std::make_unique<BumpPtrAllocator>();
134 return PdbFile.takeError();
136 Session = std::make_unique<NativeSession>(std::move(PdbFile.get()),
137 std::move(Allocator));
157 return std::string(PdbPath);
161 std::unique_ptr<IPDBSession> &Session) {
169 auto Allocator = std::make_unique<BumpPtrAllocator>();
172 return File.takeError();
174 Session = std::make_unique<NativeSession>(std::move(File.get()),
175 std::move(Allocator));
196 auto Allocator = std::make_unique<BumpPtrAllocator>();
199 return std::string(PdbPath);
204 if (
auto File =
loadPdbFile(PathFromExe, Allocator))
205 return std::string(PathFromExe);
207 return File.takeError();
223std::unique_ptr<PDBSymbol>
225 return Cache.getSymbolById(SymbolId);
239 auto Dbi = Pdb->getPDBDbiStream();
243 if ((int32_t)RVA < 0)
247 for (; Section < Dbi->getSectionHeaders().
size(); ++Section) {
248 auto &Sec = Dbi->getSectionHeaders()[Section];
249 if (RVA < Sec.VirtualAddress)
251 Offset = RVA - Sec.VirtualAddress;
256std::unique_ptr<PDBSymbol>
272std::unique_ptr<PDBSymbol>
275 if (AddrToModuleIndex.empty())
276 parseSectionContribs();
278 return Cache.findSymbolBySectOffset(Sect,
Offset,
Type);
281std::unique_ptr<IPDBEnumLineNumbers>
287std::unique_ptr<IPDBEnumLineNumbers>
293std::unique_ptr<IPDBEnumLineNumbers>
298std::unique_ptr<IPDBEnumLineNumbers>
302 return Cache.findLineNumbersByVA(VA,
Length);
305std::unique_ptr<IPDBEnumSourceFiles>
312std::unique_ptr<IPDBSourceFile>
319std::unique_ptr<IPDBEnumChildren<PDBSymbolCompiland>>
325std::unique_ptr<PDBSymbolCompiland>
340std::unique_ptr<IPDBSourceFile>
342 return Cache.getSourceFileById(FileId);
353std::unique_ptr<IPDBEnumInjectedSources>
355 auto ISS = Pdb->getInjectedSourceStream();
360 auto Strings = Pdb->getStringTable();
365 return std::make_unique<NativeEnumInjectedSources>(*Pdb, *ISS, *Strings);
368std::unique_ptr<IPDBEnumSectionContribs>
373std::unique_ptr<IPDBEnumFrameData>
378void NativeSession::initializeExeSymbol() {
398 uint32_t MaxSection = Dbi->getSectionHeaders().size();
399 if (Section > MaxSection + 1)
400 Section = MaxSection + 1;
401 auto &Sec = Dbi->getSectionHeaders()[Section - 1];
402 return Sec.VirtualAddress +
Offset;
412 auto Iter = AddrToModuleIndex.find(VA);
413 if (Iter == AddrToModuleIndex.end())
415 ModuleIndex = Iter.value();
423 if (Iter == AddrToModuleIndex.end())
425 ModuleIndex = Iter.value();
429void NativeSession::parseSectionContribs() {
430 auto Dbi = Pdb->getPDBDbiStream();
440 : Session(Session), AddrMap(AddrMap) {}
450 if (!AddrMap.overlaps(VA, End))
451 AddrMap.insert(VA, End,
C.Imod);
456 Visitor
V(*
this, AddrToModuleIndex);
457 Dbi->visitSectionContributions(V);
460Expected<ModuleDebugStreamRef>
463 assert(Dbi &&
"Dbi stream not present");
471 std::unique_ptr<msf::MappedBlockStream> ModStreamData =
472 Pdb->createIndexedStream(ModiStream);
475 if (
auto EC = ModS.
reload())
476 return std::move(EC);
478 return std::move(ModS);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
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 Error validatePdbMagic(StringRef PdbPath)
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)
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.
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.
Error getDebugPDBInfo(const debug_directory *DebugDir, const codeview::DebugInfo *&Info, StringRef &PDBFileName) const
Get PDB information out of a codeview debug directory entry.
LLVM_ABI 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
static std::unique_ptr< ConcreteT > createAs(const IPDBSession &PDBSession, std::unique_ptr< IPDBRawSymbol > RawSymbol)
@ C
The default llvm calling convention, compatible with C.
static const char Magic[]
LLVM_ABI 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....
LLVM_ABI void remove_filename(SmallVectorImpl< char > &path, Style style=Style::native)
Remove the last component from path unless it is the root dir.
LLVM_ABI StringRef filename(StringRef path LLVM_LIFETIME_BOUND, Style style=Style::native)
Get filename.
LLVM_ABI 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.
LLVM_ABI 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.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Error make_error(ArgTs &&... Args)
Make a Error instance representing failure using the given error info type.
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.