LLVM: lib/DebugInfo/PDB/Native/DbiStream.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
22#include
23#include
24
25using namespace llvm;
30
31template
34 if (Reader.bytesRemaining() % sizeof(ContribType) != 0)
37 "Invalid number of bytes of section contributions");
38
41 return EC;
43}
44
46 : Stream(std::move(Stream)), Header(nullptr) {}
47
49
52
55 "DBI Stream does not contain a header.");
58 "DBI Stream does not contain a header.");
59
60 if (Header->VersionSignature != -1)
62 "Invalid DBI version signature.");
63
64
65
66
67 if (Header->VersionHeader < PdbDbiV70)
69 "Unsupported DBI version.");
70
71 if (Stream->getLength() !=
73 Header->SecContrSubstreamSize + Header->SectionMapSize +
74 Header->FileInfoSize + Header->TypeServerSize +
75 Header->OptionalDbgHdrSize + Header->ECSubstreamSize)
77 "DBI Length does not equal sum of substreams.");
78
79
80
81 if (Header->ModiSubstreamSize % sizeof(uint32_t) != 0)
83 "DBI MODI substream not aligned.");
84 if (Header->SecContrSubstreamSize % sizeof(uint32_t) != 0)
87 "DBI section contribution substream not aligned.");
88 if (Header->SectionMapSize % sizeof(uint32_t) != 0)
90 "DBI section map substream not aligned.");
91 if (Header->FileInfoSize % sizeof(uint32_t) != 0)
93 "DBI file info substream not aligned.");
94 if (Header->TypeServerSize % sizeof(uint32_t) != 0)
96 "DBI type server substream not aligned.");
97
98 if (auto EC = Reader.readSubstream(ModiSubstream, Header->ModiSubstreamSize))
99 return EC;
100
102 Header->SecContrSubstreamSize))
103 return EC;
104 if (auto EC = Reader.readSubstream(SecMapSubstream, Header->SectionMapSize))
105 return EC;
106 if (auto EC = Reader.readSubstream(FileInfoSubstream, Header->FileInfoSize))
107 return EC;
108 if (auto EC =
109 Reader.readSubstream(TypeServerMapSubstream, Header->TypeServerSize))
110 return EC;
111 if (auto EC = Reader.readSubstream(ECSubstream, Header->ECSubstreamSize))
112 return EC;
114 DbgStreams, Header->OptionalDbgHdrSize / sizeof(ulittle16_t)))
115 return EC;
116
117 if (auto EC = Modules.initialize(ModiSubstream.StreamData,
118 FileInfoSubstream.StreamData))
119 return EC;
120
121 if (auto EC = initializeSectionContributionData())
122 return EC;
123 if (auto EC = initializeSectionHeadersData(Pdb))
124 return EC;
125 if (auto EC = initializeSectionMapData())
126 return EC;
127 if (auto EC = initializeOldFpoRecords(Pdb))
128 return EC;
129 if (auto EC = initializeNewFpoRecords(Pdb))
130 return EC;
131
134 "Found unexpected bytes in DBI Stream.");
135
136 if (!ECSubstream.empty()) {
138 if (auto EC = ECNames.reload(ECReader))
139 return EC;
140 }
141
143}
144
149
151
153 return Header->PublicSymbolStreamIndex;
154}
155
157 return Header->GlobalSymbolStreamIndex;
158}
159
161
165
169
173
175
180
185
187
189
191 return Header->SymRecordStreamIndex;
192}
193
198
200 return SectionHeaders;
201}
202
204
206 return OldFpoRecords;
207}
208
210
212 return NewFpoRecords;
213}
214
216
218 return SectionMap;
219}
220
223 if (!SectionContribs.empty()) {
225 for (auto &SC : SectionContribs)
226 Visitor.visit(SC);
227 } else if (!SectionContribs2.empty()) {
229 for (auto &SC : SectionContribs2)
230 Visitor.visit(SC);
231 }
232}
233
235 return ECNames.getStringForID(NI);
236}
237
238Error DbiStream::initializeSectionContributionData() {
239 if (SecContrSubstream.empty())
241
243 if (auto EC = SCReader.readEnum(SectionContribVersion))
244 return EC;
245
250
252 "Unsupported DBI Section Contribution version");
253}
254
255
256Error DbiStream::initializeSectionHeadersData(PDBFile *Pdb) {
259 if (auto EC = ExpectedStream.takeError())
260 return EC;
261
262 auto &SHS = *ExpectedStream;
263 if (!SHS)
265
266 size_t StreamLen = SHS->getLength();
269 "Corrupted section header stream.");
270
273 if (auto EC = Reader.readArray(SectionHeaders, NumSections))
275 "Could not read a bitmap.");
276
277 SectionHeaderStream = std::move(SHS);
279}
280
281
285 if (auto EC = ExpectedStream.takeError())
286 return EC;
287
288 auto &FS = *ExpectedStream;
289 if (!FS)
291
292 size_t StreamLen = FS->getLength();
295 "Corrupted Old FPO stream.");
296
299 if (auto EC = Reader.readArray(OldFpoRecords, NumRecords))
301 "Corrupted Old FPO stream.");
302 OldFpoStream = std::move(FS);
304}
305
307 Expected<std::unique_ptrmsf::MappedBlockStream> ExpectedStream =
309 if (auto EC = ExpectedStream.takeError())
310 return EC;
311
312 auto &FS = *ExpectedStream;
313 if (!FS)
315
316 if (auto EC = NewFpoRecords.initialize(*FS))
317 return EC;
318
319 NewFpoStream = std::move(FS);
321}
322
323Expected<std::unique_ptrmsf::MappedBlockStream>
324DbiStream::createIndexedStreamForHeaderType(PDBFile *Pdb,
326 if ()
327 return nullptr;
328
329 if (DbgStreams.empty())
330 return nullptr;
331
333
334
336 return nullptr;
337
338 return Pdb->safelyCreateIndexedStream(StreamNum);
339}
340
342 return SecContrSubstream;
343}
344
346 return SecMapSubstream;
347}
348
350 return ModiSubstream;
351}
352
354 return FileInfoSubstream;
355}
356
358 return TypeServerMapSubstream;
359}
360
362
363Error DbiStream::initializeSectionMapData() {
364 if (SecMapSubstream.empty())
366
369 if (auto EC = SMReader.readObject(Header))
370 return EC;
371 if (auto EC = SMReader.readArray(SectionMap, Header->SecCount))
372 return EC;
374}
375
378 if (T >= DbgStreams.size())
380 return DbgStreams[T];
381}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
Lightweight arrays that are backed by an arbitrary BinaryStream.
static Error loadSectionContribs(FixedStreamArray< ContribType > &Output, BinaryStreamReader &Reader)
Definition DbiStream.cpp:32
Function const char TargetMachine * Machine
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...
LLVM_ABI 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.
LLVM Value Representation.
LLVM_ABI Expected< StringRef > getECName(uint32_t NI) const
Definition DbiStream.cpp:234
LLVM_ABI BinarySubstreamRef getSecMapSubstreamData() const
Definition DbiStream.cpp:345
LLVM_ABI PDB_Machine getMachineType() const
Definition DbiStream.cpp:194
LLVM_ABI BinarySubstreamRef getFileInfoSubstreamData() const
Definition DbiStream.cpp:353
LLVM_ABI void visitSectionContributions(ISectionContribVisitor &Visitor) const
Definition DbiStream.cpp:221
LLVM_ABI uint32_t getAge() const
Definition DbiStream.cpp:150
LLVM_ABI bool isIncrementallyLinked() const
Definition DbiStream.cpp:162
LLVM_ABI uint16_t getFlags() const
Definition DbiStream.cpp:160
LLVM_ABI PdbRaw_DbiVer getDbiVersion() const
Definition DbiStream.cpp:145
LLVM_ABI bool isStripped() const
Definition DbiStream.cpp:170
LLVM_ABI bool hasNewFpoRecords() const
Definition DbiStream.cpp:209
LLVM_ABI uint16_t getBuildMajorVersion() const
Definition DbiStream.cpp:176
LLVM_ABI FixedStreamArray< object::coff_section > getSectionHeaders() const
Definition DbiStream.cpp:199
LLVM_ABI uint16_t getGlobalSymbolStreamIndex() const
Definition DbiStream.cpp:156
LLVM_ABI DbiStream(std::unique_ptr< BinaryStream > Stream)
Definition DbiStream.cpp:45
LLVM_ABI Error reload(PDBFile *Pdb)
Definition DbiStream.cpp:50
LLVM_ABI BinarySubstreamRef getTypeServerMapSubstreamData() const
Definition DbiStream.cpp:357
LLVM_ABI BinarySubstreamRef getModiSubstreamData() const
Definition DbiStream.cpp:349
LLVM_ABI const DbiModuleList & modules() const
Definition DbiStream.cpp:215
LLVM_ABI uint16_t getBuildNumber() const
Definition DbiStream.cpp:174
LLVM_ABI const codeview::DebugFrameDataSubsectionRef & getNewFpoRecords() const
Definition DbiStream.cpp:211
LLVM_ABI uint16_t getBuildMinorVersion() const
Definition DbiStream.cpp:181
LLVM_ABI uint32_t getDebugStreamIndex(DbgHeaderType Type) const
If the given stream type is present, returns its stream index.
Definition DbiStream.cpp:376
LLVM_ABI FixedStreamArray< object::FpoData > getOldFpoRecords() const
Definition DbiStream.cpp:205
LLVM_ABI uint32_t getPdbDllVersion() const
Definition DbiStream.cpp:188
LLVM_ABI uint32_t getSymRecordStreamIndex() const
Definition DbiStream.cpp:190
LLVM_ABI uint16_t getPublicSymbolStreamIndex() const
Definition DbiStream.cpp:152
LLVM_ABI BinarySubstreamRef getECSubstreamData() const
Definition DbiStream.cpp:361
LLVM_ABI bool hasCTypes() const
Definition DbiStream.cpp:166
LLVM_ABI uint16_t getPdbDllRbld() const
Definition DbiStream.cpp:186
LLVM_ABI FixedStreamArray< SecMapEntry > getSectionMap() const
Definition DbiStream.cpp:217
LLVM_ABI BinarySubstreamRef getSectionContributionData() const
Definition DbiStream.cpp:341
LLVM_ABI bool hasOldFpoRecords() const
Definition DbiStream.cpp:203
virtual void visit(const SectionContrib &C)=0
const uint16_t kInvalidStreamIndex
detail::packed_endian_specific_integral< uint16_t, llvm::endianness::little, unaligned > ulittle16_t
This is an optimization pass for GlobalISel generic memory operations.
FunctionAddr VTableAddr Count
Error make_error(ArgTs &&... Args)
Make a Error instance representing failure using the given error info type.
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