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 {

50namespace codeview {

52}

53}

54

57 if (DbiS)

58 return &DbiS.get();

59

61 return nullptr;

62}

63

65 std::unique_ptr 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 false);

95 if (!ErrorOrBuffer)

96 return make_error(ErrorOrBuffer.getError());

97 std::unique_ptrllvm::MemoryBuffer Buffer = std::move(*ErrorOrBuffer);

98

99 PdbPath = Buffer->getBufferIdentifier();

103 return make_error(EC);

104

105 auto Stream = std::make_unique(

107

108 auto File = std::make_unique(PdbPath, std::move(Stream), *Allocator);

109 if (auto EC = File->parseFileHeaders())

110 return std::move(EC);

111

112 if (auto EC = File->parseStreamData())

113 return std::move(EC);

114

115 return std::move(File);

116}

117

119 std::unique_ptr &Session) {

120 auto Allocator = std::make_unique();

122 if (!PdbFile)

123 return PdbFile.takeError();

124

125 Session = std::make_unique(std::move(PdbFile.get()),

128}

129

133 if (!BinaryFile)

135

137 dyn_castobject::COFFObjectFile(BinaryFile->getBinary());

138 if (!ObjFile)

140

144 return std::move(E);

145

146 return std::string(PdbPath);

147}

148

150 std::unique_ptr &Session) {

152 if (!PdbPath)

154

158 return make_error(EC);

159

160 auto Allocator = std::make_unique();

162 if (!File)

163 return File.takeError();

164

165 Session = std::make_unique(std::move(File.get()),

167

169}

170

174 if (!PathOrErr)

181

182

186

187 auto Allocator = std::make_unique();

188

190 return std::string(PdbPath);

191 else

193

194

196 return std::string(PathFromExe);

197 else

198 return File.takeError();

199

200 return make_error("PDB not found");

201}

202

204

207 return true;

208}

209

212}

213

214std::unique_ptr

217}

218

223}

224

227 Section = 0;

229

230 auto Dbi = Pdb->getPDBDbiStream();

231 if (!Dbi)

232 return false;

233

234 if ((int32_t)RVA < 0)

235 return true;

236

238 for (; Section < Dbi->getSectionHeaders().size(); ++Section) {

239 auto &Sec = Dbi->getSectionHeaders()[Section];

240 if (RVA < Sec.VirtualAddress)

241 return true;

242 Offset = RVA - Sec.VirtualAddress;

243 }

244 return true;

245}

246

247std::unique_ptr

253}

254

261}

262

263std::unique_ptr

266 if (AddrToModuleIndex.empty())

267 parseSectionContribs();

268

270}

271

272std::unique_ptr

275 return nullptr;

276}

277

278std::unique_ptr

282}

283

284std::unique_ptr

287}

288

289std::unique_ptr

294}

295

296std::unique_ptr

300 return nullptr;

301}

302

303std::unique_ptr

307 return nullptr;

308}

309

310std::unique_ptr<IPDBEnumChildren>

313 return nullptr;

314}

315

316std::unique_ptr

319 return nullptr;

320}

321

323 return nullptr;

324}

325

328 return nullptr;

329}

330

331std::unique_ptr

334}

335

337 return nullptr;

338}

339

341 return nullptr;

342}

343

344std::unique_ptr

346 auto ISS = Pdb->getInjectedSourceStream();

347 if (!ISS) {

349 return nullptr;

350 }

351 auto Strings = Pdb->getStringTable();

352 if (!Strings) {

354 return nullptr;

355 }

356 return std::make_unique(*Pdb, *ISS, *Strings);

357}

358

359std::unique_ptr

361 return nullptr;

362}

363

364std::unique_ptr

366 return nullptr;

367}

368

369void NativeSession::initializeExeSymbol() {

370 if (ExeSymbol == 0)

372}

373

375 const_cast<NativeSession &>(*this).initializeExeSymbol();

376

378}

379

382 if (Section <= 0)

383 return 0;

384

386 if (!Dbi)

387 return 0;

388

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;

394}

395

399}

400

402 ModuleIndex = 0;

403 auto Iter = AddrToModuleIndex.find(VA);

404 if (Iter == AddrToModuleIndex.end())

405 return false;

406 ModuleIndex = Iter.value();

407 return true;

408}

409

411 uint16_t &ModuleIndex) const {

412 ModuleIndex = 0;

414 if (Iter == AddrToModuleIndex.end())

415 return false;

416 ModuleIndex = Iter.value();

417 return true;

418}

419

420void NativeSession::parseSectionContribs() {

421 auto Dbi = Pdb->getPDBDbiStream();

422 if (!Dbi)

423 return;

424

427 IMap &AddrMap;

428

429 public:

431 : Session(Session), AddrMap(AddrMap) {}

433 if (C.Size == 0)

434 return;

435

438

439

440

441 if (!AddrMap.overlaps(VA, End))

442 AddrMap.insert(VA, End, C.Imod);

443 }

445 };

446

447 Visitor V(*this, AddrToModuleIndex);

448 Dbi->visitSectionContributions(V);

449}

450

454 assert(Dbi && "Dbi stream not present");

455

457

460 return make_error("Module stream not present");

461

462 std::unique_ptrmsf::MappedBlockStream ModStreamData =

463 Pdb->createIndexedStream(ModiStream);

464

466 if (auto EC = ModS.reload())

467 return std::move(EC);

468

469 return std::move(ModS);

470}

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 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 LLVM_LIFETIME_BOUND, 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.