43 : Allocator(Allocator), InjectedSourceTable(2) {}
50 return ExpectedMsf.takeError();
51 Msf = std::make_unique<MSFBuilder>(std::move(*ExpectedMsf));
59 Info = std::make_unique<InfoStreamBuilder>(*Msf, NamedStreams);
65 Dbi = std::make_unique<DbiStreamBuilder>(*Msf);
71 Tpi = std::make_unique<TpiStreamBuilder>(*Msf,
StreamTPI);
77 Ipi = std::make_unique<TpiStreamBuilder>(*Msf,
StreamIPI);
83 Strings = std::make_unique<PDBStringTableBuilder>();
91 Gsi = std::make_unique<GSIStreamBuilder>(*Msf);
97 Dxc = std::make_unique<SmallVector<char>>();
103 auto ExpectedStream = Msf->addStream(
Size);
105 NamedStreams.
set(Name, *ExpectedStream);
106 return ExpectedStream;
113 assert(NamedStreamData.count(*ExpectedIndex) == 0);
114 NamedStreamData[*ExpectedIndex] = std::string(
Data);
119 std::unique_ptr<MemoryBuffer> Buffer) {
129 InjectedSourceDescriptor
Desc;
130 Desc.Content = std::move(Buffer);
132 Desc.VNameIndex = VNI;
133 Desc.StreamName =
"/src/files/";
135 Desc.StreamName += VName;
140Error PDBFileBuilder::finalizeMsfLayout() {
143 if (Ipi && Ipi->getRecordCount() > 0) {
162 if (
auto EC = Gsi->finalizeMsfLayout())
165 Dbi->setPublicsStreamIndex(Gsi->getPublicsStreamIndex());
166 Dbi->setGlobalsStreamIndex(Gsi->getGlobalsStreamIndex());
167 Dbi->setSymbolRecordStreamIndex(Gsi->getRecordStreamIndex());
171 if (
auto EC = Tpi->finalizeMsfLayout())
175 if (
auto EC = Dbi->finalizeMsfLayout())
179 uint32_t StringsLen = Strings->calculateSerializedSize();
180 Expected<uint32_t> SN = allocateNamedStream(
"/names", StringsLen);
185 if (
auto EC = Ipi->finalizeMsfLayout())
192 if (
auto EC = Info->finalizeMsfLayout())
196 if (!InjectedSources.empty()) {
197 for (
const auto &IS : InjectedSources) {
201 SrcHeaderBlockEntry
Entry;
202 ::memset(&Entry, 0,
sizeof(SrcHeaderBlockEntry));
203 Entry.Size =
sizeof(SrcHeaderBlockEntry);
204 Entry.FileSize = IS.Content->getBufferSize();
205 Entry.FileNI = IS.NameIndex;
206 Entry.VFileNI = IS.VNameIndex;
211 Entry.CRC = CRC.getCRC();
213 InjectedSourceTable.set_as(VName, std::move(Entry),
214 InjectedSourceHashTraits);
217 uint32_t SrcHeaderBlockSize =
218 sizeof(SrcHeaderBlockHeader) +
219 InjectedSourceTable.calculateSerializedLength();
220 Expected<uint32_t> SN =
221 allocateNamedStream(
"/src/headerblock", SrcHeaderBlockSize);
224 for (
const auto &IS : InjectedSources) {
225 SN = allocateNamedStream(IS.StreamName, IS.Content->getBufferSize());
234 if (
auto EC = Info->finalizeMsfLayout())
243 if (!NamedStreams.get(Name, SN))
254 Layout, MsfBuffer, SN, Allocator);
258 ::memset(&Header, 0,
sizeof(Header));
260 Header.Size = Writer.bytesRemaining();
262 cantFail(Writer.writeObject(Header));
265 assert(Writer.bytesRemaining() == 0);
270 if (InjectedSourceTable.
empty())
274 commitSrcHeaderBlock(MsfBuffer, Layout);
280 Layout, MsfBuffer, SN, Allocator);
282 assert(SourceWriter.bytesRemaining() == IS.Content->getBufferSize());
290 if (
auto EC = finalizeMsfLayout())
296 if (!ExpectedMsfBuffer)
303 return ExpectedSN.takeError();
306 Layout, Buffer, *ExpectedSN, Allocator);
308 if (
auto EC = Strings->commit(NSWriter))
313 for (
const auto &NSE : NamedStreamData) {
314 if (NSE.second.empty())
318 Layout, Buffer, NSE.first, Allocator);
326 if (
auto EC = Info->commit(Layout, Buffer))
331 if (
auto EC = Dbi->commit(Layout, Buffer))
336 if (
auto EC = Tpi->commit(Layout, Buffer))
341 if (
auto EC = Ipi->commit(Layout, Buffer))
346 if (
auto EC = Gsi->commit(Layout, Buffer))
362 assert(!InfoStreamBlocks.empty());
368 commitInjectedSources(Buffer, Layout);
372 if (Info->hashPDBContentsToGUID()) {
381 memcpy(
H->Guid.Guid, &Digest, 8);
383 memcpy(
H->Guid.Guid + 8,
"LLD PDB.", 8);
386 H->Signature =
static_cast<uint32_t>(Digest);
389 memcpy(
Guid,
H->Guid.Guid, 16);
391 H->Age = Info->getAge();
392 H->Guid = Info->getGuid();
393 std::optional<uint32_t> Sig = Info->getSignature();
394 H->Signature = Sig ? *Sig : time(
nullptr);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static constexpr StringLiteral Filename
This file defines the SmallString class.
static const int BlockSize
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Provides write only access to a subclass of WritableBinaryStream.
LLVM_ABI Error writeBytes(ArrayRef< uint8_t > Buffer)
Write the bytes specified in Buffer to the underlying stream.
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
Tagged union holding either a T or a Error.
Error takeError()
Take ownership of the stored error.
An implementation of WritableBinaryStream backed by an llvm FileOutputBuffer.
Error commit() override
For buffered streams, commits changes to the backing store.
uint8_t * getBufferEnd() const
Returns a pointer to the end of the buffer.
uint8_t * getBufferStart() const
Returns a pointer to the start of the buffer.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
void push_back(const T &Elt)
Represent a constant reference to a string, i.e.
The TimeTraceScope is a helper class to call the begin and end functions of the time trace profiler.
A BinaryStream which can be read from as well as written to.
static LLVM_ABI Expected< MSFBuilder > create(BumpPtrAllocator &Allocator, uint32_t BlockSize, uint32_t MinBlockCount=0, bool CanGrow=true)
Create a new MSFBuilder.
static std::unique_ptr< WritableMappedBlockStream > createIndexedStream(const MSFLayout &Layout, WritableBinaryStreamRef MsfData, uint32_t StreamIndex, BumpPtrAllocator &Allocator)
Error commit(BinaryStreamWriter &Writer) const
LLVM_ABI void set(StringRef Stream, uint32_t StreamNo)
LLVM_ABI TpiStreamBuilder & getTpiBuilder()
LLVM_ABI msf::MSFBuilder & getMsfBuilder()
LLVM_ABI PDBStringTableBuilder & getStringTableBuilder()
LLVM_ABI Error addNamedStream(StringRef Name, StringRef Data)
LLVM_ABI DbiStreamBuilder & getDbiBuilder()
LLVM_ABI TpiStreamBuilder & getIpiBuilder()
LLVM_ABI GSIStreamBuilder & getGsiBuilder()
LLVM_ABI InfoStreamBuilder & getInfoBuilder()
LLVM_ABI ~PDBFileBuilder()
LLVM_ABI std::unique_ptr< SmallVector< char > > & getDXContainerData()
LLVM_ABI Error initialize(uint32_t BlockSize)
LLVM_ABI PDBFileBuilder(BumpPtrAllocator &Allocator)
LLVM_ABI Error commit(StringRef Filename, codeview::GUID *Guid)
LLVM_ABI void addInjectedSource(StringRef Name, std::unique_ptr< MemoryBuffer > Buffer)
LLVM_ABI Expected< uint32_t > getNamedStreamIndex(StringRef Name) const
LLVM_ABI uint32_t insert(StringRef S)
LLVM_ABI StringRef getStringForId(uint32_t Id) const
uint64_t blockToOffset(uint64_t BlockNumber, uint64_t BlockSize)
This is an optimization pass for GlobalISel generic memory operations.
ArrayRef< CharT > arrayRefFromStringRef(StringRef Input)
Construct a string ref from an array ref of unsigned chars.
uint64_t xxh3_64bits(ArrayRef< uint8_t > data)
Inline ArrayRef overloads of the xxhash entry points declared out-of-line in llvm/Support/xxhash....
Error make_error(ArgTs &&... Args)
Make a Error instance representing failure using the given error info type.
void cantFail(Error Err, const char *Msg=nullptr)
Report a fatal error if Err is a failure value.
BumpPtrAllocatorImpl<> BumpPtrAllocator
The standard BumpPtrAllocator which just uses the default template parameters.
This represents the 'GUID' type from windows.h.
std::vector< ArrayRef< support::ulittle32_t > > StreamMap
support::ulittle32_t BlockSize