31template <
typename ContribType>
37 "Invalid number of bytes of section contributions");
46 : Stream(
std::
move(Stream)), Header(nullptr) {}
55 "DBI Stream does not contain a header.");
58 "DBI Stream does not contain a header.");
60 if (Header->VersionSignature != -1)
62 "Invalid DBI version signature.");
69 "Unsupported DBI version.");
71 if (Stream->getLength() !=
73 Header->SecContrSubstreamSize + Header->SectionMapSize +
74 Header->FileInfoSize + Header->TypeServerSize +
75 Header->OptionalDbgHdrSize + Header->ECSubstreamSize)
77 "DBI Length does not equal sum of substreams.");
81 if (Header->ModiSubstreamSize %
sizeof(
uint32_t) != 0)
83 "DBI MODI substream not aligned.");
84 if (Header->SecContrSubstreamSize %
sizeof(
uint32_t) != 0)
87 "DBI section contribution substream not aligned.");
88 if (Header->SectionMapSize %
sizeof(
uint32_t) != 0)
90 "DBI section map substream not aligned.");
91 if (Header->FileInfoSize %
sizeof(
uint32_t) != 0)
93 "DBI file info substream not aligned.");
94 if (Header->TypeServerSize %
sizeof(
uint32_t) != 0)
96 "DBI type server substream not aligned.");
98 if (
auto EC = Reader.
readSubstream(ModiSubstream, Header->ModiSubstreamSize))
102 Header->SecContrSubstreamSize))
104 if (
auto EC = Reader.
readSubstream(SecMapSubstream, Header->SectionMapSize))
106 if (
auto EC = Reader.
readSubstream(FileInfoSubstream, Header->FileInfoSize))
109 Reader.
readSubstream(TypeServerMapSubstream, Header->TypeServerSize))
111 if (
auto EC = Reader.
readSubstream(ECSubstream, Header->ECSubstreamSize))
114 DbgStreams, Header->OptionalDbgHdrSize /
sizeof(
ulittle16_t)))
117 if (
auto EC = Modules.initialize(ModiSubstream.StreamData,
118 FileInfoSubstream.StreamData))
121 if (
auto EC = initializeSectionContributionData())
123 if (
auto EC = initializeSectionHeadersData(
Pdb))
125 if (
auto EC = initializeSectionMapData())
127 if (
auto EC = initializeOldFpoRecords(
Pdb))
129 if (
auto EC = initializeNewFpoRecords(
Pdb))
134 "Found unexpected bytes in DBI Stream.");
136 if (!ECSubstream.empty()) {
138 if (
auto EC = ECNames.reload(ECReader))
153 return Header->PublicSymbolStreamIndex;
157 return Header->GlobalSymbolStreamIndex;
191 return Header->SymRecordStreamIndex;
200 return SectionHeaders;
206 return OldFpoRecords;
212 return NewFpoRecords;
223 if (!SectionContribs.empty()) {
225 for (
auto &SC : SectionContribs)
227 }
else if (!SectionContribs2.empty()) {
229 for (
auto &SC : SectionContribs2)
235 return ECNames.getStringForID(NI);
238Error DbiStream::initializeSectionContributionData() {
239 if (SecContrSubstream.
empty())
243 if (
auto EC = SCReader.readEnum(SectionContribVersion))
252 "Unsupported DBI Section Contribution version");
262 auto &SHS = *ExpectedStream;
266 size_t StreamLen = SHS->getLength();
269 "Corrupted section header stream.");
273 if (
auto EC = Reader.readArray(SectionHeaders, NumSections))
275 "Could not read a bitmap.");
277 SectionHeaderStream = std::move(SHS);
288 auto &FS = *ExpectedStream;
292 size_t StreamLen = FS->getLength();
295 "Corrupted Old FPO stream.");
299 if (
auto EC = Reader.readArray(OldFpoRecords, NumRecords))
301 "Corrupted Old FPO stream.");
302 OldFpoStream = std::move(FS);
307 Expected<std::unique_ptr<msf::MappedBlockStream>> ExpectedStream =
312 auto &
FS = *ExpectedStream;
316 if (
auto EC = NewFpoRecords.initialize(*FS))
319 NewFpoStream = std::move(FS);
323Expected<std::unique_ptr<msf::MappedBlockStream>>
324DbiStream::createIndexedStreamForHeaderType(
PDBFile *
Pdb,
329 if (DbgStreams.empty())
338 return Pdb->safelyCreateIndexedStream(StreamNum);
342 return SecContrSubstream;
346 return SecMapSubstream;
350 return ModiSubstream;
354 return FileInfoSubstream;
358 return TypeServerMapSubstream;
363Error DbiStream::initializeSectionMapData() {
364 if (SecMapSubstream.
empty())
369 if (
auto EC = SMReader.readObject(Header))
371 if (
auto EC = SMReader.readArray(SectionMap, Header->SecCount))
378 if (
T >= DbgStreams.size())
380 return DbgStreams[
T];
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
Lightweight arrays that are backed by an arbitrary BinaryStream.
static Error loadSectionContribs(FixedStreamArray< ContribType > &Output, BinaryStreamReader &Reader)
Function const char TargetMachine * Machine
Provides read only access to a subclass of BinaryStream.
Error readObject(const T *&Dest)
Get a pointer to an object of type T from the underlying stream, as if by memcpy, and store the resul...
LLVM_ABI Error readSubstream(BinarySubstreamRef &Ref, uint32_t Length)
Read Length bytes from the underlying stream into Ref.
uint64_t bytesRemaining() const
Error readArray(ArrayRef< T > &Array, uint32_t NumElements)
Get a reference to a NumElements element array of objects of type T from the underlying stream as if ...
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.
Error takeError()
Take ownership of the stored error.
FixedStreamArray is similar to VarStreamArray, except with each record having a fixed-length.
LLVM Value Representation.
LLVM_ABI Expected< StringRef > getECName(uint32_t NI) const
LLVM_ABI BinarySubstreamRef getSecMapSubstreamData() const
LLVM_ABI PDB_Machine getMachineType() const
LLVM_ABI BinarySubstreamRef getFileInfoSubstreamData() const
LLVM_ABI void visitSectionContributions(ISectionContribVisitor &Visitor) const
LLVM_ABI uint32_t getAge() const
LLVM_ABI bool isIncrementallyLinked() const
LLVM_ABI uint16_t getFlags() const
LLVM_ABI PdbRaw_DbiVer getDbiVersion() const
LLVM_ABI bool isStripped() const
LLVM_ABI bool hasNewFpoRecords() const
LLVM_ABI uint16_t getBuildMajorVersion() const
LLVM_ABI FixedStreamArray< object::coff_section > getSectionHeaders() const
LLVM_ABI uint16_t getGlobalSymbolStreamIndex() const
LLVM_ABI DbiStream(std::unique_ptr< BinaryStream > Stream)
LLVM_ABI Error reload(PDBFile *Pdb)
LLVM_ABI BinarySubstreamRef getTypeServerMapSubstreamData() const
LLVM_ABI BinarySubstreamRef getModiSubstreamData() const
LLVM_ABI const DbiModuleList & modules() const
LLVM_ABI uint16_t getBuildNumber() const
LLVM_ABI const codeview::DebugFrameDataSubsectionRef & getNewFpoRecords() const
LLVM_ABI uint16_t getBuildMinorVersion() const
LLVM_ABI uint32_t getDebugStreamIndex(DbgHeaderType Type) const
If the given stream type is present, returns its stream index.
LLVM_ABI FixedStreamArray< object::FpoData > getOldFpoRecords() const
LLVM_ABI uint32_t getPdbDllVersion() const
LLVM_ABI uint32_t getSymRecordStreamIndex() const
LLVM_ABI uint16_t getPublicSymbolStreamIndex() const
LLVM_ABI BinarySubstreamRef getECSubstreamData() const
LLVM_ABI bool hasCTypes() const
LLVM_ABI uint16_t getPdbDllRbld() const
LLVM_ABI FixedStreamArray< SecMapEntry > getSectionMap() const
LLVM_ABI BinarySubstreamRef getSectionContributionData() const
LLVM_ABI bool hasOldFpoRecords() const
virtual void visit(const SectionContrib &C)=0
const uint16_t kInvalidStreamIndex
detail::packed_endian_specific_integral< uint16_t, llvm::endianness::little, unaligned > ulittle16_t
This is an optimization pass for GlobalISel generic memory operations.
FunctionAddr VTableAddr Count
Error make_error(ArgTs &&... Args)
Make a Error instance representing failure using the given error info type.
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Implement std::hash so that hash_code can be used in STL containers.
BinaryStreamRef StreamData
static const uint16_t BuildMajorShift
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
static const uint16_t FlagIncrementalMask
uint16_t IncrementalLinking : 1; // True if linked incrementally uint16_t IsStripped : 1; // True if ...
static const uint16_t FlagHasCTypesMask
static const uint16_t FlagStrippedMask