Index: include/llvm/DebugInfo/PDB/Raw/DbiStreamBuilder.h =================================================================== --- include/llvm/DebugInfo/PDB/Raw/DbiStreamBuilder.h +++ include/llvm/DebugInfo/PDB/Raw/DbiStreamBuilder.h @@ -44,6 +44,7 @@ void setPdbDllRbld(uint16_t R); void setFlags(uint16_t F); void setMachineType(PDB_Machine M); + void setDebugStreamIndex(DbgHeaderType Type, uint32_t Index); uint32_t calculateSerializedLength() const; Index: include/llvm/DebugInfo/PDB/Raw/PDBFileBuilder.h =================================================================== --- include/llvm/DebugInfo/PDB/Raw/PDBFileBuilder.h +++ include/llvm/DebugInfo/PDB/Raw/PDBFileBuilder.h @@ -44,6 +44,9 @@ TpiStreamBuilder &getTpiBuilder(); TpiStreamBuilder &getIpiBuilder(); + // Add given bytes as a new stream. Returns the stream index. + Expected addStream(ArrayRef Data); + Expected> build(std::unique_ptr PdbFileBuffer); @@ -59,6 +62,7 @@ std::unique_ptr Dbi; std::unique_ptr Tpi; std::unique_ptr Ipi; + std::vector, uint32_t>> Streams; }; } } Index: lib/DebugInfo/PDB/Raw/DbiStreamBuilder.cpp =================================================================== --- lib/DebugInfo/PDB/Raw/DbiStreamBuilder.cpp +++ lib/DebugInfo/PDB/Raw/DbiStreamBuilder.cpp @@ -44,6 +44,10 @@ void DbiStreamBuilder::setMachineType(PDB_Machine M) { MachineType = M; } +void DbiStreamBuilder::setDebugStreamIndex(DbgHeaderType Type, uint32_t Index) { + DbgStreams[(int)Type] = Index; +} + uint32_t DbiStreamBuilder::calculateSerializedLength() const { // For now we only support serializing the header. return sizeof(DbiStreamHeader) + calculateFileInfoSubstreamSize() + Index: lib/DebugInfo/PDB/Raw/PDBFileBuilder.cpp =================================================================== --- lib/DebugInfo/PDB/Raw/PDBFileBuilder.cpp +++ lib/DebugInfo/PDB/Raw/PDBFileBuilder.cpp @@ -66,6 +66,16 @@ return *Ipi; } +Expected PDBFileBuilder::addStream(ArrayRef Data) { + auto ExpectedIndex = Msf->addStream(Data.size()); + if (!ExpectedIndex) + return ExpectedIndex.takeError(); + uint32_t Index = std::move(*ExpectedIndex); + + Streams.emplace_back(Data, Index); + return *ExpectedIndex; +} + Expected PDBFileBuilder::finalizeMsfLayout() const { if (Info) { if (auto EC = Info->finalizeMsfLayout()) @@ -189,5 +199,14 @@ return EC; } + for (auto &Pair : Streams) { + ArrayRef Data = Pair.first; + uint32_t Idx = Pair.second; + auto Stream = WritableMappedBlockStream::createIndexedStream(Layout, Buffer, Idx); + StreamWriter Writer(*Stream); + if (auto EC = Writer.writeArray(Data)) + return EC; + } + return Buffer.commit(); }