29 : Msf(Msf),
Allocator(Msf.getAllocator()), Age(1), BuildNumber(0),
30 PdbDllVersion(0), PdbDllRbld(0), Flags(0), MachineType(
PDB_Machine::
x86),
63 GlobalsStreamIndex =
Index;
67 SymRecordStreamIndex =
Index;
71 PublicsStreamIndex =
Index;
76 NewFpoData.emplace(
false);
78 NewFpoData->addFrameData(FD);
82 OldFpoData.push_back(FD);
88 "NewFPO data should be written via addFrameData()!");
90 DbgStreams[(int)
Type] = DebugStream{};
105 calculateModiSubstreamSize() + calculateSectionContribsStreamSize() +
106 calculateSectionMapStreamSize() + calculateDbgStreamsSize() +
115 return *ModiList.back();
121 SourceFileNames.
insert(std::make_pair(File,
Index));
122 Module.addSourceFile(File);
127 auto NameIter = SourceFileNames.
find(File);
128 if (NameIter == SourceFileNames.
end())
130 "The specified source file was not found");
131 return NameIter->getValue();
134uint32_t DbiStreamBuilder::calculateModiSubstreamSize()
const {
136 for (
const auto &M : ModiList)
137 Size += M->calculateSerializedLength();
141uint32_t DbiStreamBuilder::calculateSectionContribsStreamSize()
const {
142 if (SectionContribs.empty())
145 sizeof(SectionContribs[0]) * SectionContribs.size();
148uint32_t DbiStreamBuilder::calculateSectionMapStreamSize()
const {
149 if (SectionMap.empty())
154uint32_t DbiStreamBuilder::calculateNamesOffset()
const {
161 for (
const auto &M : ModiList)
162 NumFileInfos +=
M->source_files().size();
167uint32_t DbiStreamBuilder::calculateFileInfoSubstreamSize()
const {
169 Size += calculateNamesBufferSize();
173uint32_t DbiStreamBuilder::calculateNamesBufferSize()
const {
175 for (
const auto &
F : SourceFileNames) {
176 Size +=
F.getKeyLength() + 1;
181uint32_t DbiStreamBuilder::calculateDbgStreamsSize()
const {
182 return DbgStreams.size() *
sizeof(
uint16_t);
185Error DbiStreamBuilder::generateFileInfoSubstream() {
188 uint32_t NamesOffset = calculateNamesOffset();
197 uint16_t ModiCount = std::min<uint32_t>(UINT16_MAX, ModiList.size());
198 uint16_t FileCount = std::min<uint32_t>(UINT16_MAX, SourceFileNames.size());
199 if (
auto EC = MetadataWriter.writeInteger(ModiCount))
201 if (
auto EC = MetadataWriter.writeInteger(FileCount))
204 if (
auto EC = MetadataWriter.writeInteger(
I))
207 for (
const auto &
MI : ModiList) {
208 FileCount =
static_cast<uint16_t>(
MI->source_files().size());
209 if (
auto EC = MetadataWriter.writeInteger(FileCount))
219 for (
auto &
Name : SourceFileNames) {
220 Name.second = NameBufferWriter.getOffset();
221 if (
auto EC = NameBufferWriter.writeCString(
Name.getKey()))
225 for (
const auto &
MI : ModiList) {
228 if (Result == SourceFileNames.end())
230 "The source file was not found.");
231 if (
auto EC = MetadataWriter.writeInteger(
Result->second))
236 if (
auto EC = NameBufferWriter.padToAlignment(
sizeof(
uint32_t)))
239 if (NameBufferWriter.bytesRemaining() > 0)
241 "The names buffer contained unexpected data.");
243 if (MetadataWriter.bytesRemaining() >
sizeof(
uint32_t))
244 return make_error<RawError>(
246 "The metadata buffer contained unexpected data.");
251Error DbiStreamBuilder::finalize() {
255 for (
auto &
MI : ModiList)
258 if (
auto EC = generateFileInfoSubstream())
263 H->VersionHeader = *VerHeader;
264 H->VersionSignature = -1;
266 H->BuildNumber = BuildNumber;
268 H->PdbDllRbld = PdbDllRbld;
269 H->PdbDllVersion = PdbDllVersion;
270 H->MachineType =
static_cast<uint16_t>(MachineType);
274 H->ModiSubstreamSize = calculateModiSubstreamSize();
275 H->OptionalDbgHdrSize = DbgStreams.size() *
sizeof(
uint16_t);
276 H->SecContrSubstreamSize = calculateSectionContribsStreamSize();
277 H->SectionMapSize = calculateSectionMapStreamSize();
278 H->TypeServerSize = 0;
279 H->SymRecordStreamIndex = SymRecordStreamIndex;
280 H->PublicSymbolStreamIndex = PublicsStreamIndex;
281 H->MFCTypeServerIndex = 0;
282 H->GlobalSymbolStreamIndex = GlobalsStreamIndex;
292 NewFpoData->calculateSerializedSize();
295 return NewFpoData->commit(Writer);
299 if (!OldFpoData.empty()) {
309 for (
auto &S : DbgStreams) {
312 auto ExpectedIndex = Msf.
addStream(S->Size);
314 return ExpectedIndex.takeError();
315 S->StreamNumber = *ExpectedIndex;
318 for (
auto &
MI : ModiList) {
319 if (
auto EC =
MI->finalizeMsfLayout())
356 SectionMap.emplace_back();
357 auto &Entry = SectionMap.back();
358 memset(&Entry, 0,
sizeof(Entry));
360 Entry.Frame =
Idx + 1;
363 Entry.SecName = UINT16_MAX;
364 Entry.ClassName = UINT16_MAX;
369 for (
auto &Hdr : SecHdrs) {
372 Entry.SecByteLength = Hdr.VirtualSize;
380 Entry.SecByteLength = UINT32_MAX;
386 if (
auto EC = finalize())
390 Layout, MsfBuffer,
StreamDBI, Allocator);
396 for (
auto &M : ModiList) {
397 if (
auto EC = M->commit(Writer))
403 ModiList, [&](std::unique_ptr<DbiModuleDescriptorBuilder> &M) {
404 return M->commitSymbolStream(Layout, MsfBuffer);
408 if (!SectionContribs.empty()) {
415 if (!SectionMap.empty()) {
416 ulittle16_t
Size =
static_cast<ulittle16_t
>(SectionMap.size());
427 if (
auto EC = ECNamesBuilder.
commit(Writer))
430 for (
auto &Stream : DbgStreams) {
433 StreamNumber = Stream->StreamNumber;
438 for (
auto &Stream : DbgStreams) {
444 Layout, MsfBuffer, Stream->StreamNumber, Allocator);
447 if (
auto EC = Stream->WriteFn(DbgStreamWriter))
453 "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 TimeTraceScope is a helper class to call the begin and end functions of the time trace profiler.
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, llvm::endianness::little, unaligned > ulittle16_t
detail::packed_endian_specific_integral< uint32_t, llvm::endianness::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