summaryrefslogtreecommitdiffstats
path: root/llvm/lib/DebugInfo/PDB/Raw
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/DebugInfo/PDB/Raw')
-rw-r--r--llvm/lib/DebugInfo/PDB/Raw/DbiStream.cpp51
-rw-r--r--llvm/lib/DebugInfo/PDB/Raw/DbiStreamBuilder.cpp66
-rw-r--r--llvm/lib/DebugInfo/PDB/Raw/InfoStream.cpp17
-rw-r--r--llvm/lib/DebugInfo/PDB/Raw/InfoStreamBuilder.cpp55
-rw-r--r--llvm/lib/DebugInfo/PDB/Raw/ModInfo.cpp2
-rw-r--r--llvm/lib/DebugInfo/PDB/Raw/ModStream.cpp2
-rw-r--r--llvm/lib/DebugInfo/PDB/Raw/NameMap.cpp54
-rw-r--r--llvm/lib/DebugInfo/PDB/Raw/NameMapBuilder.cpp55
-rw-r--r--llvm/lib/DebugInfo/PDB/Raw/PDBFile.cpp186
-rw-r--r--llvm/lib/DebugInfo/PDB/Raw/PDBFileBuilder.cpp52
-rw-r--r--llvm/lib/DebugInfo/PDB/Raw/RawSession.cpp17
-rw-r--r--llvm/lib/DebugInfo/PDB/Raw/TpiStream.cpp11
12 files changed, 254 insertions, 314 deletions
diff --git a/llvm/lib/DebugInfo/PDB/Raw/DbiStream.cpp b/llvm/lib/DebugInfo/PDB/Raw/DbiStream.cpp
index 35f79c801ba..564246a332d 100644
--- a/llvm/lib/DebugInfo/PDB/Raw/DbiStream.cpp
+++ b/llvm/lib/DebugInfo/PDB/Raw/DbiStream.cpp
@@ -272,22 +272,21 @@ Error DbiStream::initializeSectionHeadersData() {
if (StreamNum >= Pdb.getNumStreams())
return make_error<RawError>(raw_error_code::no_stream);
- auto SHS = MappedBlockStream::createIndexedStream(StreamNum, Pdb);
- if (!SHS)
- return SHS.takeError();
+ auto SHS = MappedBlockStream::createIndexedStream(
+ Pdb.getMsfLayout(), Pdb.getMsfBuffer(), StreamNum);
- size_t StreamLen = (*SHS)->getLength();
+ size_t StreamLen = SHS->getLength();
if (StreamLen % sizeof(object::coff_section))
return make_error<RawError>(raw_error_code::corrupt_file,
"Corrupted section header stream.");
size_t NumSections = StreamLen / sizeof(object::coff_section);
- msf::StreamReader Reader(**SHS);
+ msf::StreamReader Reader(*SHS);
if (auto EC = Reader.readArray(SectionHeaders, NumSections))
return make_error<RawError>(raw_error_code::corrupt_file,
"Could not read a bitmap.");
- SectionHeaderStream = std::move(*SHS);
+ SectionHeaderStream = std::move(SHS);
return Error::success();
}
@@ -305,21 +304,20 @@ Error DbiStream::initializeFpoRecords() {
if (StreamNum >= Pdb.getNumStreams())
return make_error<RawError>(raw_error_code::no_stream);
- auto FS = MappedBlockStream::createIndexedStream(StreamNum, Pdb);
- if (!FS)
- return FS.takeError();
+ auto FS = MappedBlockStream::createIndexedStream(
+ Pdb.getMsfLayout(), Pdb.getMsfBuffer(), StreamNum);
- size_t StreamLen = (*FS)->getLength();
+ size_t StreamLen = FS->getLength();
if (StreamLen % sizeof(object::FpoData))
return make_error<RawError>(raw_error_code::corrupt_file,
"Corrupted New FPO stream.");
size_t NumRecords = StreamLen / sizeof(object::FpoData);
- msf::StreamReader Reader(**FS);
+ msf::StreamReader Reader(*FS);
if (auto EC = Reader.readArray(FpoRecords, NumRecords))
return make_error<RawError>(raw_error_code::corrupt_file,
"Corrupted New FPO stream.");
- FpoStream = std::move(*FS);
+ FpoStream = std::move(FS);
return Error::success();
}
@@ -421,32 +419,3 @@ Expected<StringRef> DbiStream::getFileNameForIndex(uint32_t Index) const {
return std::move(EC);
return Name;
}
-
-Error DbiStream::commit() {
- StreamWriter Writer(*Stream);
- if (auto EC = Writer.writeObject(*Header))
- return EC;
-
- if (auto EC = Writer.writeStreamRef(ModInfoSubstream))
- return EC;
-
- if (auto EC = Writer.writeStreamRef(SecContrSubstream,
- SecContrSubstream.getLength()))
- return EC;
- if (auto EC =
- Writer.writeStreamRef(SecMapSubstream, SecMapSubstream.getLength()))
- return EC;
- if (auto EC = Writer.writeStreamRef(FileInfoSubstream,
- FileInfoSubstream.getLength()))
- return EC;
- if (auto EC = Writer.writeStreamRef(TypeServerMapSubstream,
- TypeServerMapSubstream.getLength()))
- return EC;
- if (auto EC = Writer.writeStreamRef(ECSubstream, ECSubstream.getLength()))
- return EC;
-
- if (Writer.bytesRemaining() > 0)
- return make_error<RawError>(raw_error_code::invalid_format,
- "Unexpected bytes found in DBI Stream");
- return Error::success();
-}
diff --git a/llvm/lib/DebugInfo/PDB/Raw/DbiStreamBuilder.cpp b/llvm/lib/DebugInfo/PDB/Raw/DbiStreamBuilder.cpp
index 7a688cb8968..6e1282263f6 100644
--- a/llvm/lib/DebugInfo/PDB/Raw/DbiStreamBuilder.cpp
+++ b/llvm/lib/DebugInfo/PDB/Raw/DbiStreamBuilder.cpp
@@ -25,7 +25,7 @@ class ModiSubstreamBuilder {};
DbiStreamBuilder::DbiStreamBuilder(BumpPtrAllocator &Allocator)
: Allocator(Allocator), Age(1), BuildNumber(0), PdbDllVersion(0),
- PdbDllRbld(0), Flags(0), MachineType(PDB_Machine::x86) {}
+ PdbDllRbld(0), Flags(0), MachineType(PDB_Machine::x86), Header(nullptr) {}
void DbiStreamBuilder::setVersionHeader(PdbRaw_DbiVer V) { VerHeader = V; }
@@ -108,7 +108,7 @@ Error DbiStreamBuilder::generateModiSubstream() {
uint32_t Size = calculateModiSubstreamSize();
auto Data = Allocator.Allocate<uint8_t>(Size);
- ModInfoBuffer = ByteStream<true>(MutableArrayRef<uint8_t>(Data, Size));
+ ModInfoBuffer = MutableByteStream(MutableArrayRef<uint8_t>(Data, Size));
StreamWriter ModiWriter(ModInfoBuffer);
for (const auto &M : ModuleInfoList) {
@@ -134,9 +134,10 @@ Error DbiStreamBuilder::generateFileInfoSubstream() {
auto Data = Allocator.Allocate<uint8_t>(Size);
uint32_t NamesOffset = Size - NameSize;
- FileInfoBuffer = ByteStream<true>(MutableArrayRef<uint8_t>(Data, Size));
+ FileInfoBuffer = MutableByteStream(MutableArrayRef<uint8_t>(Data, Size));
- StreamRef MetadataBuffer = StreamRef(FileInfoBuffer).keep_front(NamesOffset);
+ WritableStreamRef MetadataBuffer =
+ WritableStreamRef(FileInfoBuffer).keep_front(NamesOffset);
StreamWriter MetadataWriter(MetadataBuffer);
uint16_t ModiCount = std::min<uint16_t>(UINT16_MAX, ModuleInfos.size());
@@ -159,7 +160,7 @@ Error DbiStreamBuilder::generateFileInfoSubstream() {
// A side effect of this is that this will actually compute the various
// file name offsets, so we can then go back and write the FileNameOffsets
// array to the other substream.
- NamesBuffer = StreamRef(FileInfoBuffer).drop_front(NamesOffset);
+ NamesBuffer = WritableStreamRef(FileInfoBuffer).drop_front(NamesOffset);
StreamWriter NameBufferWriter(NamesBuffer);
for (auto &Name : SourceFileNames) {
Name.second = NameBufferWriter.getOffset();
@@ -190,16 +191,11 @@ Error DbiStreamBuilder::generateFileInfoSubstream() {
return Error::success();
}
-Expected<std::unique_ptr<DbiStream>> DbiStreamBuilder::build(PDBFile &File) {
- if (!VerHeader.hasValue())
- return make_error<RawError>(raw_error_code::unspecified,
- "Missing DBI Stream Version");
+Error DbiStreamBuilder::finalize() {
+ if (Header)
+ return Error::success();
- auto DbiS = MappedBlockStream::createIndexedStream(StreamDBI, File);
- if (!DbiS)
- return DbiS.takeError();
- auto DS = std::move(*DbiS);
- DbiStreamHeader *H = DS->getAllocator().Allocate<DbiStreamHeader>(1);
+ DbiStreamHeader *H = Allocator.Allocate<DbiStreamHeader>();
if (auto EC = generateModiSubstream())
return std::move(EC);
@@ -227,13 +223,47 @@ Expected<std::unique_ptr<DbiStream>> DbiStreamBuilder::build(PDBFile &File) {
H->MFCTypeServerIndex = kInvalidStreamIndex;
H->GlobalSymbolStreamIndex = kInvalidStreamIndex;
- auto Dbi = llvm::make_unique<DbiStream>(File, std::move(DS));
- Dbi->Header = H;
- Dbi->FileInfoSubstream = StreamRef(FileInfoBuffer);
- Dbi->ModInfoSubstream = StreamRef(ModInfoBuffer);
+ Header = H;
+ return Error::success();
+}
+
+Expected<std::unique_ptr<DbiStream>>
+DbiStreamBuilder::build(PDBFile &File, const msf::WritableStream &Buffer) {
+ if (!VerHeader.hasValue())
+ return make_error<RawError>(raw_error_code::unspecified,
+ "Missing DBI Stream Version");
+ if (auto EC = finalize())
+ return std::move(EC);
+
+ auto StreamData = MappedBlockStream::createIndexedStream(File.getMsfLayout(),
+ Buffer, StreamDBI);
+ auto Dbi = llvm::make_unique<DbiStream>(File, std::move(StreamData));
+ Dbi->Header = Header;
+ Dbi->FileInfoSubstream = ReadableStreamRef(FileInfoBuffer);
+ Dbi->ModInfoSubstream = ReadableStreamRef(ModInfoBuffer);
if (auto EC = Dbi->initializeModInfoArray())
return std::move(EC);
if (auto EC = Dbi->initializeFileInfo())
return std::move(EC);
return std::move(Dbi);
}
+
+Error DbiStreamBuilder::commit(const msf::MsfLayout &Layout,
+ const msf::WritableStream &Buffer) const {
+ auto InfoS =
+ WritableMappedBlockStream::createIndexedStream(Layout, Buffer, StreamDBI);
+
+ StreamWriter Writer(*InfoS);
+ if (auto EC = Writer.writeObject(*Header))
+ return EC;
+
+ if (auto EC = Writer.writeStreamRef(ModInfoBuffer))
+ return EC;
+ if (auto EC = Writer.writeStreamRef(FileInfoBuffer))
+ return EC;
+
+ if (Writer.bytesRemaining() > 0)
+ return make_error<RawError>(raw_error_code::invalid_format,
+ "Unexpected bytes found in DBI Stream");
+ return Error::success();
+}
diff --git a/llvm/lib/DebugInfo/PDB/Raw/InfoStream.cpp b/llvm/lib/DebugInfo/PDB/Raw/InfoStream.cpp
index c55f51d7d4a..4df24f240f3 100644
--- a/llvm/lib/DebugInfo/PDB/Raw/InfoStream.cpp
+++ b/llvm/lib/DebugInfo/PDB/Raw/InfoStream.cpp
@@ -15,6 +15,7 @@
#include "llvm/DebugInfo/PDB/Raw/PDBFile.h"
#include "llvm/DebugInfo/PDB/Raw/RawConstants.h"
#include "llvm/DebugInfo/PDB/Raw/RawError.h"
+#include "llvm/DebugInfo/PDB/Raw/RawTypes.h"
using namespace llvm;
using namespace llvm::codeview;
@@ -27,7 +28,7 @@ InfoStream::InfoStream(std::unique_ptr<MappedBlockStream> Stream)
Error InfoStream::reload() {
StreamReader Reader(*Stream);
- const HeaderInfo *H;
+ const InfoStreamHeader *H;
if (auto EC = Reader.readObject(H))
return joinErrors(
std::move(EC),
@@ -74,17 +75,3 @@ uint32_t InfoStream::getSignature() const { return Signature; }
uint32_t InfoStream::getAge() const { return Age; }
PDB_UniqueId InfoStream::getGuid() const { return Guid; }
-
-Error InfoStream::commit() {
- StreamWriter Writer(*Stream);
-
- HeaderInfo H;
- H.Age = Age;
- H.Signature = Signature;
- H.Version = Version;
- H.Guid = Guid;
- if (auto EC = Writer.writeObject(H))
- return EC;
-
- return NamedStreams.commit(Writer);
-}
diff --git a/llvm/lib/DebugInfo/PDB/Raw/InfoStreamBuilder.cpp b/llvm/lib/DebugInfo/PDB/Raw/InfoStreamBuilder.cpp
index 444aba6be0b..d20c37d9f29 100644
--- a/llvm/lib/DebugInfo/PDB/Raw/InfoStreamBuilder.cpp
+++ b/llvm/lib/DebugInfo/PDB/Raw/InfoStreamBuilder.cpp
@@ -13,13 +13,15 @@
#include "llvm/DebugInfo/Msf/StreamWriter.h"
#include "llvm/DebugInfo/PDB/Raw/InfoStream.h"
#include "llvm/DebugInfo/PDB/Raw/RawError.h"
+#include "llvm/DebugInfo/PDB/Raw/RawTypes.h"
using namespace llvm;
using namespace llvm::codeview;
using namespace llvm::msf;
using namespace llvm::pdb;
-InfoStreamBuilder::InfoStreamBuilder() {}
+InfoStreamBuilder::InfoStreamBuilder()
+ : Ver(PdbRaw_ImplVer::PdbImplVC70), Sig(-1), Age(0) {}
void InfoStreamBuilder::setVersion(PdbRaw_ImplVer V) { Ver = V; }
@@ -34,35 +36,38 @@ NameMapBuilder &InfoStreamBuilder::getNamedStreamsBuilder() {
}
uint32_t InfoStreamBuilder::calculateSerializedLength() const {
- return sizeof(InfoStream::HeaderInfo) +
- NamedStreams.calculateSerializedLength();
+ return sizeof(InfoStreamHeader) + NamedStreams.calculateSerializedLength();
}
-Expected<std::unique_ptr<InfoStream>> InfoStreamBuilder::build(PDBFile &File) {
- if (!Ver.hasValue())
- return make_error<RawError>(raw_error_code::unspecified,
- "Missing PDB Stream Version");
- if (!Sig.hasValue())
- return make_error<RawError>(raw_error_code::unspecified,
- "Missing PDB Stream Signature");
- if (!Age.hasValue())
- return make_error<RawError>(raw_error_code::unspecified,
- "Missing PDB Stream Age");
- if (!Guid.hasValue())
- return make_error<RawError>(raw_error_code::unspecified,
- "Missing PDB Stream Guid");
-
- auto InfoS = MappedBlockStream::createIndexedStream(StreamPDB, File);
- if (!InfoS)
- return InfoS.takeError();
- auto Info = llvm::make_unique<InfoStream>(std::move(*InfoS));
- Info->Version = *Ver;
- Info->Signature = *Sig;
- Info->Age = *Age;
- Info->Guid = *Guid;
+Expected<std::unique_ptr<InfoStream>>
+InfoStreamBuilder::build(PDBFile &File, const msf::WritableStream &Buffer) {
+ auto StreamData = MappedBlockStream::createIndexedStream(File.getMsfLayout(),
+ Buffer, StreamPDB);
+ auto Info = llvm::make_unique<InfoStream>(std::move(StreamData));
+ Info->Version = Ver;
+ Info->Signature = Sig;
+ Info->Age = Age;
+ Info->Guid = Guid;
auto NS = NamedStreams.build();
if (!NS)
return NS.takeError();
Info->NamedStreams = **NS;
return std::move(Info);
}
+
+Error InfoStreamBuilder::commit(const msf::MsfLayout &Layout,
+ const msf::WritableStream &Buffer) const {
+ auto InfoS =
+ WritableMappedBlockStream::createIndexedStream(Layout, Buffer, StreamPDB);
+ StreamWriter Writer(*InfoS);
+
+ InfoStreamHeader H;
+ H.Age = Age;
+ H.Signature = Sig;
+ H.Version = Ver;
+ H.Guid = Guid;
+ if (auto EC = Writer.writeObject(H))
+ return EC;
+
+ return NamedStreams.commit(Writer);
+}
diff --git a/llvm/lib/DebugInfo/PDB/Raw/ModInfo.cpp b/llvm/lib/DebugInfo/PDB/Raw/ModInfo.cpp
index 89a03ec3a4d..7b77bcda421 100644
--- a/llvm/lib/DebugInfo/PDB/Raw/ModInfo.cpp
+++ b/llvm/lib/DebugInfo/PDB/Raw/ModInfo.cpp
@@ -27,7 +27,7 @@ ModInfo::ModInfo(const ModInfo &Info)
ModInfo::~ModInfo() {}
-Error ModInfo::initialize(StreamRef Stream, ModInfo &Info) {
+Error ModInfo::initialize(ReadableStreamRef Stream, ModInfo &Info) {
StreamReader Reader(Stream);
if (auto EC = Reader.readObject(Info.Layout))
return EC;
diff --git a/llvm/lib/DebugInfo/PDB/Raw/ModStream.cpp b/llvm/lib/DebugInfo/PDB/Raw/ModStream.cpp
index 65d59a5e894..25bb9d15165 100644
--- a/llvm/lib/DebugInfo/PDB/Raw/ModStream.cpp
+++ b/llvm/lib/DebugInfo/PDB/Raw/ModStream.cpp
@@ -36,7 +36,7 @@ Error ModStream::reload() {
return llvm::make_error<RawError>(raw_error_code::corrupt_file,
"Module has both C11 and C13 line info");
- StreamRef S;
+ ReadableStreamRef S;
uint32_t SymbolSubstreamSig = 0;
if (auto EC = Reader.readInteger(SymbolSubstreamSig))
diff --git a/llvm/lib/DebugInfo/PDB/Raw/NameMap.cpp b/llvm/lib/DebugInfo/PDB/Raw/NameMap.cpp
index e17600986c9..70b810f1522 100644
--- a/llvm/lib/DebugInfo/PDB/Raw/NameMap.cpp
+++ b/llvm/lib/DebugInfo/PDB/Raw/NameMap.cpp
@@ -145,60 +145,6 @@ Error NameMap::load(StreamReader &Stream) {
return Error::success();
}
-Error NameMap::commit(StreamWriter &Writer) {
- // The first field is the number of bytes of string data. So add
- // up the length of all strings plus a null terminator for each
- // one.
- uint32_t NumBytes = 0;
- for (auto B = Mapping.begin(), E = Mapping.end(); B != E; ++B) {
- NumBytes += B->getKeyLength() + 1;
- }
-
- if (auto EC = Writer.writeInteger(NumBytes)) // Number of bytes of string data
- return EC;
- // Now all of the string data itself.
- for (auto B = Mapping.begin(), E = Mapping.end(); B != E; ++B) {
- if (auto EC = Writer.writeZeroString(B->getKey()))
- return EC;
- }
-
- if (auto EC = Writer.writeInteger(Mapping.size())) // Hash Size
- return EC;
-
- if (auto EC = Writer.writeInteger(Mapping.size())) // Max Number of Strings
- return EC;
-
- if (auto EC = Writer.writeInteger(Mapping.size())) // Num Present Words
- return EC;
-
- // For each entry in the mapping, write a bit mask which represents a bucket
- // to store it in. We don't use this, so the value we write isn't important
- // to us, it just has to be there.
- for (auto B = Mapping.begin(), E = Mapping.end(); B != E; ++B) {
- if (auto EC = Writer.writeInteger(1U))
- return EC;
- }
-
- if (auto EC = Writer.writeInteger(0U)) // Num Deleted Words
- return EC;
-
- // Mappings of each word.
- uint32_t OffsetSoFar = 0;
- for (auto B = Mapping.begin(), E = Mapping.end(); B != E; ++B) {
- // This is a list of key value pairs where the key is the offset into the
- // strings buffer, and the value is a stream number. Write each pair.
- if (auto EC = Writer.writeInteger(OffsetSoFar))
- return EC;
-
- if (auto EC = Writer.writeInteger(B->second))
- return EC;
-
- OffsetSoFar += B->getKeyLength() + 1;
- }
-
- return Error::success();
-}
-
iterator_range<StringMapConstIterator<uint32_t>> NameMap::entries() const {
return llvm::make_range<StringMapConstIterator<uint32_t>>(Mapping.begin(),
Mapping.end());
diff --git a/llvm/lib/DebugInfo/PDB/Raw/NameMapBuilder.cpp b/llvm/lib/DebugInfo/PDB/Raw/NameMapBuilder.cpp
index 41c6c2cd810..3bb4503fe6a 100644
--- a/llvm/lib/DebugInfo/PDB/Raw/NameMapBuilder.cpp
+++ b/llvm/lib/DebugInfo/PDB/Raw/NameMapBuilder.cpp
@@ -9,6 +9,7 @@
#include "llvm/DebugInfo/PDB/Raw/NameMapBuilder.h"
+#include "llvm/DebugInfo/Msf/StreamWriter.h"
#include "llvm/DebugInfo/PDB/Raw/NameMap.h"
#include "llvm/Support/Endian.h"
@@ -48,3 +49,57 @@ uint32_t NameMapBuilder::calculateSerializedLength() const {
return TotalLength;
}
+
+Error NameMapBuilder::commit(msf::StreamWriter &Writer) const {
+ // The first field is the number of bytes of string data. So add
+ // up the length of all strings plus a null terminator for each
+ // one.
+ uint32_t NumBytes = 0;
+ for (auto B = Map.begin(), E = Map.end(); B != E; ++B) {
+ NumBytes += B->getKeyLength() + 1;
+ }
+
+ if (auto EC = Writer.writeInteger(NumBytes)) // Number of bytes of string data
+ return EC;
+ // Now all of the string data itself.
+ for (auto B = Map.begin(), E = Map.end(); B != E; ++B) {
+ if (auto EC = Writer.writeZeroString(B->getKey()))
+ return EC;
+ }
+
+ if (auto EC = Writer.writeInteger(Map.size())) // Hash Size
+ return EC;
+
+ if (auto EC = Writer.writeInteger(Map.size())) // Max Number of Strings
+ return EC;
+
+ if (auto EC = Writer.writeInteger(Map.size())) // Num Present Words
+ return EC;
+
+ // For each entry in the mapping, write a bit mask which represents a bucket
+ // to store it in. We don't use this, so the value we write isn't important
+ // to us, it just has to be there.
+ for (auto B = Map.begin(), E = Map.end(); B != E; ++B) {
+ if (auto EC = Writer.writeInteger(1U))
+ return EC;
+ }
+
+ if (auto EC = Writer.writeInteger(0U)) // Num Deleted Words
+ return EC;
+
+ // Mappings of each word.
+ uint32_t OffsetSoFar = 0;
+ for (auto B = Map.begin(), E = Map.end(); B != E; ++B) {
+ // This is a list of key value pairs where the key is the offset into the
+ // strings buffer, and the value is a stream number. Write each pair.
+ if (auto EC = Writer.writeInteger(OffsetSoFar))
+ return EC;
+
+ if (auto EC = Writer.writeInteger(B->second))
+ return EC;
+
+ OffsetSoFar += B->getKeyLength() + 1;
+ }
+
+ return Error::success();
+}
diff --git a/llvm/lib/DebugInfo/PDB/Raw/PDBFile.cpp b/llvm/lib/DebugInfo/PDB/Raw/PDBFile.cpp
index ea0a8c91304..3529860899e 100644
--- a/llvm/lib/DebugInfo/PDB/Raw/PDBFile.cpp
+++ b/llvm/lib/DebugInfo/PDB/Raw/PDBFile.cpp
@@ -34,48 +34,53 @@ namespace {
typedef FixedStreamArray<support::ulittle32_t> ulittle_array;
}
-PDBFile::PDBFile(std::unique_ptr<StreamInterface> PdbFileBuffer,
+PDBFile::PDBFile(std::unique_ptr<ReadableStream> PdbFileBuffer,
BumpPtrAllocator &Allocator)
: Allocator(Allocator), Buffer(std::move(PdbFileBuffer)) {}
PDBFile::~PDBFile() {}
-uint32_t PDBFile::getBlockSize() const { return MsfLayout.SB->BlockSize; }
+uint32_t PDBFile::getBlockSize() const { return ContainerLayout.SB->BlockSize; }
uint32_t PDBFile::getFreeBlockMapBlock() const {
- return MsfLayout.SB->FreeBlockMapBlock;
+ return ContainerLayout.SB->FreeBlockMapBlock;
}
-uint32_t PDBFile::getBlockCount() const { return MsfLayout.SB->NumBlocks; }
+uint32_t PDBFile::getBlockCount() const {
+ return ContainerLayout.SB->NumBlocks;
+}
uint32_t PDBFile::getNumDirectoryBytes() const {
- return MsfLayout.SB->NumDirectoryBytes;
+ return ContainerLayout.SB->NumDirectoryBytes;
}
uint32_t PDBFile::getBlockMapIndex() const {
- return MsfLayout.SB->BlockMapAddr;
+ return ContainerLayout.SB->BlockMapAddr;
}
-uint32_t PDBFile::getUnknown1() const { return MsfLayout.SB->Unknown1; }
+uint32_t PDBFile::getUnknown1() const { return ContainerLayout.SB->Unknown1; }
uint32_t PDBFile::getNumDirectoryBlocks() const {
- return msf::bytesToBlocks(MsfLayout.SB->NumDirectoryBytes,
- MsfLayout.SB->BlockSize);
+ return msf::bytesToBlocks(ContainerLayout.SB->NumDirectoryBytes,
+ ContainerLayout.SB->BlockSize);
}
uint64_t PDBFile::getBlockMapOffset() const {
- return (uint64_t)MsfLayout.SB->BlockMapAddr * MsfLayout.SB->BlockSize;
+ return (uint64_t)ContainerLayout.SB->BlockMapAddr *
+ ContainerLayout.SB->BlockSize;
}
-uint32_t PDBFile::getNumStreams() const { return MsfLayout.StreamSizes.size(); }
+uint32_t PDBFile::getNumStreams() const {
+ return ContainerLayout.StreamSizes.size();
+}
uint32_t PDBFile::getStreamByteSize(uint32_t StreamIndex) const {
- return MsfLayout.StreamSizes[StreamIndex];
+ return ContainerLayout.StreamSizes[StreamIndex];
}
ArrayRef<support::ulittle32_t>
PDBFile::getStreamBlockList(uint32_t StreamIndex) const {
- return MsfLayout.StreamMap[StreamIndex];
+ return ContainerLayout.StreamMap[StreamIndex];
}
uint32_t PDBFile::getFileSize() const { return Buffer->getLength(); }
@@ -92,18 +97,8 @@ Expected<ArrayRef<uint8_t>> PDBFile::getBlockData(uint32_t BlockIndex,
Error PDBFile::setBlockData(uint32_t BlockIndex, uint32_t Offset,
ArrayRef<uint8_t> Data) const {
- if (Offset >= getBlockSize())
- return make_error<RawError>(
- raw_error_code::invalid_block_address,
- "setBlockData attempted to write out of block bounds.");
- if (Data.size() > getBlockSize() - Offset)
- return make_error<RawError>(
- raw_error_code::invalid_block_address,
- "setBlockData attempted to write out of block bounds.");
-
- uint64_t StreamBlockOffset = msf::blockToOffset(BlockIndex, getBlockSize());
- StreamBlockOffset += Offset;
- return Buffer->writeBytes(StreamBlockOffset, Data);
+ return make_error<RawError>(raw_error_code::not_writable,
+ "PDBFile is immutable");
}
Error PDBFile::parseFileHeaders() {
@@ -122,18 +117,18 @@ Error PDBFile::parseFileHeaders() {
if (Buffer->getLength() % SB->BlockSize != 0)
return make_error<RawError>(raw_error_code::corrupt_file,
"File size is not a multiple of block size");
- MsfLayout.SB = SB;
+ ContainerLayout.SB = SB;
Reader.setOffset(getBlockMapOffset());
- if (auto EC =
- Reader.readArray(MsfLayout.DirectoryBlocks, getNumDirectoryBlocks()))
+ if (auto EC = Reader.readArray(ContainerLayout.DirectoryBlocks,
+ getNumDirectoryBlocks()))
return EC;
return Error::success();
}
Error PDBFile::parseStreamData() {
- assert(MsfLayout.SB);
+ assert(ContainerLayout.SB);
if (DirectoryStream)
return Error::success();
@@ -144,15 +139,12 @@ Error PDBFile::parseStreamData() {
// is exactly what we are attempting to parse. By specifying a custom
// subclass of IPDBStreamData which only accesses the fields that have already
// been parsed, we can avoid this and reuse MappedBlockStream.
- auto DS = MappedBlockStream::createDirectoryStream(
- MsfLayout.SB->NumDirectoryBytes, getDirectoryBlockArray(), *this);
- if (!DS)
- return DS.takeError();
- StreamReader Reader(**DS);
+ auto DS = MappedBlockStream::createDirectoryStream(ContainerLayout, *Buffer);
+ StreamReader Reader(*DS);
if (auto EC = Reader.readInteger(NumStreams))
return EC;
- if (auto EC = Reader.readArray(MsfLayout.StreamSizes, NumStreams))
+ if (auto EC = Reader.readArray(ContainerLayout.StreamSizes, NumStreams))
return EC;
for (uint32_t I = 0; I < NumStreams; ++I) {
uint32_t StreamSize = getStreamByteSize(I);
@@ -160,7 +152,7 @@ Error PDBFile::parseStreamData() {
uint64_t NumExpectedStreamBlocks =
StreamSize == UINT32_MAX
? 0
- : msf::bytesToBlocks(StreamSize, MsfLayout.SB->BlockSize);
+ : msf::bytesToBlocks(StreamSize, ContainerLayout.SB->BlockSize);
// For convenience, we store the block array contiguously. This is because
// if someone calls setStreamMap(), it is more convenient to be able to call
@@ -172,30 +164,30 @@ Error PDBFile::parseStreamData() {
if (auto EC = Reader.readArray(Blocks, NumExpectedStreamBlocks))
return EC;
for (uint32_t Block : Blocks) {
- uint64_t BlockEndOffset = (uint64_t)(Block + 1) * MsfLayout.SB->BlockSize;
+ uint64_t BlockEndOffset =
+ (uint64_t)(Block + 1) * ContainerLayout.SB->BlockSize;
if (BlockEndOffset > getFileSize())
return make_error<RawError>(raw_error_code::corrupt_file,
"Stream block map is corrupt.");
}
- MsfLayout.StreamMap.push_back(Blocks);
+ ContainerLayout.StreamMap.push_back(Blocks);
}
// We should have read exactly SB->NumDirectoryBytes bytes.
assert(Reader.bytesRemaining() == 0);
- DirectoryStream = std::move(*DS);
+ DirectoryStream = std::move(DS);
return Error::success();
}
llvm::ArrayRef<support::ulittle32_t> PDBFile::getDirectoryBlockArray() const {
- return MsfLayout.DirectoryBlocks;
+ return ContainerLayout.DirectoryBlocks;
}
Expected<InfoStream &> PDBFile::getPDBInfoStream() {
if (!Info) {
- auto InfoS = MappedBlockStream::createIndexedStream(StreamPDB, *this);
- if (!InfoS)
- return InfoS.takeError();
- auto TempInfo = llvm::make_unique<InfoStream>(std::move(*InfoS));
+ auto InfoS = MappedBlockStream::createIndexedStream(ContainerLayout,
+ *Buffer, StreamPDB);
+ auto TempInfo = llvm::make_unique<InfoStream>(std::move(InfoS));
if (auto EC = TempInfo->reload())
return std::move(EC);
Info = std::move(TempInfo);
@@ -205,10 +197,9 @@ Expected<InfoStream &> PDBFile::getPDBInfoStream() {
Expected<DbiStream &> PDBFile::getPDBDbiStream() {
if (!Dbi) {
- auto DbiS = MappedBlockStream::createIndexedStream(StreamDBI, *this);
- if (!DbiS)
- return DbiS.takeError();
- auto TempDbi = llvm::make_unique<DbiStream>(*this, std::move(*DbiS));
+ auto DbiS = MappedBlockStream::createIndexedStream(ContainerLayout, *Buffer,
+ StreamDBI);
+ auto TempDbi = llvm::make_unique<DbiStream>(*this, std::move(DbiS));
if (auto EC = TempDbi->reload())
return std::move(EC);
Dbi = std::move(TempDbi);
@@ -218,10 +209,9 @@ Expected<DbiStream &> PDBFile::getPDBDbiStream() {
Expected<TpiStream &> PDBFile::getPDBTpiStream() {
if (!Tpi) {
- auto TpiS = MappedBlockStream::createIndexedStream(StreamTPI, *this);
- if (!TpiS)
- return TpiS.takeError();
- auto TempTpi = llvm::make_unique<TpiStream>(*this, std::move(*TpiS));
+ auto TpiS = MappedBlockStream::createIndexedStream(ContainerLayout, *Buffer,
+ StreamTPI);
+ auto TempTpi = llvm::make_unique<TpiStream>(*this, std::move(TpiS));
if (auto EC = TempTpi->reload())
return std::move(EC);
Tpi = std::move(TempTpi);
@@ -231,10 +221,9 @@ Expected<TpiStream &> PDBFile::getPDBTpiStream() {
Expected<TpiStream &> PDBFile::getPDBIpiStream() {
if (!Ipi) {
- auto IpiS = MappedBlockStream::createIndexedStream(StreamIPI, *this);
- if (!IpiS)
- return IpiS.takeError();
- auto TempIpi = llvm::make_unique<TpiStream>(*this, std::move(*IpiS));
+ auto IpiS = MappedBlockStream::createIndexedStream(ContainerLayout, *Buffer,
+ StreamIPI);
+ auto TempIpi = llvm::make_unique<TpiStream>(*this, std::move(IpiS));
if (auto EC = TempIpi->reload())
return std::move(EC);
Ipi = std::move(TempIpi);
@@ -250,12 +239,10 @@ Expected<PublicsStream &> PDBFile::getPDBPublicsStream() {
uint32_t PublicsStreamNum = DbiS->getPublicSymbolStreamIndex();
- auto PublicS =
- MappedBlockStream::createIndexedStream(PublicsStreamNum, *this);
- if (!PublicS)
- return PublicS.takeError();
+ auto PublicS = MappedBlockStream::createIndexedStream(
+ ContainerLayout, *Buffer, PublicsStreamNum);
auto TempPublics =
- llvm::make_unique<PublicsStream>(*this, std::move(*PublicS));
+ llvm::make_unique<PublicsStream>(*this, std::move(PublicS));
if (auto EC = TempPublics->reload())
return std::move(EC);
Publics = std::move(TempPublics);
@@ -270,12 +257,10 @@ Expected<SymbolStream &> PDBFile::getPDBSymbolStream() {
return DbiS.takeError();
uint32_t SymbolStreamNum = DbiS->getSymRecordStreamIndex();
+ auto SymbolS = MappedBlockStream::createIndexedStream(
+ ContainerLayout, *Buffer, SymbolStreamNum);
- auto SymbolS =
- MappedBlockStream::createIndexedStream(SymbolStreamNum, *this);
- if (!SymbolS)
- return SymbolS.takeError();
- auto TempSymbols = llvm::make_unique<SymbolStream>(std::move(*SymbolS));
+ auto TempSymbols = llvm::make_unique<SymbolStream>(std::move(SymbolS));
if (auto EC = TempSymbols->reload())
return std::move(EC);
Symbols = std::move(TempSymbols);
@@ -295,76 +280,15 @@ Expected<NameHashTable &> PDBFile::getStringTable() {
return make_error<RawError>(raw_error_code::no_stream);
if (NameStreamIndex >= getNumStreams())
return make_error<RawError>(raw_error_code::no_stream);
+ auto NS = MappedBlockStream::createIndexedStream(ContainerLayout, *Buffer,
+ NameStreamIndex);
- auto NS = MappedBlockStream::createIndexedStream(NameStreamIndex, *this);
- if (!NS)
- return NS.takeError();
-
- StreamReader Reader(**NS);
+ StreamReader Reader(*NS);
auto N = llvm::make_unique<NameHashTable>();
if (auto EC = N->load(Reader))
return std::move(EC);
StringTable = std::move(N);
- StringTableStream = std::move(*NS);
+ StringTableStream = std::move(NS);
}
return *StringTable;
}
-
-Error PDBFile::commit() {
- StreamWriter Writer(*Buffer);
-
- if (auto EC = Writer.writeObject(*MsfLayout.SB))
- return EC;
- Writer.setOffset(getBlockMapOffset());
- if (auto EC = Writer.writeArray(MsfLayout.DirectoryBlocks))
- return EC;
-
- auto DS = MappedBlockStream::createDirectoryStream(
- MsfLayout.SB->NumDirectoryBytes, getDirectoryBlockArray(), *this);
- if (!DS)
- return DS.takeError();
- auto DirStream = std::move(*DS);
- StreamWriter DW(*DirStream);
- if (auto EC = DW.writeInteger(this->getNumStreams()))
- return EC;
-
- if (auto EC = DW.writeArray(MsfLayout.StreamSizes))
- return EC;
-
- for (const auto &Blocks : MsfLayout.StreamMap) {
- if (auto EC = DW.writeArray(Blocks))
- return EC;
- }
-
- if (Info) {
- if (auto EC = Info->commit())
- return EC;
- }
-
- if (Dbi) {
- if (auto EC = Dbi->commit())
- return EC;
- }
-
- if (Symbols) {
- if (auto EC = Symbols->commit())
- return EC;
- }
-
- if (Publics) {
- if (auto EC = Publics->commit())
- return EC;
- }
-
- if (Tpi) {
- if (auto EC = Tpi->commit())
- return EC;
- }
-
- if (Ipi) {
- if (auto EC = Ipi->commit())
- return EC;
- }
-
- return Buffer->commit();
-}
diff --git a/llvm/lib/DebugInfo/PDB/Raw/PDBFileBuilder.cpp b/llvm/lib/DebugInfo/PDB/Raw/PDBFileBuilder.cpp
index 5007a56f276..6715f3d3fa1 100644
--- a/llvm/lib/DebugInfo/PDB/Raw/PDBFileBuilder.cpp
+++ b/llvm/lib/DebugInfo/PDB/Raw/PDBFileBuilder.cpp
@@ -58,7 +58,7 @@ DbiStreamBuilder &PDBFileBuilder::getDbiBuilder() {
return *Dbi;
}
-Expected<msf::Layout> PDBFileBuilder::finalizeMsfLayout() const {
+Expected<msf::MsfLayout> PDBFileBuilder::finalizeMsfLayout() const {
if (Info) {
uint32_t Length = Info->calculateSerializedLength();
if (auto EC = Msf->setStreamSize(StreamPDB, Length))
@@ -74,23 +74,23 @@ Expected<msf::Layout> PDBFileBuilder::finalizeMsfLayout() const {
}
Expected<std::unique_ptr<PDBFile>>
-PDBFileBuilder::build(std::unique_ptr<msf::StreamInterface> PdbFileBuffer) {
+PDBFileBuilder::build(std::unique_ptr<msf::WritableStream> PdbFileBuffer) {
auto ExpectedLayout = finalizeMsfLayout();
if (!ExpectedLayout)
return ExpectedLayout.takeError();
auto File = llvm::make_unique<PDBFile>(std::move(PdbFileBuffer), Allocator);
- File->MsfLayout = *ExpectedLayout;
+ File->ContainerLayout = *ExpectedLayout;
if (Info) {
- auto ExpectedInfo = Info->build(*File);
+ auto ExpectedInfo = Info->build(*File, *PdbFileBuffer);
if (!ExpectedInfo)
return ExpectedInfo.takeError();
File->Info = std::move(*ExpectedInfo);
}
if (Dbi) {
- auto ExpectedDbi = Dbi->build(*File);
+ auto ExpectedDbi = Dbi->build(*File, *PdbFileBuffer);
if (!ExpectedDbi)
return ExpectedDbi.takeError();
File->Dbi = std::move(*ExpectedDbi);
@@ -103,3 +103,45 @@ PDBFileBuilder::build(std::unique_ptr<msf::StreamInterface> PdbFileBuffer) {
return std::move(File);
}
+
+Error PDBFileBuilder::commit(const msf::WritableStream &Buffer) {
+ StreamWriter Writer(Buffer);
+ auto ExpectedLayout = finalizeMsfLayout();
+ if (!ExpectedLayout)
+ return ExpectedLayout.takeError();
+ auto &Layout = *ExpectedLayout;
+
+ if (auto EC = Writer.writeObject(*Layout.SB))
+ return EC;
+ uint32_t BlockMapOffset =
+ msf::blockToOffset(Layout.SB->BlockMapAddr, Layout.SB->BlockSize);
+ Writer.setOffset(BlockMapOffset);
+ if (auto EC = Writer.writeArray(Layout.DirectoryBlocks))
+ return EC;
+
+ auto DirStream =
+ WritableMappedBlockStream::createDirectoryStream(Layout, Buffer);
+ StreamWriter DW(*DirStream);
+ if (auto EC = DW.writeInteger(Layout.StreamSizes.size()))
+ return EC;
+
+ if (auto EC = DW.writeArray(Layout.StreamSizes))
+ return EC;
+
+ for (const auto &Blocks : Layout.StreamMap) {
+ if (auto EC = DW.writeArray(Blocks))
+ return EC;
+ }
+
+ if (Info) {
+ if (auto EC = Info->commit(Layout, Buffer))
+ return EC;
+ }
+
+ if (Dbi) {
+ if (auto EC = Dbi->commit(Layout, Buffer))
+ return EC;
+ }
+
+ return Buffer.commit();
+} \ No newline at end of file
diff --git a/llvm/lib/DebugInfo/PDB/Raw/RawSession.cpp b/llvm/lib/DebugInfo/PDB/Raw/RawSession.cpp
index e6d915fcaee..a83689f5741 100644
--- a/llvm/lib/DebugInfo/PDB/Raw/RawSession.cpp
+++ b/llvm/lib/DebugInfo/PDB/Raw/RawSession.cpp
@@ -26,21 +26,6 @@ using namespace llvm;
using namespace llvm::msf;
using namespace llvm::pdb;
-namespace {
-// We need a class which behaves like an immutable ByteStream, but whose data
-// is backed by an llvm::MemoryBuffer. It also needs to own the underlying
-// MemoryBuffer, so this simple adapter is a good way to achieve that.
-class InputByteStream : public ByteStream<false> {
-public:
- explicit InputByteStream(std::unique_ptr<MemoryBuffer> Buffer)
- : ByteStream(ArrayRef<uint8_t>(Buffer->getBuffer().bytes_begin(),
- Buffer->getBuffer().bytes_end())),
- MemBuffer(std::move(Buffer)) {}
-
- std::unique_ptr<MemoryBuffer> MemBuffer;
-};
-}
-
RawSession::RawSession(std::unique_ptr<PDBFile> PdbFile,
std::unique_ptr<BumpPtrAllocator> Allocator)
: Pdb(std::move(PdbFile)), Allocator(std::move(Allocator)) {}
@@ -57,7 +42,7 @@ Error RawSession::createFromPdb(StringRef Path,
return llvm::make_error<GenericError>(generic_error_code::invalid_path);
std::unique_ptr<MemoryBuffer> Buffer = std::move(*ErrorOrBuffer);
- auto Stream = llvm::make_unique<InputByteStream>(std::move(Buffer));
+ auto Stream = llvm::make_unique<MemoryBufferByteStream>(std::move(Buffer));
auto Allocator = llvm::make_unique<BumpPtrAllocator>();
auto File = llvm::make_unique<PDBFile>(std::move(Stream), *Allocator);
diff --git a/llvm/lib/DebugInfo/PDB/Raw/TpiStream.cpp b/llvm/lib/DebugInfo/PDB/Raw/TpiStream.cpp
index 6756580547a..a39a040705b 100644
--- a/llvm/lib/DebugInfo/PDB/Raw/TpiStream.cpp
+++ b/llvm/lib/DebugInfo/PDB/Raw/TpiStream.cpp
@@ -188,12 +188,9 @@ Error TpiStream::reload() {
if (Header->HashStreamIndex >= Pdb.getNumStreams())
return make_error<RawError>(raw_error_code::corrupt_file,
"Invalid TPI hash stream index.");
-
- auto HS =
- MappedBlockStream::createIndexedStream(Header->HashStreamIndex, Pdb);
- if (!HS)
- return HS.takeError();
- StreamReader HSR(**HS);
+ auto HS = MappedBlockStream::createIndexedStream(
+ Pdb.getMsfLayout(), Pdb.getMsfBuffer(), Header->HashStreamIndex);
+ StreamReader HSR(*HS);
uint32_t NumHashValues = Header->HashValueBuffer.Length / sizeof(ulittle32_t);
if (NumHashValues != NumTypeRecords())
@@ -216,7 +213,7 @@ Error TpiStream::reload() {
if (auto EC = HSR.readArray(HashAdjustments, NumHashAdjustments))
return EC;
- HashStream = std::move(*HS);
+ HashStream = std::move(HS);
// TPI hash table is a parallel array for the type records.
// Verify that the hash values match with type records.
OpenPOWER on IntegriCloud