LLVM: lib/DebugInfo/PDB/Native/NativeSession.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
10
40
41#include
42#include
43#include
44
45using namespace llvm;
48
49namespace llvm {
52}
53}
54
57 if (DbiS)
58 return &DbiS.get();
59
61 return nullptr;
62}
63
65 std::unique_ptr Allocator)
66 : Pdb(std::move(PdbFile)), Allocator(std::move(Allocator)),
67 Cache(*this, getDbiStreamPtr(*Pdb)), AddrToModuleIndex(IMapAllocator) {}
68
70
72 std::unique_ptr &Session) {
74 auto Stream = std::make_unique(
76
77 auto Allocator = std::make_unique();
78 auto File = std::make_unique(Path, std::move(Stream), *Allocator);
79 if (auto EC = File->parseFileHeaders())
80 return EC;
81 if (auto EC = File->parseStreamData())
82 return EC;
83
84 Session =
85 std::make_unique(std::move(File), std::move(Allocator));
86
88}
89
94
98 "The input file did not contain the pdb file magic.");
99
101}
102
103static Expected<std::unique_ptr>
107 false);
108 if (!ErrorOrBuffer)
110 std::unique_ptrllvm::MemoryBuffer Buffer = std::move(*ErrorOrBuffer);
111
112 PdbPath = Buffer->getBufferIdentifier();
114 return std::move(EC);
115
116 auto Stream = std::make_unique(
118
119 auto File = std::make_unique(PdbPath, std::move(Stream), *Allocator);
120 if (auto EC = File->parseFileHeaders())
121 return std::move(EC);
122
123 if (auto EC = File->parseStreamData())
124 return std::move(EC);
125
126 return std::move(File);
127}
128
130 std::unique_ptr &Session) {
131 auto Allocator = std::make_unique();
132 auto PdbFile = loadPdbFile(PdbPath, Allocator);
133 if (!PdbFile)
134 return PdbFile.takeError();
135
136 Session = std::make_unique(std::move(PdbFile.get()),
137 std::move(Allocator));
139}
140
144 if (!BinaryFile)
146
149 if (!ObjFile)
151
155 return std::move(E);
156
157 return std::string(PdbPath);
158}
159
161 std::unique_ptr &Session) {
163 if (!PdbPath)
165
167 return EC;
168
169 auto Allocator = std::make_unique();
171 if (!File)
172 return File.takeError();
173
174 Session = std::make_unique(std::move(File.get()),
175 std::move(Allocator));
176
178}
179
183 if (!PathOrErr)
190
191
195
196 auto Allocator = std::make_unique();
197
198 if (auto File = loadPdbFile(PdbPath, Allocator))
199 return std::string(PdbPath);
200 else
202
203
204 if (auto File = loadPdbFile(PathFromExe, Allocator))
205 return std::string(PathFromExe);
206 else
207 return File.takeError();
208
210}
211
213
218
222
223std::unique_ptr
225 return Cache.getSymbolById(SymbolId);
226}
227
233
236 Section = 0;
238
239 auto Dbi = Pdb->getPDBDbiStream();
240 if (!Dbi)
241 return false;
242
243 if ((int32_t)RVA < 0)
244 return true;
245
247 for (; Section < Dbi->getSectionHeaders().size(); ++Section) {
248 auto &Sec = Dbi->getSectionHeaders()[Section];
249 if (RVA < Sec.VirtualAddress)
250 return true;
251 Offset = RVA - Sec.VirtualAddress;
252 }
253 return true;
254}
255
256std::unique_ptr
263
271
272std::unique_ptr
275 if (AddrToModuleIndex.empty())
276 parseSectionContribs();
277
278 return Cache.findSymbolBySectOffset(Sect, Offset, Type);
279}
280
281std::unique_ptr
286
287std::unique_ptr
292
293std::unique_ptr
297
298std::unique_ptr
302 return Cache.findLineNumbersByVA(VA, Length);
303}
304
305std::unique_ptr
311
312std::unique_ptr
318
319std::unique_ptr<IPDBEnumChildren>
324
325std::unique_ptr
330
334
339
340std::unique_ptr
342 return Cache.getSourceFileById(FileId);
343}
344
348
352
353std::unique_ptr
355 auto ISS = Pdb->getInjectedSourceStream();
356 if (!ISS) {
358 return nullptr;
359 }
360 auto Strings = Pdb->getStringTable();
361 if (!Strings) {
363 return nullptr;
364 }
365 return std::make_unique(*Pdb, *ISS, *Strings);
366}
367
368std::unique_ptr
372
373std::unique_ptr
377
378void NativeSession::initializeExeSymbol() {
379 if (ExeSymbol == 0)
381}
382
388
391 if (Section <= 0)
392 return 0;
393
395 if (!Dbi)
396 return 0;
397
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;
403}
404
409
411 ModuleIndex = 0;
412 auto Iter = AddrToModuleIndex.find(VA);
413 if (Iter == AddrToModuleIndex.end())
414 return false;
415 ModuleIndex = Iter.value();
416 return true;
417}
418
420 uint16_t &ModuleIndex) const {
421 ModuleIndex = 0;
423 if (Iter == AddrToModuleIndex.end())
424 return false;
425 ModuleIndex = Iter.value();
426 return true;
427}
428
429void NativeSession::parseSectionContribs() {
430 auto Dbi = Pdb->getPDBDbiStream();
431 if (!Dbi)
432 return;
433
436 IMap &AddrMap;
437
438 public:
440 : Session(Session), AddrMap(AddrMap) {}
442 if (C.Size == 0)
443 return;
444
447
448
449
450 if (!AddrMap.overlaps(VA, End))
451 AddrMap.insert(VA, End, C.Imod);
452 }
454 };
455
456 Visitor V(*this, AddrToModuleIndex);
457 Dbi->visitSectionContributions(V);
458}
459
460Expected
463 assert(Dbi && "Dbi stream not present");
464
466
470
471 std::unique_ptrmsf::MappedBlockStream ModStreamData =
472 Pdb->createIndexedStream(ModiStream);
473
475 if (auto EC = ModS.reload())
476 return std::move(EC);
477
478 return std::move(ModS);
479}
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 smart pointer.
static DbiStream * getDbiStreamPtr(NativeSession &Session)
static Error validatePdbMagic(StringRef PdbPath)
Definition NativeSession.cpp:90
static DbiStream * getDbiStreamPtr(PDBFile &File)
Definition NativeSession.cpp:55
static Expected< std::string > getPdbPathFromExe(StringRef ExePath)
Definition NativeSession.cpp:141
static Expected< std::unique_ptr< PDBFile > > loadPdbFile(StringRef PdbPath, std::unique_ptr< BumpPtrAllocator > &Allocator)
Definition NativeSession.cpp:104
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
Definition NativeSession.cpp:374
std::unique_ptr< IPDBEnumSourceFiles > getSourceFilesForCompiland(const PDBSymbolCompiland &Compiland) const override
Definition NativeSession.cpp:335
static Expected< std::string > searchForPdb(const PdbSearchOptions &Opts)
Definition NativeSession.cpp:181
std::unique_ptr< PDBSymbolExe > getGlobalScope() override
Definition NativeSession.cpp:219
bool addressForVA(uint64_t VA, uint32_t &Section, uint32_t &Offset) const override
Definition NativeSession.cpp:228
std::unique_ptr< IPDBEnumSourceFiles > findSourceFiles(const PDBSymbolCompiland *Compiland, llvm::StringRef Pattern, PDB_NameSearchFlags Flags) const override
Definition NativeSession.cpp:306
bool addressForRVA(uint32_t RVA, uint32_t &Section, uint32_t &Offset) const override
Definition NativeSession.cpp:234
std::unique_ptr< IPDBEnumLineNumbers > findLineNumbersByRVA(uint32_t RVA, uint32_t Length) const override
Definition NativeSession.cpp:294
bool moduleIndexForSectOffset(uint32_t Sect, uint32_t Offset, uint16_t &ModuleIndex) const
Definition NativeSession.cpp:419
uint64_t getVAFromSectOffset(uint32_t Section, uint32_t Offset) const
Definition NativeSession.cpp:405
std::unique_ptr< IPDBEnumLineNumbers > findLineNumbersBySectOffset(uint32_t Section, uint32_t Offset, uint32_t Length) const override
Definition NativeSession.cpp:299
static Error createFromPdb(std::unique_ptr< MemoryBuffer > MB, std::unique_ptr< IPDBSession > &Session)
Definition NativeSession.cpp:71
static Error createFromExe(StringRef Path, std::unique_ptr< IPDBSession > &Session)
Definition NativeSession.cpp:160
std::unique_ptr< PDBSymbol > findSymbolBySectOffset(uint32_t Sect, uint32_t Offset, PDB_SymType Type) override
Definition NativeSession.cpp:273
std::unique_ptr< PDBSymbolCompiland > findOneCompilandForSourceFile(llvm::StringRef Pattern, PDB_NameSearchFlags Flags) const override
Definition NativeSession.cpp:326
uint32_t getRVAFromSectOffset(uint32_t Section, uint32_t Offset) const
Definition NativeSession.cpp:389
~NativeSession() override
std::unique_ptr< IPDBEnumInjectedSources > getInjectedSources() const override
Definition NativeSession.cpp:354
std::unique_ptr< IPDBEnumTables > getEnumTables() const override
Definition NativeSession.cpp:349
static Error createFromPdbPath(StringRef PdbPath, std::unique_ptr< IPDBSession > &Session)
Definition NativeSession.cpp:129
bool setLoadAddress(uint64_t Address) override
Definition NativeSession.cpp:214
std::unique_ptr< IPDBSourceFile > getSourceFileById(uint32_t FileId) const override
Definition NativeSession.cpp:341
std::unique_ptr< IPDBEnumSectionContribs > getSectionContribs() const override
Definition NativeSession.cpp:369
NativeSession(std::unique_ptr< PDBFile > PdbFile, std::unique_ptr< BumpPtrAllocator > Allocator)
Definition NativeSession.cpp:64
NativeExeSymbol & getNativeGlobalScope() const
Definition NativeSession.cpp:383
std::unique_ptr< IPDBEnumChildren< PDBSymbolCompiland > > findCompilandsForSourceFile(llvm::StringRef Pattern, PDB_NameSearchFlags Flags) const override
Definition NativeSession.cpp:320
std::unique_ptr< IPDBEnumLineNumbers > findLineNumbersByAddress(uint64_t Address, uint32_t Length) const override
Definition NativeSession.cpp:288
std::unique_ptr< PDBSymbol > findSymbolByAddress(uint64_t Address, PDB_SymType Type) override
Definition NativeSession.cpp:257
Expected< ModuleDebugStreamRef > getModuleDebugStream(uint32_t Index) const
Definition NativeSession.cpp:461
std::unique_ptr< IPDBEnumSourceFiles > getAllSourceFiles() const override
Definition NativeSession.cpp:331
bool moduleIndexForVA(uint64_t VA, uint16_t &ModuleIndex) const
Definition NativeSession.cpp:410
std::unique_ptr< IPDBEnumDataStreams > getDebugStreams() const override
Definition NativeSession.cpp:345
std::unique_ptr< IPDBEnumLineNumbers > findLineNumbers(const PDBSymbolCompiland &Compiland, const IPDBSourceFile &File) const override
Definition NativeSession.cpp:282
std::unique_ptr< PDBSymbol > getSymbolById(SymIndexId SymbolId) const override
Definition NativeSession.cpp:224
std::unique_ptr< IPDBSourceFile > findOneSourceFile(const PDBSymbolCompiland *Compiland, llvm::StringRef Pattern, PDB_NameSearchFlags Flags) const override
Definition NativeSession.cpp:313
std::unique_ptr< PDBSymbol > findSymbolByRVA(uint32_t RVA, PDB_SymType Type) override
Definition NativeSession.cpp:264
uint64_t getLoadAddress() const override
Definition NativeSession.cpp:212
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 - 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.