llvm.org GIT mirror llvm / 1f1f02a
Slightly simplify MappedBlockStream::createIndexedStream() calls All callers had a PDBFile object at hand, so call Pdb.createIndexedStream() instead, which pre-populates all the arguments (and returns nullptr for kInvalidStreamIndex). Also change safelyCreateIndexedStream() to only take the string index, and update callers. Make the method public and call it in two places that manually did the bounds checking before. No intended behavior change. Differential Revision: https://reviews.llvm.org/D64633 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@365936 91177308-0d34-0410-b5e6-96231b3b80d8 Nico Weber a month ago
8 changed file(s) with 32 addition(s) and 49 deletion(s). Raw diff Collapse all Expand all
8282
8383 ArrayRef getDirectoryBlockArray() const;
8484
85 std::unique_ptr createIndexedStream(uint16_t SN);
85 std::unique_ptr
86 createIndexedStream(uint16_t SN) const;
87 Expected>
88 safelyCreateIndexedStream(uint32_t StreamIndex) const;
8689
8790 msf::MSFStreamLayout getStreamLayout(uint32_t StreamIdx) const;
8891 msf::MSFStreamLayout getFpmStreamLayout() const;
113116 uint32_t getPointerSize();
114117
115118 private:
116 Expected>
117 safelyCreateIndexedStream(const msf::MSFLayout &Layout,
118 BinaryStreamRef MsfData,
119 uint32_t StreamIndex) const;
120
121119 std::string FilePath;
122120 BumpPtrAllocator &Allocator;
123121
332332
333333 uint32_t StreamNum = getDebugStreamIndex(Type);
334334
335 // This means there is no such stream
335 // This means there is no such stream.
336336 if (StreamNum == kInvalidStreamIndex)
337337 return nullptr;
338338
339 if (StreamNum >= Pdb->getNumStreams())
340 return make_error(raw_error_code::no_stream);
341
342 return MappedBlockStream::createIndexedStream(
343 Pdb->getMsfLayout(), Pdb->getMsfBuffer(), StreamNum, Pdb->getAllocator());
339 return Pdb->safelyCreateIndexedStream(StreamNum);
344340 }
345341
346342 BinarySubstreamRef DbiStream::getSectionContributionData() const {
232232 return ContainerLayout.DirectoryBlocks;
233233 }
234234
235 std::unique_ptr PDBFile::createIndexedStream(uint16_t SN) {
235 std::unique_ptr
236 PDBFile::createIndexedStream(uint16_t SN) const {
236237 if (SN == kInvalidStreamIndex)
237238 return nullptr;
238239 return MappedBlockStream::createIndexedStream(ContainerLayout, *Buffer, SN,
257258 if (!DbiS)
258259 return DbiS.takeError();
259260
260 auto GlobalS = safelyCreateIndexedStream(
261 ContainerLayout, *Buffer, DbiS->getGlobalSymbolStreamIndex());
261 auto GlobalS =
262 safelyCreateIndexedStream(DbiS->getGlobalSymbolStreamIndex());
262263 if (!GlobalS)
263264 return GlobalS.takeError();
264265 auto TempGlobals = llvm::make_unique(std::move(*GlobalS));
271272
272273 Expected PDBFile::getPDBInfoStream() {
273274 if (!Info) {
274 auto InfoS = safelyCreateIndexedStream(ContainerLayout, *Buffer, StreamPDB);
275 auto InfoS = safelyCreateIndexedStream(StreamPDB);
275276 if (!InfoS)
276277 return InfoS.takeError();
277278 auto TempInfo = llvm::make_unique(std::move(*InfoS));
284285
285286 Expected PDBFile::getPDBDbiStream() {
286287 if (!Dbi) {
287 auto DbiS = safelyCreateIndexedStream(ContainerLayout, *Buffer, StreamDBI);
288 auto DbiS = safelyCreateIndexedStream(StreamDBI);
288289 if (!DbiS)
289290 return DbiS.takeError();
290291 auto TempDbi = llvm::make_unique(std::move(*DbiS));
297298
298299 Expected PDBFile::getPDBTpiStream() {
299300 if (!Tpi) {
300 auto TpiS = safelyCreateIndexedStream(ContainerLayout, *Buffer, StreamTPI);
301 auto TpiS = safelyCreateIndexedStream(StreamTPI);
301302 if (!TpiS)
302303 return TpiS.takeError();
303304 auto TempTpi = llvm::make_unique(*this, std::move(*TpiS));
313314 if (!hasPDBIpiStream())
314315 return make_error(raw_error_code::no_stream);
315316
316 auto IpiS = safelyCreateIndexedStream(ContainerLayout, *Buffer, StreamIPI);
317 auto IpiS = safelyCreateIndexedStream(StreamIPI);
317318 if (!IpiS)
318319 return IpiS.takeError();
319320 auto TempIpi = llvm::make_unique(*this, std::move(*IpiS));
330331 if (!DbiS)
331332 return DbiS.takeError();
332333
333 auto PublicS = safelyCreateIndexedStream(
334 ContainerLayout, *Buffer, DbiS->getPublicSymbolStreamIndex());
334 auto PublicS =
335 safelyCreateIndexedStream(DbiS->getPublicSymbolStreamIndex());
335336 if (!PublicS)
336337 return PublicS.takeError();
337338 auto TempPublics = llvm::make_unique(std::move(*PublicS));
349350 return DbiS.takeError();
350351
351352 uint32_t SymbolStreamNum = DbiS->getSymRecordStreamIndex();
352 auto SymbolS =
353 safelyCreateIndexedStream(ContainerLayout, *Buffer, SymbolStreamNum);
353 auto SymbolS = safelyCreateIndexedStream(SymbolStreamNum);
354354 if (!SymbolS)
355355 return SymbolS.takeError();
356356
373373 return ExpectedNSI.takeError();
374374 uint32_t NameStreamIndex = *ExpectedNSI;
375375
376 auto NS =
377 safelyCreateIndexedStream(ContainerLayout, *Buffer, NameStreamIndex);
376 auto NS = safelyCreateIndexedStream(NameStreamIndex);
378377 if (!NS)
379378 return NS.takeError();
380379
462461 /// will have an MSFError with code msf_error_code::no_stream. Else, the return
463462 /// value will contain the stream returned by createIndexedStream().
464463 Expected>
465 PDBFile::safelyCreateIndexedStream(const MSFLayout &Layout,
466 BinaryStreamRef MsfData,
467 uint32_t StreamIndex) const {
464 PDBFile::safelyCreateIndexedStream(uint32_t StreamIndex) const {
468465 if (StreamIndex >= getNumStreams())
466 // This rejects kInvalidStreamIndex with an error as well.
469467 return make_error(raw_error_code::no_stream);
470 return MappedBlockStream::createIndexedStream(Layout, MsfData, StreamIndex,
471 Allocator);
472 }
468 return createIndexedStream(StreamIndex);
469 }
7777
7878 // Hash indices, hash values, etc come from the hash stream.
7979 if (Header->HashStreamIndex != kInvalidStreamIndex) {
80 if (Header->HashStreamIndex >= Pdb.getNumStreams())
80 auto HS = Pdb.safelyCreateIndexedStream(Header->HashStreamIndex);
81 if (!HS) {
82 consumeError(HS.takeError());
8183 return make_error(raw_error_code::corrupt_file,
8284 "Invalid TPI hash stream index.");
83
84 auto HS = MappedBlockStream::createIndexedStream(
85 Pdb.getMsfLayout(), Pdb.getMsfBuffer(), Header->HashStreamIndex,
86 Pdb.getAllocator());
87 BinaryStreamReader HSR(*HS);
85 }
86 BinaryStreamReader HSR(**HS);
8887
8988 // There should be a hash value for every type record, or no hashes at all.
9089 uint32_t NumHashValues =
109108 return EC;
110109 }
111110
112 HashStream = std::move(HS);
111 HashStream = std::move(*HS);
113112 }
114113
115114 Types = llvm::make_unique(
339339 if (ModiStream == kInvalidStreamIndex)
340340 return;
341341
342 auto ModStreamData = MappedBlockStream::createIndexedStream(
343 File.getMsfLayout(), File.getMsfBuffer(), ModiStream,
344 File.getAllocator());
342 auto ModStreamData = File.createIndexedStream(ModiStream);
345343 ModuleDebugStreamRef ModStream(Modi, std::move(ModStreamData));
346344 if (auto EC = ModStream.reload()) {
347345 P.formatLine("Could not parse debug information.");
185185 return;
186186 }
187187
188 auto S = MappedBlockStream::createIndexedStream(
189 File.getMsfLayout(), File.getMsfBuffer(), StreamIdx, File.getAllocator());
188 auto S = File.createIndexedStream(StreamIdx);
190189 if (!S) {
191190 NewLine();
192191 formatLine("Stream {0}: Not present", StreamIdx);
230230 if (ModiStream == kInvalidStreamIndex)
231231 continue;
232232
233 auto ModStreamData = msf::MappedBlockStream::createIndexedStream(
234 File.getMsfLayout(), File.getMsfBuffer(), ModiStream,
235 File.getAllocator());
236
233 auto ModStreamData = File.createIndexedStream(ModiStream);
237234 pdb::ModuleDebugStreamRef ModS(MI, std::move(ModStreamData));
238235 if (auto EC = ModS.reload())
239236 return EC;
13831383 << "' (index " << Index << ") to file " << OutFileName << ".\n";
13841384 }
13851385
1386 SourceStream = MappedBlockStream::createIndexedStream(
1387 File.getMsfLayout(), File.getMsfBuffer(), Index, File.getAllocator());
1386 SourceStream = File.createIndexedStream(Index);
13881387 auto OutFile = ExitOnErr(
13891388 FileOutputBuffer::create(OutFileName, SourceStream->getLength()));
13901389 FileBufferByteStream DestStream(std::move(OutFile), llvm::support::little);