30 using namespace llvm::codeview;
31 using namespace llvm::msf;
32 using namespace llvm::pdb;
33 using namespace llvm::support;
35 template <
typename ContribType>
39 return make_error<RawError>(
40 raw_error_code::corrupt_file,
41 "Invalid number of bytes of section contributions");
49 DbiStream::DbiStream(
PDBFile &
File, std::unique_ptr<MappedBlockStream> Stream)
50 :
Pdb(File), Stream(std::move(Stream)), Header(nullptr) {}
59 "DBI Stream does not contain a header.");
61 return make_error<RawError>(raw_error_code::corrupt_file,
62 "DBI Stream does not contain a header.");
66 "Invalid DBI version signature.");
73 "Unsupported DBI version.");
75 if (Stream->getLength() !=
81 "DBI Length does not equal sum of substreams.");
86 return make_error<RawError>(raw_error_code::corrupt_file,
87 "DBI MODI substream not aligned.");
89 return make_error<RawError>(
90 raw_error_code::corrupt_file,
91 "DBI section contribution substream not aligned.");
93 return make_error<RawError>(raw_error_code::corrupt_file,
94 "DBI section map substream not aligned.");
96 return make_error<RawError>(raw_error_code::corrupt_file,
97 "DBI file info substream not aligned.");
99 return make_error<RawError>(raw_error_code::corrupt_file,
100 "DBI type server substream not aligned.");
125 if (
auto EC = initializeSectionContributionData())
127 if (
auto EC = initializeSectionHeadersData())
129 if (
auto EC = initializeSectionMapData())
131 if (
auto EC = initializeFpoRecords())
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;
217 if (!SectionContribs.empty()) {
219 for (
auto &
SC : SectionContribs)
221 }
else if (!SectionContribs2.empty()) {
223 for (
auto &
SC : SectionContribs2)
232 Error DbiStream::initializeSectionContributionData() {
233 if (SecContrSubstream.
empty())
237 if (
auto EC = SCReader.readEnum(SectionContribVersion))
241 return loadSectionContribs<SectionContrib>(SectionContribs, SCReader);
243 return loadSectionContribs<SectionContrib2>(SectionContribs2, SCReader);
246 "Unsupported DBI Section Contribution version");
250 Error DbiStream::initializeSectionHeadersData() {
251 if (DbgStreams.
size() == 0)
261 auto SHS = MappedBlockStream::createIndexedStream(
264 size_t StreamLen = SHS->getLength();
267 "Corrupted section header stream.");
271 if (
auto EC = Reader.readArray(SectionHeaders, NumSections))
272 return make_error<RawError>(raw_error_code::corrupt_file,
273 "Could not read a bitmap.");
275 SectionHeaderStream = std::move(SHS);
280 Error DbiStream::initializeFpoRecords() {
281 if (DbgStreams.
size() == 0)
293 auto FS = MappedBlockStream::createIndexedStream(
296 size_t StreamLen =
FS->getLength();
299 "Corrupted New FPO stream.");
303 if (
auto EC = Reader.readArray(FpoRecords, NumRecords))
304 return make_error<RawError>(raw_error_code::corrupt_file,
305 "Corrupted New FPO stream.");
306 FpoStream = std::move(FS);
311 return SecContrSubstream;
315 return SecMapSubstream;
319 return ModiSubstream;
323 return FileInfoSubstream;
327 return TypeServerMapSubstream;
332 Error DbiStream::initializeSectionMapData() {
333 if (SecMapSubstream.
empty())
338 if (
auto EC = SMReader.readObject(Header))
340 if (
auto EC = SMReader.readArray(SectionMap, Header->
SecCount))
346 uint16_t
T =
static_cast<uint16_t
>(
Type);
347 if (T >= DbgStreams.
size())
349 return DbgStreams[
T];
virtual void visit(const SectionContrib &C)=0
void visitSectionContributions(ISectionContribVisitor &Visitor) const
Expected< StringRef > getStringForID(uint32_t ID) const
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)
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...
uint16_t getPublicSymbolStreamIndex() const
Error reload(BinaryStreamReader &Reader)
uint16_t getGlobalSymbolStreamIndex() const
FixedStreamArray is similar to VarStreamArray, except with each record having a fixed-length.
uint32_t getPdbDllVersion() const
uint32_t getNumStreams() const override
bool isIncrementallyLinked() const
uint16_t getBuildMajorVersion() const
FixedStreamArray< object::FpoData > getFpoRecords()
Tagged union holding either a T or a Error.
FixedStreamArray< object::coff_section > getSectionHeaders()
const DbiModuleList & modules() const
const uint16_t kInvalidStreamIndex
BumpPtrAllocator & getAllocator()
uint16_t getFlags() const
uint32_t bytesRemaining() const
static const uint16_t BuildMajorShift
The instances of the Type class are immutable: once they are created, they are never changed...
uint16_t getBuildNumber() const
PDB_Machine getMachineType() const
BinarySubstreamRef getFileInfoSubstreamData() const
Error initialize(BinaryStreamRef ModInfo, BinaryStreamRef FileInfo)
const msf::MSFLayout & getMsfLayout() const
FixedStreamArray< SecMapEntry > getSectionMap() const
BinaryStreamRef StreamData
uint32_t getSymRecordStreamIndex() 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.
BinarySubstreamRef getSectionContributionData() const
CHAIN = SC CHAIN, Imm128 - System call.
BinarySubstreamRef getTypeServerMapSubstreamData() const
uint16_t getPdbDllRbld() const
static const uint16_t FlagStrippedMask
uint32_t getDebugStreamIndex(DbgHeaderType Type) const
If the given stream type is present, returns its stream index.
BinarySubstreamRef getModiSubstreamData() const
PdbRaw_DbiVer getDbiVersion() const
uint16_t getBuildMinorVersion() const
BinaryStreamRef getMsfBuffer() const
static const uint16_t BuildMajorMask
static const uint16_t BuildMinorShift
Expected< StringRef > getECName(uint32_t NI) const
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM Value Representation.
Lightweight error class with error context and mandatory checking.
Provides read only access to a subclass of BinaryStream.
BinarySubstreamRef getECSubstreamData() 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 ...
BinarySubstreamRef getSecMapSubstreamData() const