37 : Allocator(Allocator), InjectedSourceHashTraits(Strings),
38 InjectedSourceTable(2, InjectedSourceHashTraits) {}
43 auto ExpectedMsf = MSFBuilder::create(Allocator, BlockSize);
45 return ExpectedMsf.takeError();
46 Msf = llvm::make_unique<MSFBuilder>(std::move(*ExpectedMsf));
54 Info = llvm::make_unique<InfoStreamBuilder>(*Msf, NamedStreams);
60 Dbi = llvm::make_unique<DbiStreamBuilder>(*Msf);
66 Tpi = llvm::make_unique<TpiStreamBuilder>(*Msf,
StreamTPI);
72 Ipi = llvm::make_unique<TpiStreamBuilder>(*Msf,
StreamIPI);
82 Gsi = llvm::make_unique<GSIStreamBuilder>(*Msf);
88 auto ExpectedStream = Msf->addStream(Size);
90 NamedStreams.
set(Name, *ExpectedStream);
91 return ExpectedStream;
99 NamedStreamData[*ExpectedIndex] =
Data;
104 std::unique_ptr<MemoryBuffer> Buffer) {
114 InjectedSourceDescriptor Desc;
115 Desc.Content = std::move(Buffer);
117 Desc.VNameIndex = VNI;
118 Desc.StreamName =
"/src/files/";
120 Desc.StreamName += VName;
122 InjectedSources.
push_back(std::move(Desc));
125 Error PDBFileBuilder::finalizeMsfLayout() {
127 if (Ipi && Ipi->getRecordCount() > 0) {
143 if (
auto EC = Gsi->finalizeMsfLayout())
146 Dbi->setPublicsStreamIndex(Gsi->getPublicsStreamIndex());
147 Dbi->setGlobalsStreamIndex(Gsi->getGlobalsStreamIndex());
148 Dbi->setSymbolRecordStreamIndex(Gsi->getRecordStreamIdx());
152 if (
auto EC = Tpi->finalizeMsfLayout())
156 if (
auto EC = Dbi->finalizeMsfLayout())
159 SN = allocateNamedStream(
"/names", StringsLen);
164 if (
auto EC = Ipi->finalizeMsfLayout())
171 if (
auto EC = Info->finalizeMsfLayout())
175 if (!InjectedSources.
empty()) {
176 for (
const auto &IS : InjectedSources) {
179 IS.Content->getBufferSize()));
184 Entry.
FileSize = IS.Content->getBufferSize();
185 Entry.
FileNI = IS.NameIndex;
193 InjectedSourceTable.set_as(VName, std::move(Entry));
198 InjectedSourceTable.calculateSerializedLength();
199 SN = allocateNamedStream(
"/src/headerblock", SrcHeaderBlockSize);
202 for (
const auto &IS : InjectedSources) {
203 SN = allocateNamedStream(IS.StreamName, IS.Content->getBufferSize());
212 if (
auto EC = Info->finalizeMsfLayout())
221 if (!NamedStreams.
get(Name, SN))
228 assert(!InjectedSourceTable.empty());
231 auto Stream = WritableMappedBlockStream::createIndexedStream(
232 Layout, MsfBuffer, SN, Allocator);
236 ::memset(&Header, 0,
sizeof(Header));
241 cantFail(InjectedSourceTable.commit(Writer));
248 if (InjectedSourceTable.empty())
251 commitSrcHeaderBlock(MsfBuffer, Layout);
253 for (
const auto &IS : InjectedSources) {
256 auto SourceStream = WritableMappedBlockStream::createIndexedStream(
257 Layout, MsfBuffer, SN, Allocator);
267 if (
auto EC = finalizeMsfLayout())
272 Msf->commit(Filename, Layout);
273 if (!ExpectedMsfBuffer)
279 return ExpectedSN.takeError();
281 auto NS = WritableMappedBlockStream::createIndexedStream(
282 Layout, Buffer, *ExpectedSN, Allocator);
284 if (
auto EC = Strings.
commit(NSWriter))
287 for (
const auto &NSE : NamedStreamData) {
288 if (NSE.second.empty())
291 auto NS = WritableMappedBlockStream::createIndexedStream(
292 Layout, Buffer, NSE.first, Allocator);
299 if (
auto EC = Info->commit(Layout, Buffer))
304 if (
auto EC = Dbi->commit(Layout, Buffer))
309 if (
auto EC = Tpi->commit(Layout, Buffer))
314 if (
auto EC = Ipi->commit(Layout, Buffer))
319 if (
auto EC = Gsi->commit(Layout, Buffer))
324 assert(!InfoStreamBlocks.empty());
325 uint64_t InfoStreamFileOffset =
330 commitInjectedSources(Buffer, Layout);
334 if (Info->hashPDBContentsToGUID()) {
341 memcpy(H->Guid.Guid, &Digest, 8);
343 memcpy(H->Guid.Guid + 8,
"LLD PDB.", 8);
346 H->Signature =
static_cast<uint32_t>(Digest);
351 H->Age = Info->getAge();
352 H->Guid = Info->getGuid();
354 H->Signature = Sig.
hasValue() ? *Sig : time(
nullptr);
Error writeObject(const T &Obj)
Writes the object Obj to the underlying stream, as if by using memcpy.
void cantFail(Error Err, const char *Msg=nullptr)
Report a fatal error if Err is a failure value.
Error writeBytes(ArrayRef< uint8_t > Buffer)
Write the bytes specified in Buffer to the underlying stream.
void native(const Twine &path, SmallVectorImpl< char > &result, Style style=Style::native)
Convert path to the native form.
StringRef getStringForId(uint32_t Id) const
This class represents lattice values for constants.
void push_back(const T &Elt)
uint8_t * getBufferEnd() const
Returns a pointer to the end of the buffer.
uint64_t blockToOffset(uint64_t BlockNumber, uint64_t BlockSize)
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
uint64_t xxHash64(llvm::StringRef Data)
PDBStringTableBuilder & getStringTableBuilder()
ArrayRef< uint8_t > arrayRefFromStringRef(StringRef Input)
Construct a string ref from an array ref of unsigned chars.
Error takeError()
Take ownership of the stored error.
void set(StringRef Stream, uint32_t StreamNo)
DbiStreamBuilder & getDbiBuilder()
Error commit(BinaryStreamWriter &Writer) const
amdgpu Simplify well known AMD library false Value Value const Twine & Name
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
Error addNamedStream(StringRef Name, StringRef Data)
This represents the 'GUID' type from windows.h.
Tagged union holding either a T or a Error.
TpiStreamBuilder & getIpiBuilder()
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
support::ulittle32_t BlockSize
uint32_t calculateSerializedSize() const
Error commit() override
For buffered streams, commits changes to the backing store.
Error commit(StringRef Filename, codeview::GUID *Guid)
Error initialize(uint32_t BlockSize)
Allocate memory in an ever growing pool, as if by bump-pointer.
uint32_t insert(StringRef S)
uint8_t * getBufferStart() const
Returns a pointer to the start of the buffer.
Provides write only access to a subclass of WritableBinaryStream.
uint32_t bytesRemaining() const
static const int BlockSize
static ErrorSuccess success()
Create a success value.
GSIStreamBuilder & getGsiBuilder()
InfoStreamBuilder & getInfoBuilder()
LLVM_NODISCARD bool empty() const
void addInjectedSource(StringRef Name, std::unique_ptr< MemoryBuffer > Buffer)
std::vector< ArrayRef< support::ulittle32_t > > StreamMap
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
bool get(StringRef Stream, uint32_t &StreamNo) const
LLVM_NODISCARD std::string lower() const
msf::MSFBuilder & getMsfBuilder()
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
void update(ArrayRef< char > Data)
Lightweight error class with error context and mandatory checking.
An implementation of WritableBinaryStream backed by an llvm FileOutputBuffer.
StringRef - Represent a constant reference to a string, i.e.
Expected< uint32_t > getNamedStreamIndex(StringRef Name) const
TpiStreamBuilder & getTpiBuilder()
A BinaryStream which can be read from as well as written to.