36 : Allocator(Allocator), InjectedSourceHashTraits(Strings),
37 InjectedSourceTable(2) {}
42 auto ExpectedMsf = MSFBuilder::create(Allocator, BlockSize);
44 return ExpectedMsf.takeError();
45 Msf = std::make_unique<MSFBuilder>(std::move(*ExpectedMsf));
53 Info = std::make_unique<InfoStreamBuilder>(*Msf, NamedStreams);
59 Dbi = std::make_unique<DbiStreamBuilder>(*Msf);
65 Tpi = std::make_unique<TpiStreamBuilder>(*Msf,
StreamTPI);
71 Ipi = std::make_unique<TpiStreamBuilder>(*Msf,
StreamIPI);
81 Gsi = std::make_unique<GSIStreamBuilder>(*Msf);
87 auto ExpectedStream = Msf->addStream(Size);
89 NamedStreams.
set(Name, *ExpectedStream);
90 return ExpectedStream;
98 NamedStreamData[*ExpectedIndex] =
Data;
103 std::unique_ptr<MemoryBuffer> Buffer) {
113 InjectedSourceDescriptor Desc;
114 Desc.Content = std::move(Buffer);
116 Desc.VNameIndex = VNI;
117 Desc.StreamName =
"/src/files/";
119 Desc.StreamName += VName;
121 InjectedSources.
push_back(std::move(Desc));
124 Error PDBFileBuilder::finalizeMsfLayout() {
126 if (Ipi && Ipi->getRecordCount() > 0) {
142 if (
auto EC = Gsi->finalizeMsfLayout())
145 Dbi->setPublicsStreamIndex(Gsi->getPublicsStreamIndex());
146 Dbi->setGlobalsStreamIndex(Gsi->getGlobalsStreamIndex());
147 Dbi->setSymbolRecordStreamIndex(Gsi->getRecordStreamIdx());
151 if (
auto EC = Tpi->finalizeMsfLayout())
155 if (
auto EC = Dbi->finalizeMsfLayout())
158 SN = allocateNamedStream(
"/names", StringsLen);
163 if (
auto EC = Ipi->finalizeMsfLayout())
170 if (
auto EC = Info->finalizeMsfLayout())
174 if (!InjectedSources.
empty()) {
175 for (
const auto &IS : InjectedSources) {
182 Entry.
FileSize = IS.Content->getBufferSize();
183 Entry.
FileNI = IS.NameIndex;
191 InjectedSourceTable.
set_as(VName, std::move(Entry),
192 InjectedSourceHashTraits);
198 SN = allocateNamedStream(
"/src/headerblock", SrcHeaderBlockSize);
201 for (
const auto &IS : InjectedSources) {
202 SN = allocateNamedStream(IS.StreamName, IS.Content->getBufferSize());
211 if (
auto EC = Info->finalizeMsfLayout())
220 if (!NamedStreams.
get(Name, SN))
230 auto Stream = WritableMappedBlockStream::createIndexedStream(
231 Layout, MsfBuffer, SN, Allocator);
235 ::memset(&Header, 0,
sizeof(Header));
247 if (InjectedSourceTable.
empty())
250 commitSrcHeaderBlock(MsfBuffer, Layout);
252 for (
const auto &IS : InjectedSources) {
255 auto SourceStream = WritableMappedBlockStream::createIndexedStream(
256 Layout, MsfBuffer, SN, Allocator);
266 if (
auto EC = finalizeMsfLayout())
271 Msf->commit(Filename, Layout);
272 if (!ExpectedMsfBuffer)
278 return ExpectedSN.takeError();
280 auto NS = WritableMappedBlockStream::createIndexedStream(
281 Layout, Buffer, *ExpectedSN, Allocator);
283 if (
auto EC = Strings.
commit(NSWriter))
286 for (
const auto &NSE : NamedStreamData) {
287 if (NSE.second.empty())
290 auto NS = WritableMappedBlockStream::createIndexedStream(
291 Layout, Buffer, NSE.first, Allocator);
298 if (
auto EC = Info->commit(Layout, Buffer))
303 if (
auto EC = Dbi->commit(Layout, Buffer))
308 if (
auto EC = Tpi->commit(Layout, Buffer))
313 if (
auto EC = Ipi->commit(Layout, Buffer))
318 if (
auto EC = Gsi->commit(Layout, Buffer))
323 assert(!InfoStreamBlocks.empty());
324 uint64_t InfoStreamFileOffset =
329 commitInjectedSources(Buffer, Layout);
333 if (Info->hashPDBContentsToGUID()) {
340 memcpy(H->Guid.Guid, &Digest, 8);
342 memcpy(H->Guid.Guid + 8,
"LLD PDB.", 8);
345 H->Signature =
static_cast<uint32_t>(Digest);
348 memcpy(Guid, H->
Guid.Guid, 16);
350 H->Age = Info->getAge();
351 H->Guid = Info->getGuid();
353 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.
bool set_as(const Key &K, ValueT V, TraitsT &Traits)
Set the entry using a key type that the specified Traits can convert from a real key to an internal k...
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
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)
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
Error addNamedStream(StringRef Name, StringRef Data)
This represents the 'GUID' type from windows.h.
Tagged union holding either a T or a Error.
LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
TpiStreamBuilder & getIpiBuilder()
uint32_t calculateSerializedLength() const
LLVM_NODISCARD size_t size() const
size - Get the string size.
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.
Error commit(BinaryStreamWriter &Writer) const
uint32_t bytesRemaining() const
static const int BlockSize
static ErrorSuccess success()
Create a success value.
GSIStreamBuilder & getGsiBuilder()
InfoStreamBuilder & getInfoBuilder()
void update(ArrayRef< uint8_t > Data)
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())
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.