28 : Msf(Msf),
Allocator(Msf.getAllocator()), Age(1), BuildNumber(0),
29 PdbDllVersion(0), PdbDllRbld(0), Flags(0), MachineType(
PDB_Machine::
x86),
66 GlobalsStreamIndex =
Index;
70 SymRecordStreamIndex =
Index;
74 PublicsStreamIndex =
Index;
78 if (!NewFpoData.hasValue())
79 NewFpoData.emplace(
false);
81 NewFpoData->addFrameData(FD);
85 OldFpoData.push_back(FD);
91 "NewFPO data should be written via addFrameData()!");
93 DbgStreams[(int)Type].emplace();
94 DbgStreams[(int)Type]->
Size = Data.
size();
102 return ECNamesBuilder.
insert(Name);
108 calculateModiSubstreamSize() + calculateSectionContribsStreamSize() +
109 calculateSectionMapStreamSize() + calculateDbgStreamsSize() +
117 std::make_unique<DbiModuleDescriptorBuilder>(ModuleName, Index, Msf));
118 return *ModiList.back();
124 SourceFileNames.
insert(std::make_pair(File, Index));
125 Module.addSourceFile(File);
130 auto NameIter = SourceFileNames.
find(File);
131 if (NameIter == SourceFileNames.
end())
133 "The specified source file was not found");
134 return NameIter->getValue();
137 uint32_t DbiStreamBuilder::calculateModiSubstreamSize()
const {
139 for (
const auto &M : ModiList)
140 Size += M->calculateSerializedLength();
144 uint32_t DbiStreamBuilder::calculateSectionContribsStreamSize()
const {
145 if (SectionContribs.empty())
148 sizeof(SectionContribs[0]) * SectionContribs.size();
151 uint32_t DbiStreamBuilder::calculateSectionMapStreamSize()
const {
152 if (SectionMap.empty())
157 uint32_t DbiStreamBuilder::calculateNamesOffset()
const {
164 for (
const auto &M : ModiList)
165 NumFileInfos += M->source_files().size();
170 uint32_t DbiStreamBuilder::calculateFileInfoSubstreamSize()
const {
172 Size += calculateNamesBufferSize();
176 uint32_t DbiStreamBuilder::calculateNamesBufferSize()
const {
178 for (
const auto &
F : SourceFileNames) {
179 Size +=
F.getKeyLength() + 1;
184 uint32_t DbiStreamBuilder::calculateDbgStreamsSize()
const {
185 return DbgStreams.size() *
sizeof(
uint16_t);
188 Error DbiStreamBuilder::generateFileInfoSubstream() {
191 uint32_t NamesOffset = calculateNamesOffset();
200 uint16_t ModiCount = std::min<uint32_t>(UINT16_MAX, ModiList.size());
201 uint16_t FileCount = std::min<uint32_t>(UINT16_MAX, SourceFileNames.
size());
210 for (
const auto &
MI : ModiList) {
211 FileCount =
static_cast<uint16_t>(
MI->source_files().size());
222 for (
auto &
Name : SourceFileNames) {
228 for (
const auto &
MI : ModiList) {
230 auto Result = SourceFileNames.find(
Name);
231 if (Result == SourceFileNames.end())
233 "The source file was not found.");
244 "The names buffer contained unexpected data.");
247 return make_error<RawError>(
249 "The metadata buffer contained unexpected data.");
254 Error DbiStreamBuilder::finalize() {
258 for (
auto &
MI : ModiList)
261 if (
auto EC = generateFileInfoSubstream())
292 if (NewFpoData.hasValue()) {
295 NewFpoData->calculateSerializedSize();
298 return NewFpoData->commit(Writer);
302 if (!OldFpoData.empty()) {
312 for (
auto &S : DbgStreams) {
315 auto ExpectedIndex = Msf.
addStream(S->Size);
317 return ExpectedIndex.takeError();
318 S->StreamNumber = *ExpectedIndex;
321 for (
auto &
MI : ModiList) {
322 if (
auto EC =
MI->finalizeMsfLayout())
340 if (Flags & COFF::IMAGE_SCN_MEM_EXECUTE)
358 std::vector<SecMapEntry>
Ret;
363 auto &
Entry = Ret.back();
366 Entry.Frame = Idx + 1;
369 Entry.SecName = UINT16_MAX;
370 Entry.ClassName = UINT16_MAX;
375 for (
auto &Hdr : SecHdrs) {
378 Entry.SecByteLength = Hdr.VirtualSize;
386 Entry.SecByteLength = UINT32_MAX;
393 if (
auto EC = finalize())
396 auto DbiS = WritableMappedBlockStream::createIndexedStream(
397 Layout, MsfBuffer,
StreamDBI, Allocator);
403 for (
auto &M : ModiList) {
404 if (
auto EC = M->commit(Writer, Layout, MsfBuffer))
408 if (!SectionContribs.empty()) {
415 if (!SectionMap.empty()) {
427 if (
auto EC = ECNamesBuilder.
commit(Writer))
430 for (
auto &Stream : DbgStreams) {
432 if (Stream.hasValue())
433 StreamNumber = Stream->StreamNumber;
438 for (
auto &Stream : DbgStreams) {
439 if (!Stream.hasValue())
443 auto WritableStream = WritableMappedBlockStream::createIndexedStream(
444 Layout, MsfBuffer, Stream->StreamNumber, Allocator);
447 if (
auto EC = Stream->WriteFn(DbgStreamWriter))
453 "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.
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
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)
detail::packed_endian_specific_integral< uint16_t, little, unaligned > ulittle16_t
void setGlobalsStreamIndex(uint32_t Index)
Error commit(BinaryStreamWriter &Writer) const
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
Instrumentation for Order File
size_t size() const
size - Get the array size.
uint32_t insert(StringRef S)
Expected< uint32_t > getSourceFileNameIndex(StringRef FileName)
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)
LLVM_ATTRIBUTE_RETURNS_NONNULL LLVM_ATTRIBUTE_RETURNS_NOALIAS void * Allocate(size_t Size, Align Alignment)
Allocate space at the specified alignment.
void addOldFpoData(const object::FpoData &Fpo)
Error writeEnum(T Num)
Similar to writeInteger.
void setPublicsStreamIndex(uint32_t Index)
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
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.