42 PDBFile::PDBFile(
StringRef Path, std::unique_ptr<BinaryStream> PdbFileBuffer,
44 : FilePath(Path), Allocator(Allocator), Buffer(
std::move(PdbFileBuffer)) {}
89 return *std::max_element(ContainerLayout.
StreamSizes.begin(),
99 return ContainerLayout.
StreamMap[StreamIndex];
109 if (
auto EC = Buffer->readBytes(StreamBlockOffset, NumBytes, Result))
110 return std::move(
EC);
117 "PDBFile is immutable");
128 "MSF superblock is missing");
134 if (Buffer->getLength() % SB->
BlockSize != 0)
136 "File size is not a multiple of block size");
137 ContainerLayout.
SB = SB;
155 MappedBlockStream::createFpmStream(ContainerLayout, *Buffer, Allocator);
162 for (
auto Byte : FpmBytes) {
163 uint32_t BlocksThisByte = std::min(BlocksRemaining, 8U);
192 auto DS = MappedBlockStream::createDirectoryStream(ContainerLayout, *Buffer,
203 uint64_t NumExpectedStreamBlocks =
204 StreamSize == UINT32_MAX
215 if (
auto EC = Reader.
readArray(Blocks, NumExpectedStreamBlocks))
218 uint64_t BlockEndOffset =
222 "Stream block map is corrupt.");
224 ContainerLayout.
StreamMap.push_back(Blocks);
229 DirectoryStream = std::move(
DS);
240 return MappedBlockStream::createIndexedStream(ContainerLayout, *Buffer, SN,
247 Result.
Blocks.assign(Blocks.begin(), Blocks.end());
260 return DbiS.takeError();
262 auto GlobalS = safelyCreateIndexedStream(
263 ContainerLayout, *Buffer, DbiS->getGlobalSymbolStreamIndex());
265 return GlobalS.takeError();
266 auto TempGlobals = llvm::make_unique<GlobalsStream>(std::move(*GlobalS));
267 if (
auto EC = TempGlobals->reload())
268 return std::move(
EC);
269 Globals = std::move(TempGlobals);
276 auto InfoS = safelyCreateIndexedStream(ContainerLayout, *Buffer,
StreamPDB);
278 return InfoS.takeError();
279 auto TempInfo = llvm::make_unique<InfoStream>(std::move(*InfoS));
280 if (
auto EC = TempInfo->reload())
281 return std::move(
EC);
282 Info = std::move(TempInfo);
289 auto DbiS = safelyCreateIndexedStream(ContainerLayout, *Buffer,
StreamDBI);
291 return DbiS.takeError();
292 auto TempDbi = llvm::make_unique<DbiStream>(std::move(*DbiS));
293 if (
auto EC = TempDbi->reload(
this))
294 return std::move(
EC);
295 Dbi = std::move(TempDbi);
302 auto TpiS = safelyCreateIndexedStream(ContainerLayout, *Buffer,
StreamTPI);
304 return TpiS.takeError();
305 auto TempTpi = llvm::make_unique<TpiStream>(*
this, std::move(*TpiS));
306 if (
auto EC = TempTpi->reload())
307 return std::move(
EC);
308 Tpi = std::move(TempTpi);
318 auto IpiS = safelyCreateIndexedStream(ContainerLayout, *Buffer,
StreamIPI);
320 return IpiS.takeError();
321 auto TempIpi = llvm::make_unique<TpiStream>(*
this, std::move(*IpiS));
322 if (
auto EC = TempIpi->reload())
323 return std::move(
EC);
324 Ipi = std::move(TempIpi);
333 return DbiS.takeError();
335 auto PublicS = safelyCreateIndexedStream(
336 ContainerLayout, *Buffer, DbiS->getPublicSymbolStreamIndex());
338 return PublicS.takeError();
339 auto TempPublics = llvm::make_unique<PublicsStream>(std::move(*PublicS));
340 if (
auto EC = TempPublics->reload())
341 return std::move(
EC);
342 Publics = std::move(TempPublics);
351 return DbiS.takeError();
353 uint32_t SymbolStreamNum = DbiS->getSymRecordStreamIndex();
355 safelyCreateIndexedStream(ContainerLayout, *Buffer, SymbolStreamNum);
357 return SymbolS.takeError();
359 auto TempSymbols = llvm::make_unique<SymbolStream>(std::move(*SymbolS));
360 if (
auto EC = TempSymbols->reload())
361 return std::move(
EC);
362 Symbols = std::move(TempSymbols);
371 return IS.takeError();
376 uint32_t NameStreamIndex = *ExpectedNSI;
379 safelyCreateIndexedStream(ContainerLayout, *Buffer, NameStreamIndex);
381 return NS.takeError();
383 auto N = llvm::make_unique<PDBStringTable>();
385 if (
auto EC =
N->reload(Reader))
386 return std::move(
EC);
387 assert(Reader.bytesRemaining() == 0);
388 StringTableStream = std::move(*NS);
389 Strings = std::move(
N);
405 return StreamDBI < getNumStreams() && getStreamByteSize(StreamDBI) > 0;
467 PDBFile::safelyCreateIndexedStream(
const MSFLayout &Layout,
472 return MappedBlockStream::createIndexedStream(Layout, MsfData, StreamIndex,
void resize(unsigned N, bool t=false)
resize - Grow or shrink the bitvector.
void cantFail(Error Err, const char *Msg=nullptr)
Report a fatal error if Err is a failure value.
Expected< PDBStringTable & > getStringTable()
bool hasPDBSymbolStream()
ArrayRef< support::ulittle32_t > getDirectoryBlockArray() const
This class represents lattice values for constants.
Error validateSuperBlock(const SuperBlock &SB)
Error readInteger(T &Dest)
Read an integer of the specified endianness into Dest and update the stream's offset.
uint32_t getNumDirectoryBlocks() const
uint64_t blockToOffset(uint64_t BlockNumber, uint64_t BlockSize)
Error readObject(const T *&Dest)
Get a pointer to an object of type T from the underlying stream, as if by memcpy, and store the resul...
Expected< GlobalsStream & > getPDBGlobalsStream()
Error takeError()
Take ownership of the stored error.
bool hasPDBPublicsStream()
Expected< TpiStream & > getPDBTpiStream()
uint32_t getNumStreams() const override
Error setBlockData(uint32_t BlockIndex, uint32_t Offset, ArrayRef< uint8_t > Data) const override
uint64_t getBlockMapOffset() const
Describes the layout of a stream in an MSF layout.
MSFStreamLayout getFpmStreamLayout(const MSFLayout &Msf, bool IncludeUnusedFpmData=false, bool AltFpm=false)
Determine the layout of the FPM stream, given the MSF layout.
bool hasPDBTpiStream() const
uint32_t getStreamByteSize(uint32_t StreamIndex) const override
msf::MSFStreamLayout getFpmStreamLayout() const
uint32_t getBlockSize() const override
Tagged union holding either a T or a Error.
uint32_t getUnknown1() const
uint32_t getPointerSize()
std::vector< support::ulittle32_t > Blocks
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
support::ulittle32_t BlockSize
COFF::MachineTypes Machine
bool hasPDBDbiStream() const
uint32_t getMaxStreamSize() const
const uint16_t kInvalidStreamIndex
support::ulittle32_t BlockMapAddr
uint32_t getNumDirectoryBytes() const
std::unique_ptr< msf::MappedBlockStream > createIndexedStream(uint16_t SN)
Allocate memory in an ever growing pool, as if by bump-pointer.
Expected< SymbolStream & > getPDBSymbolStream()
Expected< TpiStream & > getPDBIpiStream()
StringRef getFileDirectory() const
uint32_t getBlockMapIndex() const
StringRef parent_path(StringRef path, Style style=Style::native)
Get parent path.
void consumeError(Error Err)
Consume a Error without doing anything.
Expected< DbiStream & > getPDBDbiStream()
support::ulittle32_t Unknown1
uint32_t getFreeBlockMapBlock() const
void setOffset(uint32_t Off)
static ErrorSuccess success()
Create a success value.
ArrayRef< support::ulittle32_t > DirectoryBlocks
BinaryStreamRef is to BinaryStream what ArrayRef is to an Array.
bool hasPDBIpiStream() const
uint32_t getFileSize() const
StringRef getFilePath() const
Expected< PublicsStream & > getPDBPublicsStream()
uint64_t bytesToBlocks(uint64_t NumBytes, uint64_t BlockSize)
Error readBytes(ArrayRef< uint8_t > &Buffer, uint32_t Size)
Read Size bytes from the underlying stream at the current offset and and set Buffer to the resulting ...
std::vector< ArrayRef< support::ulittle32_t > > StreamMap
bool hasPDBGlobalsStream()
uint32_t bytesRemaining() const
Expected< ArrayRef< uint8_t > > getBlockData(uint32_t BlockIndex, uint32_t NumBytes) const override
ArrayRef< support::ulittle32_t > StreamSizes
Expected< InfoStream & > getPDBInfoStream()
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
support::ulittle32_t FreeBlockMapBlock
Lightweight error class with error context and mandatory checking.
bool containsIdStream() const
Provides read only access to a subclass of BinaryStream.
StringRef - Represent a constant reference to a string, i.e.
ArrayRef< support::ulittle32_t > getStreamBlockList(uint32_t StreamIndex) const override
uint32_t getBlockCount() const override
support::ulittle32_t NumDirectoryBytes
support::ulittle32_t NumBlocks
bool hasPDBInfoStream() 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 ...
msf::MSFStreamLayout getStreamLayout(uint32_t StreamIdx) const