31 using namespace llvm::codeview;
32 using namespace llvm::msf;
33 using namespace llvm::pdb;
34 using namespace llvm::support;
36 template <
typename ContribType>
40 return make_error<RawError>(
41 raw_error_code::corrupt_file,
42 "Invalid number of bytes of section contributions");
50 DbiStream::DbiStream(
PDBFile &
File, std::unique_ptr<MappedBlockStream> Stream)
51 : Pdb(File), Stream(std::move(Stream)), Header(nullptr) {
61 "DBI Stream does not contain a header.");
63 return make_error<RawError>(raw_error_code::corrupt_file,
64 "DBI Stream does not contain a header.");
68 "Invalid DBI version signature.");
75 "Unsupported DBI version.");
79 return IS.takeError();
81 if (Header->
Age != IS->getAge())
82 return make_error<RawError>(raw_error_code::corrupt_file,
83 "DBI Age does not match PDB Age.");
85 if (Stream->getLength() !=
91 "DBI Length does not equal sum of substreams.");
96 return make_error<RawError>(raw_error_code::corrupt_file,
97 "DBI MODI substream not aligned.");
99 return make_error<RawError>(
100 raw_error_code::corrupt_file,
101 "DBI section contribution substream not aligned.");
103 return make_error<RawError>(raw_error_code::corrupt_file,
104 "DBI section map substream not aligned.");
106 return make_error<RawError>(raw_error_code::corrupt_file,
107 "DBI file info substream not aligned.");
109 return make_error<RawError>(raw_error_code::corrupt_file,
110 "DBI type server substream not aligned.");
115 if (
auto EC = initializeModInfoArray())
134 if (
auto EC = initializeSectionContributionData())
136 if (
auto EC = initializeSectionHeadersData())
138 if (
auto EC = initializeSectionMapData())
140 if (
auto EC = initializeFileInfo())
142 if (
auto EC = initializeFpoRecords())
146 return make_error<RawError>(raw_error_code::corrupt_file,
147 "Found unexpected bytes in DBI Stream.");
151 if (
auto EC = ECNames.
load(ECReader))
213 return SectionHeaders;
228 for (
auto &
SC : SectionContribs)
231 for (
auto &
SC : SectionContribs2)
236 Error DbiStream::initializeSectionContributionData() {
241 if (
auto EC = SCReader.readEnum(SectionContribVersion))
245 return loadSectionContribs<SectionContrib>(SectionContribs, SCReader);
247 return loadSectionContribs<SectionContrib2>(SectionContribs2, SCReader);
250 "Unsupported DBI Section Contribution version");
253 Error DbiStream::initializeModInfoArray() {
262 if (
auto EC = Reader.readArray(ModInfoArray, ModInfoSubstream.
getLength()))
264 for (
auto &Info : ModInfoArray) {
265 ModuleInfos.emplace_back(Info);
272 Error DbiStream::initializeSectionHeadersData() {
273 if (DbgStreams.
size() == 0)
280 auto SHS = MappedBlockStream::createIndexedStream(
283 size_t StreamLen = SHS->getLength();
286 "Corrupted section header stream.");
290 if (
auto EC = Reader.readArray(SectionHeaders, NumSections))
291 return make_error<RawError>(raw_error_code::corrupt_file,
292 "Could not read a bitmap.");
294 SectionHeaderStream = std::move(SHS);
299 Error DbiStream::initializeFpoRecords() {
300 if (DbgStreams.
size() == 0)
312 auto FS = MappedBlockStream::createIndexedStream(
315 size_t StreamLen =
FS->getLength();
318 "Corrupted New FPO stream.");
322 if (
auto EC = Reader.readArray(FpoRecords, NumRecords))
323 return make_error<RawError>(raw_error_code::corrupt_file,
324 "Corrupted New FPO stream.");
325 FpoStream = std::move(FS);
329 Error DbiStream::initializeSectionMapData() {
335 if (
auto EC = SMReader.readObject(Header))
337 if (
auto EC = SMReader.readArray(SectionMap, Header->
SecCount))
342 Error DbiStream::initializeFileInfo() {
348 if (
auto EC = FISR.readObject(FH))
354 return make_error<RawError>(raw_error_code::corrupt_file,
355 "FileInfo substream count doesn't match DBI.");
365 if (
auto EC = FISR.readArray(ModIndexArray, ModuleInfos.size()))
367 if (
auto EC = FISR.readArray(ModFileCountArray, ModuleInfos.size()))
372 for (
auto Count : ModFileCountArray)
373 NumSourceFiles += Count;
383 if (
auto EC = FISR.readArray(FileNameOffsets, NumSourceFiles))
386 if (
auto EC = FISR.readStreamRef(NamesBuffer))
394 for (
size_t I = 0;
I < ModuleInfos.size(); ++
I) {
395 uint32_t NumFiles = ModFileCountArray[
I];
396 ModuleInfos[
I].SourceFiles.resize(NumFiles);
397 for (
size_t J = 0; J < NumFiles; ++J, ++NextFileIndex) {
400 return ThisName.takeError();
401 ModuleInfos[
I].SourceFiles[J] = *ThisName;
409 uint16_t
T =
static_cast<uint16_t
>(
Type);
410 if (T >= DbgStreams.
size())
412 return DbgStreams[
T];
417 if (Index >= FileNameOffsets.
size())
420 uint32_t FileOffset = FileNameOffsets[Index];
424 return std::move(
EC);
virtual void visit(const SectionContrib &C)=0
void visitSectionContributions(ISectionContribVisitor &Visitor) const
static const uint16_t FlagHasCTypesMask
static const uint16_t BuildMinorMask
uint16_t MinorVersion : 8; uint16_t MajorVersion : 7; uint16_t NewVersionFormat : 1; ...
uint16_t getPublicSymbolStreamIndex() const
uint16_t getGlobalSymbolStreamIndex() const
void setOffset(uint32_t Off)
uint32_t getPdbDllVersion() const
uint32_t getNumStreams() const override
bool isIncrementallyLinked() const
uint16_t getBuildMajorVersion() const
Error readZeroString(StringRef &Dest)
Tagged union holding either a T or a Error.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
COFF::MachineTypes Machine
const uint16_t kInvalidStreamIndex
uint16_t getFlags() const
msf::FixedStreamArray< SecMapEntry > getSectionMap() const
static const uint16_t BuildMajorShift
uint32_t getLength() const
The instances of the Type class are immutable: once they are created, they are never changed...
uint16_t getBuildNumber() const
PDB_Machine getMachineType() const
Error readArray(ArrayRef< T > &Array, uint32_t NumElements)
Expected< StringRef > getFileNameForIndex(uint32_t Index) const
msf::FixedStreamArray< object::FpoData > getFpoRecords()
const msf::ReadableStream & getMsfBuffer() const
const msf::MSFLayout & getMsfLayout() const
ArrayRef< ModuleInfoEx > modules() const
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.
CHAIN = SC CHAIN, Imm128 - System call.
static Error loadSectionContribs(FixedStreamArray< ContribType > &Output, StreamReader &Reader)
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.
PdbRaw_DbiVer getDbiVersion() const
msf::FixedStreamArray< object::coff_section > getSectionHeaders()
uint16_t getBuildMinorVersion() const
Error load(msf::StreamReader &Stream)
static const uint16_t BuildMajorMask
Error readStreamRef(ReadableStreamRef &Ref)
static const uint16_t BuildMinorShift
uint32_t bytesRemaining() const
Expected< InfoStream & > getPDBInfoStream()
LLVM Value Representation.
Lightweight error class with error context and mandatory checking.
StringRef - Represent a constant reference to a string, i.e.
Error readObject(const T *&Dest)