35InputFile::InputFile() =
default;
45 const auto &Modules = Dbi.
modules();
46 if (
Index >= Modules.getModuleCount())
47 return make_error<RawError>(raw_error_code::index_out_of_bounds,
48 "Invalid module index");
50 auto Modi = Modules.getModuleDescriptor(
Index);
54 uint16_t ModiStream = Modi.getModuleStreamIndex();
56 return make_error<RawError>(raw_error_code::no_stream,
57 "Module stream not present");
59 auto ModStreamData = File.createIndexedStream(ModiStream);
63 return make_error<RawError>(raw_error_code::corrupt_file,
64 "Invalid module stream");
66 return std::move(ModS);
75 const auto &Modules = Dbi.
modules();
78 uint16_t ModiStream = Modi.getModuleStreamIndex();
80 return make_error<RawError>(raw_error_code::no_stream,
81 "Module stream not present");
83 auto ModStreamData = File.createIndexedStream(ModiStream);
87 return make_error<RawError>(raw_error_code::corrupt_file,
88 "Invalid module stream");
90 return std::move(ModS);
97 if (*NameOrErr !=
Name)
105 if (!ContentsOrErr) {
149template <
typename...
Args>
162 initializeForPdb(GroupIndex);
166 for (
const auto &S : File->obj().sections()) {
180 rebuildChecksumMap();
190void SymbolGroup::updatePdbModi(
uint32_t Modi) { initializeForPdb(Modi); }
192void SymbolGroup::initializeForPdb(
uint32_t Modi) {
212 DebugStream = std::make_shared<ModuleDebugStreamRef>(std::move(*MDS));
213 Subsections = DebugStream->getSubsectionsArray();
215 rebuildChecksumMap();
218void SymbolGroup::rebuildChecksumMap() {
222 for (
const auto &Entry : SC.
checksums()) {
226 ChecksumsByFile[*S] =
Entry;
242 return std::move(Name);
247 return std::move(Name);
253 return std::move(Name);
256 return *ExpectedFile;
261 auto FC = ChecksumsByFile.find(File);
262 if (FC == ChecksumsByFile.end()) {
269 toHex(FC->getValue().Checksum), File);
293 if (Iter->Kind == FileChecksumKind::None) {
304 return make_error<StringError>(
formatv(
"File {0} not found",
Path),
309 return make_error<StringError>(
310 formatv(
"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());
319 return std::move(IF);
323 std::unique_ptr<IPDBSession> Session;
325 return std::move(Err);
327 IF.PdbSession.reset(
static_cast<NativeSession *
>(Session.release()));
328 IF.PdbOrObj = &IF.PdbSession->getPDBFile();
330 return std::move(IF);
333 if (!AllowUnknownFile)
334 return make_error<StringError>(
335 formatv(
"File {0} is not a supported file type",
Path),
341 return make_error<StringError>(
342 formatv(
"File {0} could not be opened",
Path), Result.getError());
344 IF.UnknownFile = std::move(*Result);
345 IF.PdbOrObj = IF.UnknownFile.get();
346 return std::move(IF);
351 return *cast<PDBFile *>(PdbOrObj);
356 return *cast<PDBFile *>(PdbOrObj);
361 return *cast<object::COFFObjectFile *>(PdbOrObj);
366 return *cast<object::COFFObjectFile *>(PdbOrObj);
371 return *cast<MemoryBuffer *>(PdbOrObj);
376 return *cast<MemoryBuffer *>(PdbOrObj);
409 return isa<object::COFFObjectFile *>(PdbOrObj);
415InputFile::getOrCreateTypeCollection(TypeCollectionKind
Kind) {
416 if (Types &&
Kind == kTypes)
418 if (Ids &&
Kind == kIds)
428 TypeCollectionPtr &Collection = (
Kind == kIds) ? Ids : Types;
430 :
pdb().getPDBTpiStream());
432 auto &Array = Stream.typeArray();
433 uint32_t Count = Stream.getNumTypeRecords();
434 auto 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);
458 return getOrCreateTypeCollection(kTypes);
465 if (
isObj() || !
pdb().hasPDBIpiStream())
468 return getOrCreateTypeCollection(kIds);
488 SectionIter = File.obj().section_begin();
499 if (
Value.File != R.Value.File)
501 return Index == R.Index;
519 if (
Value.File->isPdb()) {
528void SymbolGroupIterator::scanToNextDebugS() {
530 auto End =
Value.File->obj().section_end();
531 auto &Iter = *SectionIter;
534 while (++Iter !=
End) {
540 Value.updateDebugS(SS);
545bool SymbolGroupIterator::isEnd()
const {
548 if (
Value.File->isPdb()) {
552 return Index == Count;
556 return *SectionIter ==
Value.File->obj().section_end();
564 if (
Name.starts_with(
"Import:"))
566 if (
Name.ends_with_insensitive(
".dll"))
568 if (
Name.equals_insensitive(
"* linker *"))
570 if (
Name.starts_with_insensitive(
"f:\\binaries\\Intermediate\\vctools"))
572 if (
Name.starts_with_insensitive(
"f:\\dd\\vctools\\crt"))
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
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
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.
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
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(const char *Fmt, Ts &&...Vals) -> formatv_object< decltype(std::make_tuple(support::detail::build_format_adapter(std::forward< 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.