diff options
Diffstat (limited to 'llvm/lib/DebugInfo/PDB/Raw/PDBFileBuilder.cpp')
-rw-r--r-- | llvm/lib/DebugInfo/PDB/Raw/PDBFileBuilder.cpp | 52 |
1 files changed, 47 insertions, 5 deletions
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 |