35 InjectedSourceTable(2) {}
40 auto ExpectedMsf = MSFBuilder::create(Allocator,
BlockSize);
42 return ExpectedMsf.takeError();
43 Msf = std::make_unique<MSFBuilder>(
std::move(*ExpectedMsf));
51 Info = std::make_unique<InfoStreamBuilder>(*Msf, NamedStreams);
57 Dbi = std::make_unique<DbiStreamBuilder>(*Msf);
63 Tpi = std::make_unique<TpiStreamBuilder>(*Msf,
StreamTPI);
69 Ipi = std::make_unique<TpiStreamBuilder>(*Msf,
StreamIPI);
79 Gsi = std::make_unique<GSIStreamBuilder>(*Msf);
85 auto ExpectedStream = Msf->addStream(
Size);
87 NamedStreams.
set(
Name, *ExpectedStream);
88 return ExpectedStream;
96 NamedStreamData[*ExpectedIndex] = std::string(
Data);
101 std::unique_ptr<MemoryBuffer> Buffer) {
111 InjectedSourceDescriptor Desc;
114 Desc.VNameIndex = VNI;
115 Desc.StreamName =
"/src/files/";
117 Desc.StreamName += VName;
119 InjectedSources.push_back(
std::move(Desc));
122 Error PDBFileBuilder::finalizeMsfLayout() {
124 if (Ipi && Ipi->getRecordCount() > 0) {
140 if (
auto EC = Gsi->finalizeMsfLayout())
143 Dbi->setPublicsStreamIndex(Gsi->getPublicsStreamIndex());
144 Dbi->setGlobalsStreamIndex(Gsi->getGlobalsStreamIndex());
145 Dbi->setSymbolRecordStreamIndex(Gsi->getRecordStreamIndex());
149 if (
auto EC = Tpi->finalizeMsfLayout())
153 if (
auto EC = Dbi->finalizeMsfLayout())
156 SN = allocateNamedStream(
"/names", StringsLen);
161 if (
auto EC = Ipi->finalizeMsfLayout())
168 if (
auto EC = Info->finalizeMsfLayout())
172 if (!InjectedSources.empty()) {
173 for (
const auto &IS : InjectedSources) {
175 CRC.update(arrayRefFromStringRef(IS.Content->getBuffer()));
180 Entry.
FileSize = IS.Content->getBufferSize();
181 Entry.
FileNI = IS.NameIndex;
187 Entry.
CRC = CRC.getCRC();
190 InjectedSourceHashTraits);
196 SN = allocateNamedStream(
"/src/headerblock", SrcHeaderBlockSize);
199 for (
const auto &IS : InjectedSources) {
200 SN = allocateNamedStream(IS.StreamName, IS.Content->getBufferSize());
209 if (
auto EC = Info->finalizeMsfLayout())
218 if (!NamedStreams.
get(
Name, SN))
228 auto Stream = WritableMappedBlockStream::createIndexedStream(
229 Layout, MsfBuffer, SN, Allocator);
233 ::memset(&Header, 0,
sizeof(Header));
235 Header.
Size = Writer.bytesRemaining();
237 cantFail(Writer.writeObject(Header));
240 assert(Writer.bytesRemaining() == 0);
245 if (InjectedSourceTable.
empty())
248 commitSrcHeaderBlock(MsfBuffer, Layout);
250 for (
const auto &IS : InjectedSources) {
253 auto SourceStream = WritableMappedBlockStream::createIndexedStream(
254 Layout, MsfBuffer, SN, Allocator);
256 assert(SourceWriter.bytesRemaining() == IS.Content->getBufferSize());
258 arrayRefFromStringRef(IS.Content->getBuffer())));
264 if (
auto EC = finalizeMsfLayout())
269 Msf->commit(Filename, Layout);
270 if (!ExpectedMsfBuffer)
276 return ExpectedSN.takeError();
278 auto NS = WritableMappedBlockStream::createIndexedStream(
279 Layout, Buffer, *ExpectedSN, Allocator);
281 if (
auto EC = Strings.
commit(NSWriter))
284 for (
const auto &NSE : NamedStreamData) {
285 if (NSE.second.empty())
288 auto NS = WritableMappedBlockStream::createIndexedStream(
289 Layout, Buffer, NSE.first, Allocator);
291 if (
auto EC = NSW.
writeBytes(arrayRefFromStringRef(NSE.second)))
296 if (
auto EC = Info->commit(Layout, Buffer))
301 if (
auto EC = Dbi->commit(Layout, Buffer))
306 if (
auto EC = Tpi->commit(Layout, Buffer))
311 if (
auto EC = Ipi->commit(Layout, Buffer))
316 if (
auto EC = Gsi->commit(Layout, Buffer))
321 assert(!InfoStreamBlocks.empty());
322 uint64_t InfoStreamFileOffset =
327 commitInjectedSources(Buffer, Layout);
331 if (Info->hashPDBContentsToGUID()) {
338 memcpy(
H->Guid.Guid, &Digest, 8);
340 memcpy(
H->Guid.Guid + 8,
"LLD PDB.", 8);
343 H->Signature =
static_cast<uint32_t>(Digest);
346 memcpy(Guid,
H->Guid.Guid, 16);
348 H->Age = Info->getAge();
349 H->Guid = Info->getGuid();
351 H->Signature = Sig.
hasValue() ? *Sig : time(
nullptr);