LLVM: lib/DebugInfo/PDB/Native/InputFile.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

10

29

30using namespace llvm;

34

35InputFile::InputFile() = default;

37

42 if (!DbiOrErr)

45 const auto &Modules = Dbi.modules();

46 if (Index >= Modules.getModuleCount())

48 "Invalid module index");

49

50 auto Modi = Modules.getModuleDescriptor(Index);

51

53

54 uint16_t ModiStream = Modi.getModuleStreamIndex();

57 "Module stream not present");

58

59 auto ModStreamData = File.createIndexedStream(ModiStream);

60

64 "Invalid module stream");

65

66 return std::move(ModS);

67}

68

72 if (!DbiOrErr)

75 const auto &Modules = Dbi.modules();

77

78 uint16_t ModiStream = Modi.getModuleStreamIndex();

81 "Module stream not present");

82

83 auto ModStreamData = File.createIndexedStream(ModiStream);

84

88 "Invalid module stream");

89

90 return std::move(ModS);

91}

92

97 if (*NameOrErr != Name)

98 return false;

99 } else {

101 return false;

102 }

103

105 if (!ContentsOrErr) {

107 return false;

108 }

109

113 return false;

116 return false;

117 return true;

118}

119

124 return false;

125

127 return true;

128}

129

134 return false;

136 return true;

137}

138

140 switch (Kind) {

145 }

147}

148

149template <typename... Args>

151 if (Append)

152 Printer.format(std::forward(args)...);

153 else

154 Printer.formatLine(std::forward(args)...);

155}

156

158 if (!File)

159 return;

160

161 if (File->isPdb())

162 initializeForPdb(GroupIndex);

163 else {

164 Name = ".debug$S";

166 for (const auto &S : File->obj().sections()) {

169 continue;

170

171 if (!SC.hasChecksums() || !SC.hasStrings())

172 SC.initialize(SS);

173

174 if (I == GroupIndex)

175 Subsections = SS;

176

177 if (SC.hasChecksums() && SC.hasStrings())

178 break;

179 }

180 rebuildChecksumMap();

181 }

182}

183

185

187 Subsections = SS;

188}

189

190void SymbolGroup::updatePdbModi(uint32_t Modi) { initializeForPdb(Modi); }

191

192void SymbolGroup::initializeForPdb(uint32_t Modi) {

194

195

196

201 else

203 }

204

205 SC.resetChecksums();

207 if (!MDS) {

209 return;

210 }

211

212 DebugStream = std::make_shared(std::move(*MDS));

213 Subsections = DebugStream->getSubsectionsArray();

214 SC.initialize(Subsections);

215 rebuildChecksumMap();

216}

217

218void SymbolGroup::rebuildChecksumMap() {

219 if (!SC.hasChecksums())

220 return;

221

222 for (const auto &Entry : SC.checksums()) {

223 auto S = SC.strings().getString(Entry.FileNameOffset);

224 if (!S)

225 continue;

226 ChecksumsByFile[*S] = Entry;

227 }

228}

229

231 assert(File && File->isPdb() && DebugStream);

232 return *DebugStream;

233}

234

236 return SC.strings().getString(Offset);

237}

238

241 if (!SC.hasChecksums()) {

242 return std::move(Name);

243 }

244

245 auto Iter = SC.checksums().getArray().at(Offset);

246 if (Iter == SC.checksums().getArray().end()) {

247 return std::move(Name);

248 }

249

250 uint32_t FO = Iter->FileNameOffset;

252 if (!ExpectedFile) {

253 return std::move(Name);

254 }

255

256 return *ExpectedFile;

257}

258

260 bool Append) const {

261 auto FC = ChecksumsByFile.find(File);

262 if (FC == ChecksumsByFile.end()) {

264 return;

265 }

266

269 toHex(FC->getValue().Checksum), File);

270}

271

274 bool Append) const {

275 if (!SC.hasChecksums()) {

277 return;

278 }

279

280 auto Iter = SC.checksums().getArray().at(Offset);

281 if (Iter == SC.checksums().getArray().end()) {

283 return;

284 }

285

286 uint32_t FO = Iter->FileNameOffset;

288 if (!ExpectedFile) {

291 return;

292 }

295 } else {

298 }

299}

300

302 InputFile IF;

306

310 formatv("Unable to identify file type for file {0}", Path), EC);

311

314 if (!BinaryOrErr)

316

317 IF.CoffObject = std::move(*BinaryOrErr);

319 return std::move(IF);

320 }

321

323 std::unique_ptr Session;

325 return std::move(Err);

326

327 IF.PdbSession.reset(static_cast<NativeSession *>(Session.release()));

328 IF.PdbOrObj = &IF.PdbSession->getPDBFile();

329

330 return std::move(IF);

331 }

332

333 if (!AllowUnknownFile)

335 formatv("File {0} is not a supported file type", Path),

337

339 false);

340 if (!Result)

342 formatv("File {0} could not be opened", Path), Result.getError());

343

344 IF.UnknownFile = std::move(*Result);

345 IF.PdbOrObj = IF.UnknownFile.get();

346 return std::move(IF);

347}

348

353

358

363

368

373

378

387

391

392 for (const auto &Section : obj().sections()) {

395 return true;

396 }

397 return false;

398}

399

405

407

411

413

415InputFile::getOrCreateTypeCollection(TypeCollectionKind Kind) {

416 if (Types && Kind == kTypes)

417 return *Types;

418 if (Ids && Kind == kIds)

419 return *Ids;

420

421 if (Kind == kIds) {

423 }

424

425

426

428 TypeCollectionPtr &Collection = (Kind == kIds) ? Ids : Types;

429 auto &Stream = cantFail((Kind == kIds) ? pdb().getPDBIpiStream()

430 : pdb().getPDBTpiStream());

431

432 auto &Array = Stream.typeArray();

434 auto Offsets = Stream.getTypeIndexOffsets();

435 Collection =

436 std::make_unique(Array, Count, Offsets);

437 return *Collection;

438 }

439

443

444 for (const auto &Section : obj().sections()) {

447 continue;

448

449 Types = std::make_unique(Records, 100);

450 return *Types;

451 }

452

453 Types = std::make_unique(100);

454 return *Types;

455}

456

458 return getOrCreateTypeCollection(kTypes);

459}

460

462

463

464

465 if (isObj() || pdb().hasPDBIpiStream())

467

468 return getOrCreateTypeCollection(kIds);

469}

470

475

479

483

485

487 if (File.isObj()) {

488 SectionIter = File.obj().section_begin();

489 scanToNextDebugS();

490 }

491}

492

494 bool E = isEnd();

495 bool RE = R.isEnd();

496 if (E || RE)

497 return E == RE;

498

499 if (Value.File != R.Value.File)

500 return false;

501 return Index == R.Index;

502}

503

512

514 assert(Value.File && !isEnd());

515 ++Index;

516 if (isEnd())

517 return *this;

518

519 if (Value.File->isPdb()) {

520 Value.updatePdbModi(Index);

521 return *this;

522 }

523

524 scanToNextDebugS();

525 return *this;

526}

527

528void SymbolGroupIterator::scanToNextDebugS() {

530 auto End = Value.File->obj().section_end();

531 auto &Iter = *SectionIter;

533

534 while (++Iter != End) {

538 continue;

539

540 Value.updateDebugS(SS);

541 return;

542 }

543}

544

545bool SymbolGroupIterator::isEnd() const {

547 return true;

548 if (Value.File->isPdb()) {

552 return Index == Count;

553 }

554

556 return *SectionIter == Value.File->obj().section_end();

557}

558

561 return true;

562

564 if (Name.starts_with("Import:"))

565 return false;

566 if (Name.ends_with_insensitive(".dll"))

567 return false;

568 if (Name.equals_insensitive("* linker *"))

569 return false;

570 if (Name.starts_with_insensitive("f:\\binaries\\Intermediate\\vctools"))

571 return false;

572 if (Name.starts_with_insensitive("f:\\dd\\vctools\\crt"))

573 return false;

574 return true;

575}

576

580 return false;

581

582

584 return true;

585

586

587 return (Filters.DumpModi == Idx);

588}

589llvm::pdb::InputFile::InputFile(PDBFile *Pdb) { PdbOrObj = Pdb; }

590

592

593llvm::pdb::InputFile::InputFile(MemoryBuffer *Buffer) { PdbOrObj = Buffer; }

assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")

bbsections Prepares for basic block sections

dxil pretty DXIL Metadata Pretty Printer

#define RETURN_CASE(Enum, X, Ret)

static bool isDebugSSection(object::SectionRef Section, DebugSubsectionArray &Subsections)

Definition InputFile.cpp:120

static void formatInternal(LinePrinter &Printer, bool Append, Args &&...args)

Definition InputFile.cpp:150

static bool isDebugTSection(SectionRef Section, CVTypeArray &Types)

Definition InputFile.cpp:130

static bool isCodeViewDebugSubsection(object::SectionRef Section, StringRef Name, BinaryStreamReader &Reader)

Definition InputFile.cpp:93

static std::string formatChecksumKind(FileChecksumKind Kind)

Definition InputFile.cpp:139

static bool isMyCode(const SymbolGroup &Group)

Definition InputFile.cpp:559

Provides read only access to a subclass of BinaryStream.

Error readInteger(T &Dest)

Read an integer of the specified endianness into Dest and update the stream's offset.

uint64_t bytesRemaining() const

Error readArray(ArrayRef< T > &Array, uint32_t NumElements)

Get a reference to a NumElements element array of objects of type T from the underlying stream as if ...

Lightweight error class with error context and mandatory checking.

Tagged union holding either a T or a Error.

Error takeError()

Take ownership of the stored error.

This interface provides simple read-only access to a block of memory, and provides simple methods for...

virtual StringRef getBufferIdentifier() const

Return an identifier for this buffer, typically the filename it was read from.

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

A class that wrap the SHA1 algorithm.

StringRef - Represent a constant reference to a string, i.e.

A table of densely packed, null-terminated strings indexed by offset.

LLVM Value Representation.

Provides amortized O(1) random access to a CodeView type stream.

LLVM_ABI void setStrings(const DebugStringTableSubsectionRef &Strings)

A range adaptor for a pair of iterators.

StringRef getFileName() const

This is a value type class that represents a single section in the list of sections in the object fil...

LLVM_ABI DbiModuleDescriptor getModuleDescriptor(uint32_t Modi) const

LLVM_ABI uint32_t getModuleCount() const

LLVM_ABI const DbiModuleList & modules() const

LLVM_ABI bool hasIds() const

Definition InputFile.cpp:400

LLVM_ABI MemoryBuffer & unknown()

Definition InputFile.cpp:369

LLVM_ABI SymbolGroupIterator symbol_groups_begin()

Definition InputFile.cpp:476

LLVM_ABI iterator_range< SymbolGroupIterator > symbol_groups()

Definition InputFile.cpp:471

LLVM_ABI StringRef getFilePath() const

Definition InputFile.cpp:379

LLVM_ABI codeview::LazyRandomTypeCollection & types()

Definition InputFile.cpp:457

static LLVM_ABI Expected< InputFile > open(StringRef Path, bool AllowUnknownFile=false)

Definition InputFile.cpp:301

LLVM_ABI SymbolGroupIterator symbol_groups_end()

Definition InputFile.cpp:480

LLVM_ABI bool isUnknown() const

Definition InputFile.cpp:412

LLVM_ABI PDBFile & pdb()

Definition InputFile.cpp:349

LLVM_ABI bool hasTypes() const

Definition InputFile.cpp:388

LLVM_ABI codeview::LazyRandomTypeCollection & ids()

Definition InputFile.cpp:461

LLVM_ABI object::COFFObjectFile & obj()

Definition InputFile.cpp:359

LLVM_ABI bool isObj() const

Definition InputFile.cpp:408

LLVM_ABI bool isPdb() const

Definition InputFile.cpp:406

bool hasPDBTpiStream() const

bool hasPDBIpiStream() const

StringRef getFilePath() const

Expected< PDBStringTable & > getStringTable()

LLVM_ABI SymbolGroupIterator & operator++()

Definition InputFile.cpp:513

LLVM_ABI const SymbolGroup & operator*() const

Definition InputFile.cpp:504

LLVM_ABI SymbolGroupIterator()

Definition InputFile.cpp:484

LLVM_ABI bool operator==(const SymbolGroupIterator &R) const

Definition InputFile.cpp:493

LLVM_ABI Expected< StringRef > getNameFromChecksums(uint32_t Offset) const

Definition InputFile.cpp:239

LLVM_ABI Expected< StringRef > getNameFromStringTable(uint32_t Offset) const

Definition InputFile.cpp:235

LLVM_ABI SymbolGroup(InputFile *File, uint32_t GroupIndex=0)

Definition InputFile.cpp:157

LLVM_ABI void formatFromFileName(LinePrinter &Printer, StringRef File, bool Append=false) const

Definition InputFile.cpp:259

LLVM_ABI const ModuleDebugStreamRef & getPdbModuleStream() const

Definition InputFile.cpp:230

LLVM_ABI void formatFromChecksumsOffset(LinePrinter &Printer, uint32_t Offset, bool Append=false) const

Definition InputFile.cpp:272

LLVM_ABI StringRef name() const

Definition InputFile.cpp:184

const InputFile & getFile() const

constexpr char Args[]

Key for Kernel::Metadata::mArgs.

VarStreamArray< CVType > CVTypeArray

VarStreamArray< DebugSubsectionRecord > DebugSubsectionArray

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.

LLVM_ABI bool shouldDumpSymbolGroup(uint32_t Idx, const SymbolGroup &Group, const FilterOptions &Filters)

Definition InputFile.cpp:577

const uint16_t kInvalidStreamIndex

std::string formatUnknownEnum(T Value)

LLVM_ABI Expected< ModuleDebugStreamRef > getModuleDebugStream(PDBFile &File, StringRef &ModuleName, uint32_t Index)

Definition InputFile.cpp:39

LLVM_ABI Error loadDataForPDB(PDB_ReaderType Type, StringRef Path, std::unique_ptr< IPDBSession > &Session)

LLVM_ABI bool exists(const basic_file_status &status)

Does file exist?

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.

LLVM_ABI std::error_code inconvertibleErrorCode()

The value returned by this function can be returned from convertToErrorCode for Error values where no...

iterator_range< T > make_range(T x, T y)

Convenience function for iterating over sub-ranges.

auto formatv(bool Validate, const char *Fmt, Ts &&...Vals)

FunctionAddr VTableAddr Count

bool isa(const From &Val)

isa - Return true if the parameter to the template is an instance of one of the template type argu...

Error make_error(ArgTs &&... Args)

Make a Error instance representing failure using the given error info type.

void cantFail(Error Err, const char *Msg=nullptr)

Report a fatal error if Err is a failure value.

void toHex(ArrayRef< uint8_t > Input, bool LowerCase, SmallVectorImpl< char > &Output)

Convert buffer Input to its hexadecimal representation. The returned string is double the size of Inp...

decltype(auto) cast(const From &Val)

cast - Return the argument parameter cast to the specified type.

void consumeError(Error Err)

Consume a Error without doing anything.

std::optional< uint32_t > DumpModi

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.

@ coff_object

COFF object file.