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;
79 DbgStreams[(int)Type].emplace();
80 DbgStreams[(int)Type]->Data = Data;
85 return ECNamesBuilder.
insert(Name);
91 calculateModiSubstreamSize() + calculateSectionContribsStreamSize() +
92 calculateSectionMapStreamSize() + calculateDbgStreamsSize() +
100 llvm::make_unique<DbiModuleDescriptorBuilder>(ModuleName, Index, Msf));
101 return *ModiList.back();
107 SourceFileNames.
insert(std::make_pair(File, Index));
108 Module.addSourceFile(File);
113 auto NameIter = SourceFileNames.
find(File);
114 if (NameIter == SourceFileNames.
end())
116 "The specified source file was not found");
117 return NameIter->getValue();
120 uint32_t DbiStreamBuilder::calculateModiSubstreamSize()
const {
122 for (
const auto &M : ModiList)
123 Size += M->calculateSerializedLength();
127 uint32_t DbiStreamBuilder::calculateSectionContribsStreamSize()
const {
128 if (SectionContribs.empty())
131 sizeof(SectionContribs[0]) * SectionContribs.size();
134 uint32_t DbiStreamBuilder::calculateSectionMapStreamSize()
const {
135 if (SectionMap.empty())
140 uint32_t DbiStreamBuilder::calculateNamesOffset()
const {
147 for (
const auto &M : ModiList)
148 NumFileInfos += M->source_files().size();
153 uint32_t DbiStreamBuilder::calculateFileInfoSubstreamSize()
const {
155 Size += calculateNamesBufferSize();
159 uint32_t DbiStreamBuilder::calculateNamesBufferSize()
const {
161 for (
const auto &
F : SourceFileNames) {
162 Size +=
F.getKeyLength() + 1;
167 uint32_t DbiStreamBuilder::calculateDbgStreamsSize()
const {
168 return DbgStreams.size() *
sizeof(uint16_t);
171 Error DbiStreamBuilder::generateFileInfoSubstream() {
174 uint32_t NamesOffset = calculateNamesOffset();
183 uint16_t ModiCount = std::min<uint32_t>(UINT16_MAX, ModiList.size());
184 uint16_t FileCount = std::min<uint32_t>(UINT16_MAX, SourceFileNames.
size());
189 for (uint16_t
I = 0;
I < ModiCount; ++
I) {
193 for (
const auto &
MI : ModiList) {
194 FileCount =
static_cast<uint16_t
>(
MI->source_files().size());
205 for (
auto &
Name : SourceFileNames) {
211 for (
const auto &
MI : ModiList) {
214 if (
Result == SourceFileNames.end())
216 "The source file was not found.");
227 "The names buffer contained unexpected data.");
230 return make_error<RawError>(
232 "The metadata buffer contained unexpected data.");
237 Error DbiStreamBuilder::finalize() {
241 for (
auto &
MI : ModiList)
244 if (
auto EC = generateFileInfoSubstream())
256 H->
MachineType =
static_cast<uint16_t
>(MachineType);
275 for (
auto &S : DbgStreams) {
278 auto ExpectedIndex = Msf.
addStream(S->Data.size());
280 return ExpectedIndex.takeError();
281 S->StreamNumber = *ExpectedIndex;
284 for (
auto &
MI : ModiList) {
285 if (
auto EC =
MI->finalizeMsfLayout())
303 if (Flags & COFF::IMAGE_SCN_MEM_EXECUTE)
321 std::vector<SecMapEntry>
Ret;
326 auto &Entry = Ret.back();
327 memset(&Entry, 0,
sizeof(Entry));
329 Entry.Frame = Idx + 1;
332 Entry.SecName = UINT16_MAX;
333 Entry.ClassName = UINT16_MAX;
338 for (
auto &Hdr : SecHdrs) {
341 Entry.SecByteLength = Hdr.VirtualSize;
349 Entry.SecByteLength = UINT32_MAX;
356 if (
auto EC = finalize())
359 auto DbiS = WritableMappedBlockStream::createIndexedStream(
360 Layout, MsfBuffer,
StreamDBI, Allocator);
366 for (
auto &M : ModiList) {
367 if (
auto EC = M->commit(Writer, Layout, MsfBuffer))
371 if (!SectionContribs.empty()) {
378 if (!SectionMap.empty()) {
390 if (
auto EC = ECNamesBuilder.
commit(Writer))
393 for (
auto &Stream : DbgStreams) {
395 if (Stream.hasValue())
396 StreamNumber = Stream->StreamNumber;
401 for (
auto &Stream : DbgStreams) {
402 if (!Stream.hasValue())
406 auto WritableStream = WritableMappedBlockStream::createIndexedStream(
407 Layout, MsfBuffer, Stream->StreamNumber, Allocator);
415 "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...
Compute iterated dominance frontiers using a linear time algorithm.
A Module instance is used to store all the information related to an LLVM module. ...
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
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
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.
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)
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())
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
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.