28 : Msf(Msf),
Allocator(Msf.getAllocator()), Age(1), BuildNumber(0),
62 GlobalsStreamIndex =
Index;
66 SymRecordStreamIndex =
Index;
70 PublicsStreamIndex =
Index;
75 NewFpoData.emplace(
false);
77 NewFpoData->addFrameData(FD);
81 OldFpoData.push_back(FD);
87 "NewFPO data should be written via addFrameData()!");
89 DbgStreams[(int)
Type] = DebugStream{};
104 calculateModiSubstreamSize() + calculateSectionContribsStreamSize() +
105 calculateSectionMapStreamSize() + calculateDbgStreamsSize() +
114 return *ModiList.back();
120 SourceFileNames.
insert(std::make_pair(File,
Index));
121 Module.addSourceFile(File);
126 auto NameIter = SourceFileNames.
find(File);
127 if (NameIter == SourceFileNames.
end())
129 "The specified source file was not found");
130 return NameIter->getValue();
133uint32_t DbiStreamBuilder::calculateModiSubstreamSize()
const {
135 for (
const auto &M : ModiList)
136 Size += M->calculateSerializedLength();
140uint32_t DbiStreamBuilder::calculateSectionContribsStreamSize()
const {
141 if (SectionContribs.empty())
144 sizeof(SectionContribs[0]) * SectionContribs.size();
147uint32_t DbiStreamBuilder::calculateSectionMapStreamSize()
const {
148 if (SectionMap.empty())
153uint32_t DbiStreamBuilder::calculateNamesOffset()
const {
160 for (
const auto &M : ModiList)
161 NumFileInfos +=
M->source_files().size();
166uint32_t DbiStreamBuilder::calculateFileInfoSubstreamSize()
const {
168 Size += calculateNamesBufferSize();
172uint32_t DbiStreamBuilder::calculateNamesBufferSize()
const {
174 for (
const auto &
F : SourceFileNames) {
175 Size +=
F.getKeyLength() + 1;
180uint32_t DbiStreamBuilder::calculateDbgStreamsSize()
const {
181 return DbgStreams.size() *
sizeof(
uint16_t);
184Error DbiStreamBuilder::generateFileInfoSubstream() {
187 uint32_t NamesOffset = calculateNamesOffset();
196 uint16_t ModiCount = std::min<uint32_t>(UINT16_MAX, ModiList.size());
197 uint16_t FileCount = std::min<uint32_t>(UINT16_MAX, SourceFileNames.size());
198 if (
auto EC = MetadataWriter.writeInteger(ModiCount))
200 if (
auto EC = MetadataWriter.writeInteger(FileCount))
203 if (
auto EC = MetadataWriter.writeInteger(
I))
206 for (
const auto &
MI : ModiList) {
207 FileCount =
static_cast<uint16_t>(
MI->source_files().size());
208 if (
auto EC = MetadataWriter.writeInteger(FileCount))
218 for (
auto &
Name : SourceFileNames) {
219 Name.second = NameBufferWriter.getOffset();
220 if (
auto EC = NameBufferWriter.writeCString(
Name.getKey()))
224 for (
const auto &
MI : ModiList) {
227 if (Result == SourceFileNames.end())
229 "The source file was not found.");
230 if (
auto EC = MetadataWriter.writeInteger(
Result->second))
235 if (
auto EC = NameBufferWriter.padToAlignment(
sizeof(
uint32_t)))
238 if (NameBufferWriter.bytesRemaining() > 0)
240 "The names buffer contained unexpected data.");
242 if (MetadataWriter.bytesRemaining() >
sizeof(
uint32_t))
243 return make_error<RawError>(
245 "The metadata buffer contained unexpected data.");
250Error DbiStreamBuilder::finalize() {
254 for (
auto &
MI : ModiList)
257 if (
auto EC = generateFileInfoSubstream())
262 H->VersionHeader = *VerHeader;
263 H->VersionSignature = -1;
265 H->BuildNumber = BuildNumber;
267 H->PdbDllRbld = PdbDllRbld;
268 H->PdbDllVersion = PdbDllVersion;
269 H->MachineType =
static_cast<uint16_t>(MachineType);
273 H->ModiSubstreamSize = calculateModiSubstreamSize();
274 H->OptionalDbgHdrSize = DbgStreams.size() *
sizeof(
uint16_t);
275 H->SecContrSubstreamSize = calculateSectionContribsStreamSize();
276 H->SectionMapSize = calculateSectionMapStreamSize();
277 H->TypeServerSize = 0;
278 H->SymRecordStreamIndex = SymRecordStreamIndex;
279 H->PublicSymbolStreamIndex = PublicsStreamIndex;
280 H->MFCTypeServerIndex = 0;
281 H->GlobalSymbolStreamIndex = GlobalsStreamIndex;
291 NewFpoData->calculateSerializedSize();
294 return NewFpoData->commit(Writer);
298 if (!OldFpoData.empty()) {
308 for (
auto &S : DbgStreams) {
311 auto ExpectedIndex = Msf.
addStream(S->Size);
313 return ExpectedIndex.takeError();
314 S->StreamNumber = *ExpectedIndex;
317 for (
auto &
MI : ModiList) {
318 if (
auto EC =
MI->finalizeMsfLayout())
355 SectionMap.emplace_back();
356 auto &Entry = SectionMap.back();
357 memset(&Entry, 0,
sizeof(Entry));
359 Entry.Frame =
Idx + 1;
362 Entry.SecName = UINT16_MAX;
363 Entry.ClassName = UINT16_MAX;
368 for (
auto &Hdr : SecHdrs) {
371 Entry.SecByteLength = Hdr.VirtualSize;
379 Entry.SecByteLength = UINT32_MAX;
384 if (
auto EC = finalize())
388 Layout, MsfBuffer,
StreamDBI, Allocator);
394 for (
auto &M : ModiList) {
395 if (
auto EC = M->commit(Writer))
401 ModiList, [&](std::unique_ptr<DbiModuleDescriptorBuilder> &M) {
402 return M->commitSymbolStream(Layout, MsfBuffer);
406 if (!SectionContribs.empty()) {
413 if (!SectionMap.empty()) {
414 ulittle16_t
Size =
static_cast<ulittle16_t
>(SectionMap.size());
425 if (
auto EC = ECNamesBuilder.
commit(Writer))
428 for (
auto &Stream : DbgStreams) {
431 StreamNumber = Stream->StreamNumber;
436 for (
auto &Stream : DbgStreams) {
442 Layout, MsfBuffer, Stream->StreamNumber, Allocator);
445 if (
auto EC = Stream->WriteFn(DbgStreamWriter))
451 "Unexpected bytes found in DBI Stream");
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static uint16_t toSecMapFlags(uint32_t Flags)
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
RefType drop_front(uint64_t N) const
Return a new BinaryStreamRef with the first N elements removed.
RefType keep_front(uint64_t N) const
Return a new BinaryStreamRef with only the first N elements remaining.
Provides write only access to a subclass of WritableBinaryStream.
Error writeArray(ArrayRef< T > Array)
Writes an array of objects of type T to the underlying stream, as if by using memcpy.
Error writeInteger(T Value)
Write the integer Value to the underlying stream in the specified endianness.
uint64_t bytesRemaining() const
Error writeStreamRef(BinaryStreamRef Ref)
Efficiently reads all data from Ref, and writes it to this stream.
Error writeEnum(T Num)
Similar to writeInteger.
Error writeObject(const T &Obj)
Writes the object Obj to the underlying stream, as if by using memcpy.
LLVM_ATTRIBUTE_RETURNS_NONNULL void * Allocate(size_t Size, Align Alignment)
Allocate space at the specified alignment.
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.
A Module instance is used to store all the information related to an LLVM module.
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
An implementation of BinaryStream which holds its entire data set in a single contiguous buffer.
uint64_t getLength() override
Return the number of bytes of data in this stream.
iterator find(StringRef Key)
bool insert(MapEntryTy *KeyValue)
insert - Insert the specified key/value pair into the map.
StringRef - Represent a constant reference to a string, i.e.
The instances of the Type class are immutable: once they are created, they are never changed.
Error setStreamSize(uint32_t Idx, uint32_t Size)
Update the size of an existing stream.
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.
static std::unique_ptr< WritableMappedBlockStream > createIndexedStream(const MSFLayout &Layout, WritableBinaryStreamRef MsfData, uint32_t StreamIndex, BumpPtrAllocator &Allocator)
void createSectionMap(ArrayRef< llvm::object::coff_section > SecHdrs)
void addOldFpoData(const object::FpoData &Fpo)
void setPublicsStreamIndex(uint32_t Index)
void setFlags(uint16_t F)
Error addModuleSourceFile(DbiModuleDescriptorBuilder &Module, StringRef File)
void setGlobalsStreamIndex(uint32_t Index)
Expected< uint32_t > getSourceFileNameIndex(StringRef FileName)
Error finalizeMsfLayout()
void setSymbolRecordStreamIndex(uint32_t Index)
void addNewFpoData(const codeview::FrameData &FD)
void setVersionHeader(PdbRaw_DbiVer V)
Error commit(const msf::MSFLayout &Layout, WritableBinaryStreamRef MsfBuffer)
Expected< DbiModuleDescriptorBuilder & > addModuleInfo(StringRef ModuleName)
uint32_t calculateSerializedLength() const
Error addDbgStream(pdb::DbgHeaderType Type, ArrayRef< uint8_t > Data)
uint32_t addECName(StringRef Name)
void setBuildNumber(uint16_t B)
void setPdbDllVersion(uint16_t V)
void setMachineType(PDB_Machine M)
void setPdbDllRbld(uint16_t R)
DbiStreamBuilder(msf::MSFBuilder &Msf)
uint32_t insert(StringRef S)
uint32_t calculateSerializedSize() const
Error commit(BinaryStreamWriter &Writer) const
const uint16_t kInvalidStreamIndex
detail::packed_endian_specific_integral< uint16_t, little, unaligned > ulittle16_t
detail::packed_endian_specific_integral< uint32_t, little, unaligned > ulittle32_t
This is an optimization pass for GlobalISel generic memory operations.
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
Error parallelForEachError(RangeTy &&R, FuncTy Fn)
Data in the SUBSEC_FRAMEDATA subection.
static const uint16_t BuildMajorShift
static const uint16_t NewVersionFormatMask
static const uint16_t BuildMajorMask
static const uint16_t BuildMinorMask
uint16_t MinorVersion : 8; uint16_t MajorVersion : 7; uint16_t NewVersionFormat : 1;
static const uint16_t BuildMinorShift