Index: include/llvm/DebugInfo/MSF/MSFCommon.h =================================================================== --- include/llvm/DebugInfo/MSF/MSFCommon.h +++ include/llvm/DebugInfo/MSF/MSFCommon.h @@ -50,8 +50,7 @@ }; struct MSFLayout { - MSFLayout() : SB(nullptr) {} - const SuperBlock *SB; + const SuperBlock *SB = nullptr; BitVector FreePageMap; ArrayRef DirectoryBlocks; ArrayRef StreamSizes; Index: include/llvm/DebugInfo/PDB/Raw/PDBFileBuilder.h =================================================================== --- include/llvm/DebugInfo/PDB/Raw/PDBFileBuilder.h +++ include/llvm/DebugInfo/PDB/Raw/PDBFileBuilder.h @@ -38,6 +38,7 @@ Error initialize(const msf::SuperBlock &Super); + msf::MSFLayout &getMsf(); msf::MSFBuilder &getMsfBuilder(); InfoStreamBuilder &getInfoBuilder(); DbiStreamBuilder &getDbiBuilder(); @@ -49,12 +50,13 @@ Error commit(const msf::WritableStream &Buffer); -private: - Expected finalizeMsfLayout() const; + Error finalizeMsfLayout(); +private: BumpPtrAllocator &Allocator; - std::unique_ptr Msf; + std::unique_ptr Msf; + std::unique_ptr MsfBuilder; std::unique_ptr Info; std::unique_ptr Dbi; std::unique_ptr Tpi; Index: lib/DebugInfo/PDB/Raw/PDBFileBuilder.cpp =================================================================== --- lib/DebugInfo/PDB/Raw/PDBFileBuilder.cpp +++ lib/DebugInfo/PDB/Raw/PDBFileBuilder.cpp @@ -32,6 +32,11 @@ : Allocator(Allocator) {} Error PDBFileBuilder::initialize(const msf::SuperBlock &Super) { + auto ExpectedMsfBuilder = + MSFBuilder::create(Allocator, Super.BlockSize); + if (!ExpectedMsfBuilder) + return ExpectedMsfBuilder.takeError(); + auto ExpectedMsf = MSFBuilder::create(Allocator, Super.BlockSize, Super.NumBlocks); if (!ExpectedMsf) @@ -43,64 +48,70 @@ Msf = llvm::make_unique(std::move(MsfResult)); Msf->setFreePageMap(Super.FreeBlockMapBlock); Msf->setUnknown1(Super.Unknown1); - return Error::success(); } -MSFBuilder &PDBFileBuilder::getMsfBuilder() { return *Msf; } +MSFLayout &PDBFileBuilder::getMsf() { return *Msf; } + +MSFBuilder &PDBFileBuilder::getMsfBuilder() { return *MsfBuilder; } InfoStreamBuilder &PDBFileBuilder::getInfoBuilder() { if (!Info) - Info = llvm::make_unique(*Msf); + Info = llvm::make_unique(*MsfBuilder); return *Info; } DbiStreamBuilder &PDBFileBuilder::getDbiBuilder() { if (!Dbi) - Dbi = llvm::make_unique(*Msf); + Dbi = llvm::make_unique(*MsfBuilder); return *Dbi; } TpiStreamBuilder &PDBFileBuilder::getTpiBuilder() { if (!Tpi) - Tpi = llvm::make_unique(*Msf, StreamTPI); + Tpi = llvm::make_unique(*MsfBuilder, StreamTPI); return *Tpi; } TpiStreamBuilder &PDBFileBuilder::getIpiBuilder() { if (!Ipi) - Ipi = llvm::make_unique(*Msf, StreamIPI); + Ipi = llvm::make_unique(*MsfBuilder, StreamIPI); return *Ipi; } -Expected PDBFileBuilder::finalizeMsfLayout() const { +Error PDBFileBuilder::finalizeMsfLayout() { + if (Msf) + return Error::success(); if (Info) { if (auto EC = Info->finalizeMsfLayout()) - return std::move(EC); + return EC; } if (Dbi) { if (auto EC = Dbi->finalizeMsfLayout()) - return std::move(EC); + return EC; } if (Tpi) { if (auto EC = Tpi->finalizeMsfLayout()) - return std::move(EC); + return EC; } if (Ipi) { if (auto EC = Ipi->finalizeMsfLayout()) - return std::move(EC); + return EC; } - return Msf->build(); + Expected ExpectedMsf = MsfBuilder->build(); + if (!ExpectedMsf) + return ExpectedMsf.takeError(); + Msf.reset(new MSFLayout(*ExpectedMsf)); + return Error::success(); } Expected> PDBFileBuilder::build(std::unique_ptr PdbFileBuffer) { - auto ExpectedLayout = finalizeMsfLayout(); - if (!ExpectedLayout) - return ExpectedLayout.takeError(); + if (Error E = finalizeMsfLayout()) + return std::move(E); auto File = llvm::make_unique(std::move(PdbFileBuffer), Allocator); - File->ContainerLayout = *ExpectedLayout; + File->ContainerLayout = *Msf; if (Info) { auto ExpectedInfo = Info->build(*File, *PdbFileBuffer); @@ -140,10 +151,9 @@ Error PDBFileBuilder::commit(const msf::WritableStream &Buffer) { StreamWriter Writer(Buffer); - auto ExpectedLayout = finalizeMsfLayout(); - if (!ExpectedLayout) - return ExpectedLayout.takeError(); - auto &Layout = *ExpectedLayout; + if (Error E = finalizeMsfLayout()) + return E; + msf::MSFLayout &Layout = *Msf; if (auto EC = Writer.writeObject(*Layout.SB)) return EC; @@ -189,4 +199,4 @@ } return Buffer.commit(); -} \ No newline at end of file +}