31template <
typename ContribType>
35 return make_error<RawError>(
36 raw_error_code::corrupt_file,
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.");
62 "Invalid DBI version signature.");
69 "Unsupported DBI version.");
71 if (Stream->getLength() !=
77 "DBI Length does not equal sum of substreams.");
83 "DBI MODI substream not aligned.");
85 return make_error<RawError>(
87 "DBI section contribution substream not aligned.");
90 "DBI section map substream not aligned.");
93 "DBI file info substream not aligned.");
96 "DBI type server substream not aligned.");
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))
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)
238Error DbiStream::initializeSectionContributionData() {
239 if (SecContrSubstream.
empty())
243 if (
auto EC = SCReader.readEnum(SectionContribVersion))
247 return loadSectionContribs<SectionContrib>(SectionContribs, SCReader);
249 return loadSectionContribs<SectionContrib2>(SectionContribs2, SCReader);
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);
312 auto &
FS = *ExpectedStream;
319 NewFpoStream = std::move(FS);
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];
Lightweight arrays that are backed by an arbitrary BinaryStream.
COFF::MachineTypes Machine
static Error loadSectionContribs(FixedStreamArray< ContribType > &Output, BinaryStreamReader &Reader)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
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...
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.
The instances of the Type class are immutable: once they are created, they are never changed.
LLVM Value Representation.
Error initialize(BinaryStreamReader Reader)
Error initialize(BinaryStreamRef ModInfo, BinaryStreamRef FileInfo)
Expected< StringRef > getECName(uint32_t NI) const
BinarySubstreamRef getSecMapSubstreamData() const
PDB_Machine getMachineType() const
BinarySubstreamRef getFileInfoSubstreamData() const
void visitSectionContributions(ISectionContribVisitor &Visitor) const
bool isIncrementallyLinked() const
uint16_t getFlags() const
PdbRaw_DbiVer getDbiVersion() const
bool hasNewFpoRecords() const
uint16_t getBuildMajorVersion() const
FixedStreamArray< object::coff_section > getSectionHeaders() const
uint16_t getGlobalSymbolStreamIndex() const
DbiStream(std::unique_ptr< BinaryStream > Stream)
Error reload(PDBFile *Pdb)
BinarySubstreamRef getTypeServerMapSubstreamData() const
BinarySubstreamRef getModiSubstreamData() const
const DbiModuleList & modules() const
uint16_t getBuildNumber() const
const codeview::DebugFrameDataSubsectionRef & getNewFpoRecords() const
uint16_t getBuildMinorVersion() const
uint32_t getDebugStreamIndex(DbgHeaderType Type) const
If the given stream type is present, returns its stream index.
FixedStreamArray< object::FpoData > getOldFpoRecords() const
uint32_t getPdbDllVersion() const
uint32_t getSymRecordStreamIndex() const
uint16_t getPublicSymbolStreamIndex() const
BinarySubstreamRef getECSubstreamData() const
uint16_t getPdbDllRbld() const
FixedStreamArray< SecMapEntry > getSectionMap() const
BinarySubstreamRef getSectionContributionData() const
bool hasOldFpoRecords() const
virtual void visit(const SectionContrib &C)=0
Error reload(BinaryStreamReader &Reader)
Expected< StringRef > getStringForID(uint32_t ID) const
const uint16_t kInvalidStreamIndex
This is an optimization pass for GlobalISel generic memory operations.
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