33 template <
typename ContribType>
37 return make_error<RawError>(
38 raw_error_code::corrupt_file,
39 "Invalid number of bytes of section contributions");
47 DbiStream::DbiStream(std::unique_ptr<BinaryStream> Stream)
48 : Stream(
std::move(Stream)), Header(nullptr) {}
57 "DBI Stream does not contain a header.");
59 return make_error<RawError>(raw_error_code::corrupt_file,
60 "DBI Stream does not contain a header.");
64 "Invalid DBI version signature.");
71 "Unsupported DBI version.");
73 if (Stream->getLength() !=
79 "DBI Length does not equal sum of substreams.");
84 return make_error<RawError>(raw_error_code::corrupt_file,
85 "DBI MODI substream not aligned.");
87 return make_error<RawError>(
88 raw_error_code::corrupt_file,
89 "DBI section contribution substream not aligned.");
91 return make_error<RawError>(raw_error_code::corrupt_file,
92 "DBI section map substream not aligned.");
94 return make_error<RawError>(raw_error_code::corrupt_file,
95 "DBI file info substream not aligned.");
97 return make_error<RawError>(raw_error_code::corrupt_file,
98 "DBI type server substream not aligned.");
123 if (
auto EC = initializeSectionContributionData())
125 if (
auto EC = initializeSectionHeadersData(Pdb))
127 if (
auto EC = initializeSectionMapData())
129 if (
auto EC = initializeOldFpoRecords(Pdb))
131 if (
auto EC = initializeNewFpoRecords(Pdb))
135 return make_error<RawError>(raw_error_code::corrupt_file,
136 "Found unexpected bytes in DBI Stream.");
138 if (!ECSubstream.
empty()) {
140 if (
auto EC = ECNames.
reload(ECReader))
202 return SectionHeaders;
208 return OldFpoRecords;
214 return NewFpoRecords;
225 if (!SectionContribs.empty()) {
227 for (
auto &
SC : SectionContribs)
229 }
else if (!SectionContribs2.empty()) {
231 for (
auto &
SC : SectionContribs2)
240 Error DbiStream::initializeSectionContributionData() {
241 if (SecContrSubstream.
empty())
245 if (
auto EC = SCReader.
readEnum(SectionContribVersion))
249 return loadSectionContribs<SectionContrib>(SectionContribs, SCReader);
251 return loadSectionContribs<SectionContrib2>(SectionContribs2, SCReader);
254 "Unsupported DBI Section Contribution version");
264 auto &SHS = *ExpectedStream;
268 size_t StreamLen = SHS->getLength();
271 "Corrupted section header stream.");
275 if (
auto EC = Reader.
readArray(SectionHeaders, NumSections))
276 return make_error<RawError>(raw_error_code::corrupt_file,
277 "Could not read a bitmap.");
279 SectionHeaderStream = std::move(SHS);
284 Error DbiStream::initializeOldFpoRecords(
PDBFile *Pdb) {
290 auto &
FS = *ExpectedStream;
294 size_t StreamLen =
FS->getLength();
297 "Corrupted Old FPO stream.");
301 if (
auto EC = Reader.
readArray(OldFpoRecords, NumRecords))
302 return make_error<RawError>(raw_error_code::corrupt_file,
303 "Corrupted Old FPO stream.");
304 OldFpoStream = std::move(
FS);
308 Error DbiStream::initializeNewFpoRecords(
PDBFile *Pdb) {
314 auto &
FS = *ExpectedStream;
321 NewFpoStream = std::move(
FS);
326 DbiStream::createIndexedStreamForHeaderType(
PDBFile *Pdb,
331 if (DbgStreams.empty())
344 return SecContrSubstream;
348 return SecMapSubstream;
352 return ModiSubstream;
356 return FileInfoSubstream;
360 return TypeServerMapSubstream;
365 Error DbiStream::initializeSectionMapData() {
366 if (SecMapSubstream.
empty())
380 if (T >= DbgStreams.size())
382 return DbgStreams[
T];
virtual void visit(const SectionContrib &C)=0
bool hasOldFpoRecords() const
FixedStreamArray< object::FpoData > getOldFpoRecords() const
static const uint16_t FlagHasCTypesMask
static Error loadSectionContribs(FixedStreamArray< ContribType > &Output, BinaryStreamReader &Reader)
This class represents lattice values for constants.
Expected< StringRef > getECName(uint32_t NI) const
BinarySubstreamRef getECSubstreamData() const
static const uint16_t BuildMinorMask
uint16_t MinorVersion : 8; uint16_t MajorVersion : 7; uint16_t NewVersionFormat : 1; ...
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 reload(BinaryStreamReader &Reader)
Error takeError()
Take ownership of the stored error.
FixedStreamArray is similar to VarStreamArray, except with each record having a fixed-length.
uint16_t getGlobalSymbolStreamIndex() const
Error reload(PDBFile *Pdb)
FixedStreamArray< object::coff_section > getSectionHeaders() const
BinarySubstreamRef getSectionContributionData() const
PDB_Machine getMachineType() const
Tagged union holding either a T or a Error.
BinarySubstreamRef getSecMapSubstreamData() const
uint32_t getSymRecordStreamIndex() const
Expected< StringRef > getStringForID(uint32_t ID) const
uint16_t getBuildNumber() const
Expected< std::unique_ptr< msf::MappedBlockStream > > safelyCreateIndexedStream(uint32_t StreamIndex) const
Wrapper around MappedBlockStream::createIndexedStream() that checks if a stream with that index actua...
COFF::MachineTypes Machine
Error initialize(BinaryStreamReader Reader)
BinarySubstreamRef getTypeServerMapSubstreamData() const
const uint16_t kInvalidStreamIndex
static const uint16_t BuildMajorShift
The instances of the Type class are immutable: once they are created, they are never changed...
uint16_t getBuildMajorVersion() const
Error initialize(BinaryStreamRef ModInfo, BinaryStreamRef FileInfo)
uint32_t getDebugStreamIndex(DbgHeaderType Type) const
If the given stream type is present, returns its stream index.
uint16_t getBuildMinorVersion() const
const DbiModuleList & modules() const
uint32_t getPdbDllVersion() const
BinaryStreamRef StreamData
bool hasNewFpoRecords() const
static const uint16_t FlagIncrementalMask
uint16_t IncrementalLinking : 1; // True if linked incrementally uint16_t IsStripped : 1; // True if ...
static ErrorSuccess success()
Create a success value.
CHAIN = SC CHAIN, Imm128 - System call.
BinarySubstreamRef getFileInfoSubstreamData() const
static const uint16_t FlagStrippedMask
PdbRaw_DbiVer getDbiVersion() const
Error readSubstream(BinarySubstreamRef &Ref, uint32_t Length)
Read Length bytes from the underlying stream into Ref.
static const uint16_t BuildMajorMask
static const uint16_t BuildMinorShift
uint32_t bytesRemaining() const
uint16_t getPdbDllRbld() const
uint16_t getPublicSymbolStreamIndex() const
uint16_t getFlags() const
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM Value Representation.
Lightweight error class with error context and mandatory checking.
const codeview::DebugFrameDataSubsectionRef & getNewFpoRecords() const
Provides read only access to a subclass of BinaryStream.
BinarySubstreamRef getModiSubstreamData() const
Error readEnum(T &Dest)
Similar to readInteger.
void visitSectionContributions(ISectionContribVisitor &Visitor) const
FixedStreamArray< SecMapEntry > getSectionMap() const
bool isIncrementallyLinked() 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 ...