1//===- InputFile.cpp ------------------------------------------ *- C++ --*-===// 3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4// See https://llvm.org/LICENSE.txt for license information. 5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7//===----------------------------------------------------------------------===// 35InputFile::InputFile() =
default;
45constauto &Modules = Dbi.
modules();
46if (Index >= Modules.getModuleCount())
47return make_error<RawError>(raw_error_code::index_out_of_bounds,
48"Invalid module index");
50auto Modi = Modules.getModuleDescriptor(Index);
54uint16_t ModiStream = Modi.getModuleStreamIndex();
56return make_error<RawError>(raw_error_code::no_stream,
57"Module stream not present");
59auto ModStreamData = File.createIndexedStream(ModiStream);
63return make_error<RawError>(raw_error_code::corrupt_file,
64"Invalid module stream");
66return std::move(ModS);
75constauto &Modules = Dbi.
modules();
78uint16_t ModiStream = Modi.getModuleStreamIndex();
80return make_error<RawError>(raw_error_code::no_stream,
81"Module stream not present");
83auto ModStreamData = File.createIndexedStream(ModiStream);
87return make_error<RawError>(raw_error_code::corrupt_file,
88"Invalid module stream");
90return std::move(ModS);
149template <
typename...
Args>
162 initializeForPdb(GroupIndex);
166for (
constauto &S : File->obj().sections()) {
180 rebuildChecksumMap();
190void SymbolGroup::updatePdbModi(
uint32_t Modi) { initializeForPdb(Modi); }
192void SymbolGroup::initializeForPdb(
uint32_t Modi) {
195// PDB always uses the same string table, but each module has its own 196// checksums. So we only set the strings if they're not already set. 212 DebugStream = std::make_shared<ModuleDebugStreamRef>(std::move(*MDS));
213 Subsections = DebugStream->getSubsectionsArray();
215 rebuildChecksumMap();
218void SymbolGroup::rebuildChecksumMap() {
226 ChecksumsByFile[*S] =
Entry;
242return std::move(Name);
247return std::move(Name);
253return std::move(Name);
261auto FC = ChecksumsByFile.find(File);
262if (FC == ChecksumsByFile.end()) {
269 toHex(FC->getValue().Checksum), File);
293if (Iter->Kind == FileChecksumKind::None) {
304return make_error<StringError>(
formatv(
"File {0} not found",
Path),
309return make_error<StringError>(
310formatv(
"Unable to identify file type for file {0}",
Path),
EC);
317 IF.CoffObject = std::move(*BinaryOrErr);
318 IF.PdbOrObj = llvm::cast<COFFObjectFile>(IF.CoffObject.getBinary());
323 std::unique_ptr<IPDBSession> Session;
325return std::move(Err);
327 IF.PdbSession.reset(
static_cast<NativeSession *
>(Session.release()));
328 IF.PdbOrObj = &IF.PdbSession->getPDBFile();
333if (!AllowUnknownFile)
334return make_error<StringError>(
335formatv(
"File {0} is not a supported file type",
Path),
339/*RequiresNullTerminator=*/false);
341return make_error<StringError>(
342formatv(
"File {0} could not be opened",
Path), Result.getError());
344 IF.UnknownFile = std::move(*Result);
345 IF.PdbOrObj = IF.UnknownFile.get();
351return *cast<PDBFile *>(PdbOrObj);
356return *cast<PDBFile *>(PdbOrObj);
361return *cast<object::COFFObjectFile *>(PdbOrObj);
366return *cast<object::COFFObjectFile *>(PdbOrObj);
371return *cast<MemoryBuffer *>(PdbOrObj);
376return *cast<MemoryBuffer *>(PdbOrObj);
409return isa<object::COFFObjectFile *>(PdbOrObj);
415InputFile::getOrCreateTypeCollection(TypeCollectionKind
Kind) {
416if (Types &&
Kind == kTypes)
418if (Ids &&
Kind == kIds)
425// If the collection was already initialized, we should have just returned it 428 TypeCollectionPtr &Collection = (
Kind == kIds) ? Ids : Types;
430 :
pdb().getPDBTpiStream());
432auto &Array = Stream.typeArray();
433uint32_t Count = Stream.getNumTypeRecords();
434auto Offsets = Stream.getTypeIndexOffsets();
436 std::make_unique<LazyRandomTypeCollection>(Array, Count, Offsets);
449 Types = std::make_unique<LazyRandomTypeCollection>(Records, 100);
453 Types = std::make_unique<LazyRandomTypeCollection>(100);
458return getOrCreateTypeCollection(kTypes);
462// Object files have only one type stream that contains both types and ids. 463// Similarly, some PDBs don't contain an IPI stream, and for those both types 464// and IDs are in the same stream. 465if (
isObj() || !
pdb().hasPDBIpiStream())
468return getOrCreateTypeCollection(kIds);
488 SectionIter = File.obj().section_begin();
499if (
Value.File != R.Value.File)
501return Index == R.Index;
519if (
Value.File->isPdb()) {
520Value.updatePdbModi(Index);
528void SymbolGroupIterator::scanToNextDebugS() {
530autoEnd =
Value.File->obj().section_end();
531auto &Iter = *SectionIter;
534while (++Iter !=
End) {
540Value.updateDebugS(SS);
545bool SymbolGroupIterator::isEnd()
const{
548if (
Value.File->isPdb()) {
552return Index == Count;
556return *SectionIter ==
Value.File->obj().section_end();
564if (
Name.starts_with(
"Import:"))
566if (
Name.ends_with_insensitive(
".dll"))
568if (
Name.equals_insensitive(
"* linker *"))
570if (
Name.starts_with_insensitive(
"f:\\binaries\\Intermediate\\vctools"))
572if (
Name.starts_with_insensitive(
"f:\\dd\\vctools\\crt"))
582// If the arg was not specified on the command line, always dump all modules. 586// Otherwise, only dump if this is the same module specified. bbsections Prepares for basic block sections
dxil pretty DXIL Metadata Pretty Printer
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
#define RETURN_CASE(Enum, X, Ret)
static bool isDebugSSection(object::SectionRef Section, DebugSubsectionArray &Subsections)
static void formatInternal(LinePrinter &Printer, bool Append, Args &&...args)
static bool isDebugTSection(SectionRef Section, CVTypeArray &Types)
static bool isCodeViewDebugSubsection(object::SectionRef Section, StringRef Name, BinaryStreamReader &Reader)
static std::string formatChecksumKind(FileChecksumKind Kind)
static bool isMyCode(const SymbolGroup &Group)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file contains some functions that are useful when dealing with strings.
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.
Iterator at(uint32_t Offset) const
given an offset into the array's underlying stream, return an iterator to the record at that offset.
const FileChecksumArray & getArray() const
Expected< StringRef > getString(uint32_t Offset) const
Provides amortized O(1) random access to a CodeView type stream.
void setStrings(const DebugStringTableSubsectionRef &Strings)
const DebugStringTableSubsectionRef & strings() const
bool hasChecksums() const
void initialize(T &&FragmentRange)
const DebugChecksumsSubsectionRef & checksums() const
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...
DbiModuleDescriptor getModuleDescriptor(uint32_t Modi) const
uint32_t getModuleCount() const
const DbiModuleList & modules() const
SymbolGroupIterator symbol_groups_begin()
iterator_range< SymbolGroupIterator > symbol_groups()
StringRef getFilePath() const
codeview::LazyRandomTypeCollection & types()
static Expected< InputFile > open(StringRef Path, bool AllowUnknownFile=false)
SymbolGroupIterator symbol_groups_end()
codeview::LazyRandomTypeCollection & ids()
object::COFFObjectFile & obj()
bool hasPDBTpiStream() const
bool hasPDBIpiStream() const
StringRef getFilePath() const
Expected< PDBStringTable & > getStringTable()
SymbolGroupIterator & operator++()
const SymbolGroup & operator*() const
bool operator==(const SymbolGroupIterator &R) const
Expected< StringRef > getNameFromChecksums(uint32_t Offset) const
Expected< StringRef > getNameFromStringTable(uint32_t Offset) const
SymbolGroup(InputFile *File, uint32_t GroupIndex=0)
void formatFromFileName(LinePrinter &Printer, StringRef File, bool Append=false) const
const ModuleDebugStreamRef & getPdbModuleStream() const
void formatFromChecksumsOffset(LinePrinter &Printer, uint32_t Offset, bool Append=false) const
const InputFile & getFile() const
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
Expected< std::unique_ptr< Binary > > createBinary(MemoryBufferRef Source, LLVMContext *Context=nullptr, bool InitContent=true)
Create a Binary from Source, autodetecting the file type.
bool shouldDumpSymbolGroup(uint32_t Idx, const SymbolGroup &Group, const FilterOptions &Filters)
const uint16_t kInvalidStreamIndex
std::string formatUnknownEnum(T Value)
Expected< ModuleDebugStreamRef > getModuleDebugStream(PDBFile &File, StringRef &ModuleName, uint32_t Index)
Error loadDataForPDB(PDB_ReaderType Type, StringRef Path, std::unique_ptr< IPDBSession > &Session)
bool exists(const basic_file_status &status)
Does file exist?
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.
std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
auto formatv(bool Validate, const char *Fmt, Ts &&...Vals)
void cantFail(Error Err, const char *Msg=nullptr)
Report a fatal error if Err is a failure value.
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.