34 template <
typename ContribType>
38 return make_error<RawError>(
39 raw_error_code::corrupt_file,
40 "Invalid number of bytes of section contributions");
48 DbiStream::DbiStream(std::unique_ptr<BinaryStream> Stream)
49 : Stream(
std::move(Stream)), Header(nullptr) {}
58 "DBI Stream does not contain a header.");
60 return make_error<RawError>(raw_error_code::corrupt_file,
61 "DBI Stream does not contain a header.");
65 "Invalid DBI version signature.");
72 "Unsupported DBI version.");
74 if (Stream->getLength() !=
80 "DBI Length does not equal sum of substreams.");
85 return make_error<RawError>(raw_error_code::corrupt_file,
86 "DBI MODI substream not aligned.");
88 return make_error<RawError>(
89 raw_error_code::corrupt_file,
90 "DBI section contribution substream not aligned.");
92 return make_error<RawError>(raw_error_code::corrupt_file,
93 "DBI section map substream not aligned.");
95 return make_error<RawError>(raw_error_code::corrupt_file,
96 "DBI file info substream not aligned.");
98 return make_error<RawError>(raw_error_code::corrupt_file,
99 "DBI type server substream not aligned.");
124 if (
auto EC = initializeSectionContributionData())
126 if (
auto EC = initializeSectionHeadersData(Pdb))
128 if (
auto EC = initializeSectionMapData())
130 if (
auto EC = initializeFpoRecords(Pdb))
134 return make_error<RawError>(raw_error_code::corrupt_file,
135 "Found unexpected bytes in DBI Stream.");
137 if (!ECSubstream.
empty()) {
139 if (
auto EC = ECNames.
reload(ECReader))
201 return SectionHeaders;
216 if (!SectionContribs.empty()) {
218 for (
auto &
SC : SectionContribs)
220 }
else if (!SectionContribs2.empty()) {
222 for (
auto &
SC : SectionContribs2)
231 Error DbiStream::initializeSectionContributionData() {
232 if (SecContrSubstream.
empty())
236 if (
auto EC = SCReader.
readEnum(SectionContribVersion))
240 return loadSectionContribs<SectionContrib>(SectionContribs, SCReader);
242 return loadSectionContribs<SectionContrib2>(SectionContribs2, SCReader);
245 "Unsupported DBI Section Contribution version");
253 if (DbgStreams.size() == 0)
263 auto SHS = MappedBlockStream::createIndexedStream(
266 size_t StreamLen = SHS->getLength();
269 "Corrupted section header stream.");
273 if (
auto EC = Reader.
readArray(SectionHeaders, NumSections))
274 return make_error<RawError>(raw_error_code::corrupt_file,
275 "Could not read a bitmap.");
277 SectionHeaderStream = std::move(SHS);
286 if (DbgStreams.size() == 0)
298 auto FS = MappedBlockStream::createIndexedStream(
301 size_t StreamLen = FS->getLength();
304 "Corrupted New FPO stream.");
308 if (
auto EC = Reader.
readArray(FpoRecords, NumRecords))
309 return make_error<RawError>(raw_error_code::corrupt_file,
310 "Corrupted New FPO stream.");
311 FpoStream = std::move(FS);
316 return SecContrSubstream;
320 return SecMapSubstream;
324 return ModiSubstream;
328 return FileInfoSubstream;
332 return TypeServerMapSubstream;
337 Error DbiStream::initializeSectionMapData() {
338 if (SecMapSubstream.
empty())
351 uint16_t
T =
static_cast<uint16_t
>(
Type);
352 if (T >= DbgStreams.size())
354 return DbgStreams[
T];
virtual void visit(const SectionContrib &C)=0
Error readSubstream(BinarySubstreamRef &Stream, uint32_t Size)
Read Length bytes from the underlying stream into Stream.
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)
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
uint32_t getNumStreams() const override
BinarySubstreamRef getSectionContributionData() const
FixedStreamArray< object::FpoData > getFpoRecords()
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
BinaryStreamRef getMsfBuffer() const
COFF::MachineTypes Machine
BinarySubstreamRef getTypeServerMapSubstreamData() const
const uint16_t kInvalidStreamIndex
BumpPtrAllocator & getAllocator()
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
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
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())
const msf::MSFLayout & getMsfLayout() const
LLVM Value Representation.
Lightweight error class with error context and mandatory checking.
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 ...