29 : Msf(Msf),
Allocator(Msf.getAllocator()), Age(1), BuildNumber(0),
30 PdbDllVersion(0), PdbDllRbld(0), Flags(0), MachineType(
PDB_Machine::
x86),
67 GlobalsStreamIndex =
Index;
71 SymRecordStreamIndex =
Index;
75 PublicsStreamIndex =
Index;
79 if (!NewFpoData.hasValue())
80 NewFpoData.emplace(
false);
82 NewFpoData->addFrameData(FD);
86 OldFpoData.push_back(FD);
92 "NewFPO data should be written via addFrameData()!");
94 DbgStreams[(int)Type].emplace();
95 DbgStreams[(int)Type]->
Size = Data.
size();
103 return ECNamesBuilder.
insert(Name);
109 calculateModiSubstreamSize() + calculateSectionContribsStreamSize() +
110 calculateSectionMapStreamSize() + calculateDbgStreamsSize() +
118 llvm::make_unique<DbiModuleDescriptorBuilder>(ModuleName, Index, Msf));
119 return *ModiList.back();
125 SourceFileNames.
insert(std::make_pair(File, Index));
126 Module.addSourceFile(File);
131 auto NameIter = SourceFileNames.
find(File);
132 if (NameIter == SourceFileNames.
end())
134 "The specified source file was not found");
135 return NameIter->getValue();
138 uint32_t DbiStreamBuilder::calculateModiSubstreamSize()
const {
140 for (
const auto &M : ModiList)
141 Size += M->calculateSerializedLength();
145 uint32_t DbiStreamBuilder::calculateSectionContribsStreamSize()
const {
146 if (SectionContribs.empty())
149 sizeof(SectionContribs[0]) * SectionContribs.size();
152 uint32_t DbiStreamBuilder::calculateSectionMapStreamSize()
const {
153 if (SectionMap.empty())
158 uint32_t DbiStreamBuilder::calculateNamesOffset()
const {
165 for (
const auto &M : ModiList)
166 NumFileInfos += M->source_files().size();
171 uint32_t DbiStreamBuilder::calculateFileInfoSubstreamSize()
const {
173 Size += calculateNamesBufferSize();
177 uint32_t DbiStreamBuilder::calculateNamesBufferSize()
const {
179 for (
const auto &
F : SourceFileNames) {
180 Size +=
F.getKeyLength() + 1;
185 uint32_t DbiStreamBuilder::calculateDbgStreamsSize()
const {
186 return DbgStreams.size() *
sizeof(uint16_t);
189 Error DbiStreamBuilder::generateFileInfoSubstream() {
192 uint32_t NamesOffset = calculateNamesOffset();
201 uint16_t ModiCount = std::min<uint32_t>(UINT16_MAX, ModiList.size());
202 uint16_t FileCount = std::min<uint32_t>(UINT16_MAX, SourceFileNames.
size());
207 for (uint16_t
I = 0;
I < ModiCount; ++
I) {
211 for (
const auto &
MI : ModiList) {
212 FileCount =
static_cast<uint16_t
>(
MI->source_files().size());
223 for (
auto &
Name : SourceFileNames) {
229 for (
const auto &
MI : ModiList) {
231 auto Result = SourceFileNames.find(
Name);
232 if (Result == SourceFileNames.end())
234 "The source file was not found.");
245 "The names buffer contained unexpected data.");
248 return make_error<RawError>(
250 "The metadata buffer contained unexpected data.");
255 Error DbiStreamBuilder::finalize() {
259 for (
auto &
MI : ModiList)
262 if (
auto EC = generateFileInfoSubstream())
274 H->
MachineType =
static_cast<uint16_t
>(MachineType);
293 if (NewFpoData.hasValue()) {
296 NewFpoData->calculateSerializedSize();
299 return NewFpoData->commit(Writer);
303 if (!OldFpoData.empty()) {
313 for (
auto &S : DbgStreams) {
316 auto ExpectedIndex = Msf.
addStream(S->Size);
318 return ExpectedIndex.takeError();
319 S->StreamNumber = *ExpectedIndex;
322 for (
auto &
MI : ModiList) {
323 if (
auto EC =
MI->finalizeMsfLayout())
341 if (Flags & COFF::IMAGE_SCN_MEM_EXECUTE)
359 std::vector<SecMapEntry>
Ret;
364 auto &Entry = Ret.back();
365 memset(&Entry, 0,
sizeof(Entry));
367 Entry.Frame = Idx + 1;
370 Entry.SecName = UINT16_MAX;
371 Entry.ClassName = UINT16_MAX;
376 for (
auto &Hdr : SecHdrs) {
379 Entry.SecByteLength = Hdr.VirtualSize;
387 Entry.SecByteLength = UINT32_MAX;
394 if (
auto EC = finalize())
397 auto DbiS = WritableMappedBlockStream::createIndexedStream(
398 Layout, MsfBuffer,
StreamDBI, Allocator);
404 for (
auto &M : ModiList) {
405 if (
auto EC = M->commit(Writer, Layout, MsfBuffer))
409 if (!SectionContribs.empty()) {
416 if (!SectionMap.empty()) {
428 if (
auto EC = ECNamesBuilder.
commit(Writer))
431 for (
auto &Stream : DbgStreams) {
433 if (Stream.hasValue())
434 StreamNumber = Stream->StreamNumber;
439 for (
auto &Stream : DbgStreams) {
440 if (!Stream.hasValue())
444 auto WritableStream = WritableMappedBlockStream::createIndexedStream(
445 Layout, MsfBuffer, Stream->StreamNumber, Allocator);
448 if (
auto EC = Stream->WriteFn(DbgStreamWriter))
454 "Unexpected bytes found in DBI Stream");
Error writeObject(const T &Obj)
Writes the object Obj to the underlying stream, as if by using memcpy.
uint32_t addECName(StringRef Name)
Error finalizeMsfLayout()
An implementation of BinaryStream which holds its entire data set in a single contiguous buffer...
This class represents lattice values for constants.
A Module instance is used to store all the information related to an LLVM module. ...
Data in the SUBSEC_FRAMEDATA subection.
void setSectionMap(ArrayRef< SecMapEntry > SecMap)
static const uint16_t BuildMinorMask
uint16_t MinorVersion : 8; uint16_t MajorVersion : 7; uint16_t NewVersionFormat : 1; ...
void setMachineType(PDB_Machine M)
static std::vector< SecMapEntry > createSectionMap(ArrayRef< llvm::object::coff_section > SecHdrs)
iterator find(StringRef Key)
uint64_t alignTo(uint64_t Value, uint64_t Align, uint64_t Skew=0)
Returns the next integer (mod 2**64) that is greater than or equal to Value and is a multiple of Alig...
detail::packed_endian_specific_integral< uint16_t, little, unaligned > ulittle16_t
void setGlobalsStreamIndex(uint32_t Index)
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.
static const uint16_t NewVersionFormatMask
Tagged union holding either a T or a Error.
void setSymbolRecordStreamIndex(uint32_t Index)
Error addDbgStream(pdb::DbgHeaderType Type, ArrayRef< uint8_t > Data)
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Error writeArray(ArrayRef< T > Array)
Writes an array of objects of type T to the underlying stream, as if by using memcpy.
uint32_t calculateSerializedSize() const
const uint16_t kInvalidStreamIndex
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
* if(!EatIfPresent(lltok::kw_thread_local)) return false
ParseOptionalThreadLocal := /*empty.
static const uint16_t BuildMajorShift
The instances of the Type class are immutable: once they are created, they are never changed...
detail::packed_endian_specific_integral< uint32_t, little, unaligned > ulittle32_t
void setBuildNumber(uint16_t B)
uint32_t getOffset() const
size_t size() const
size - Get the array size.
uint32_t insert(StringRef S)
Expected< uint32_t > getSourceFileNameIndex(StringRef FileName)
LLVM_ATTRIBUTE_RETURNS_NONNULL LLVM_ATTRIBUTE_RETURNS_NOALIAS void * Allocate(size_t Size, size_t Alignment)
Allocate space at the specified alignment.
Error writeStreamRef(BinaryStreamRef Ref)
Efficiently reads all data from Ref, and writes it to this stream.
uint32_t calculateSerializedLength() const
RefType drop_front(uint32_t N) const
Return a new BinaryStreamRef with the first N elements removed.
Provides write only access to a subclass of WritableBinaryStream.
void setFlags(uint16_t F)
void setVersionHeader(PdbRaw_DbiVer V)
void setPdbDllRbld(uint16_t R)
Error writeInteger(T Value)
Write the integer Value to the underlying stream in the specified endianness.
Error commit(const msf::MSFLayout &Layout, WritableBinaryStreamRef MsfBuffer)
void setPdbDllVersion(uint16_t V)
Error setStreamSize(uint32_t Idx, uint32_t Size)
Update the size of an existing stream.
uint32_t bytesRemaining() const
Error writeCString(StringRef Str)
Write the string Str to the underlying stream followed by a null terminator.
static ErrorSuccess success()
Create a success value.
void addNewFpoData(const codeview::FrameData &FD)
Expected< uint32_t > addStream(uint32_t Size, ArrayRef< uint32_t > Blocks)
Add a stream to the MSF file with the given size, occupying the given list of blocks.
bool insert(MapEntryTy *KeyValue)
insert - Insert the specified key/value pair into the map.
Expected< DbiModuleDescriptorBuilder & > addModuleInfo(StringRef ModuleName)
void addOldFpoData(const object::FpoData &Fpo)
Error writeEnum(T Num)
Similar to writeInteger.
void setPublicsStreamIndex(uint32_t Index)
static uint16_t toSecMapFlags(uint32_t Flags)
static const uint16_t BuildMajorMask
Error padToAlignment(uint32_t Align)
static const uint16_t BuildMinorShift
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
RefType keep_front(uint32_t N) const
Return a new BinaryStreamRef with only the first N elements remaining.
Lightweight error class with error context and mandatory checking.
StringRef - Represent a constant reference to a string, i.e.
Error addModuleSourceFile(DbiModuleDescriptorBuilder &Module, StringRef File)
uint32_t getLength() override
Return the number of bytes of data in this stream.