[llvm] r365936 - Slightly simplify MappedBlockStream::createIndexedStream() calls
Nico Weber via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 12 11:24:38 PDT 2019
Author: nico
Date: Fri Jul 12 11:24:38 2019
New Revision: 365936
URL: http://llvm.org/viewvc/llvm-project?rev=365936&view=rev
Log:
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
Modified:
llvm/trunk/include/llvm/DebugInfo/PDB/Native/PDBFile.h
llvm/trunk/lib/DebugInfo/PDB/Native/DbiStream.cpp
llvm/trunk/lib/DebugInfo/PDB/Native/PDBFile.cpp
llvm/trunk/lib/DebugInfo/PDB/Native/TpiStream.cpp
llvm/trunk/tools/llvm-pdbutil/BytesOutputStyle.cpp
llvm/trunk/tools/llvm-pdbutil/LinePrinter.cpp
llvm/trunk/tools/llvm-pdbutil/YAMLOutputStyle.cpp
llvm/trunk/tools/llvm-pdbutil/llvm-pdbutil.cpp
Modified: llvm/trunk/include/llvm/DebugInfo/PDB/Native/PDBFile.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/PDB/Native/PDBFile.h?rev=365936&r1=365935&r2=365936&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/PDB/Native/PDBFile.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/PDB/Native/PDBFile.h Fri Jul 12 11:24:38 2019
@@ -83,7 +83,10 @@ public:
ArrayRef<support::ulittle32_t> getDirectoryBlockArray() const;
- std::unique_ptr<msf::MappedBlockStream> createIndexedStream(uint16_t SN);
+ std::unique_ptr<msf::MappedBlockStream>
+ createIndexedStream(uint16_t SN) const;
+ Expected<std::unique_ptr<msf::MappedBlockStream>>
+ safelyCreateIndexedStream(uint32_t StreamIndex) const;
msf::MSFStreamLayout getStreamLayout(uint32_t StreamIdx) const;
msf::MSFStreamLayout getFpmStreamLayout() const;
@@ -114,11 +117,6 @@ public:
uint32_t getPointerSize();
private:
- Expected<std::unique_ptr<msf::MappedBlockStream>>
- safelyCreateIndexedStream(const msf::MSFLayout &Layout,
- BinaryStreamRef MsfData,
- uint32_t StreamIndex) const;
-
std::string FilePath;
BumpPtrAllocator &Allocator;
Modified: llvm/trunk/lib/DebugInfo/PDB/Native/DbiStream.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/PDB/Native/DbiStream.cpp?rev=365936&r1=365935&r2=365936&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/PDB/Native/DbiStream.cpp (original)
+++ llvm/trunk/lib/DebugInfo/PDB/Native/DbiStream.cpp Fri Jul 12 11:24:38 2019
@@ -333,15 +333,11 @@ DbiStream::createIndexedStreamForHeaderT
uint32_t StreamNum = getDebugStreamIndex(Type);
- // This means there is no such stream
+ // This means there is no such stream.
if (StreamNum == kInvalidStreamIndex)
return nullptr;
- if (StreamNum >= Pdb->getNumStreams())
- return make_error<RawError>(raw_error_code::no_stream);
-
- return MappedBlockStream::createIndexedStream(
- Pdb->getMsfLayout(), Pdb->getMsfBuffer(), StreamNum, Pdb->getAllocator());
+ return Pdb->safelyCreateIndexedStream(StreamNum);
}
BinarySubstreamRef DbiStream::getSectionContributionData() const {
Modified: llvm/trunk/lib/DebugInfo/PDB/Native/PDBFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/PDB/Native/PDBFile.cpp?rev=365936&r1=365935&r2=365936&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/PDB/Native/PDBFile.cpp (original)
+++ llvm/trunk/lib/DebugInfo/PDB/Native/PDBFile.cpp Fri Jul 12 11:24:38 2019
@@ -233,7 +233,8 @@ ArrayRef<support::ulittle32_t> PDBFile::
return ContainerLayout.DirectoryBlocks;
}
-std::unique_ptr<MappedBlockStream> PDBFile::createIndexedStream(uint16_t SN) {
+std::unique_ptr<MappedBlockStream>
+PDBFile::createIndexedStream(uint16_t SN) const {
if (SN == kInvalidStreamIndex)
return nullptr;
return MappedBlockStream::createIndexedStream(ContainerLayout, *Buffer, SN,
@@ -258,8 +259,8 @@ Expected<GlobalsStream &> PDBFile::getPD
if (!DbiS)
return DbiS.takeError();
- auto GlobalS = safelyCreateIndexedStream(
- ContainerLayout, *Buffer, DbiS->getGlobalSymbolStreamIndex());
+ auto GlobalS =
+ safelyCreateIndexedStream(DbiS->getGlobalSymbolStreamIndex());
if (!GlobalS)
return GlobalS.takeError();
auto TempGlobals = llvm::make_unique<GlobalsStream>(std::move(*GlobalS));
@@ -272,7 +273,7 @@ Expected<GlobalsStream &> PDBFile::getPD
Expected<InfoStream &> PDBFile::getPDBInfoStream() {
if (!Info) {
- auto InfoS = safelyCreateIndexedStream(ContainerLayout, *Buffer, StreamPDB);
+ auto InfoS = safelyCreateIndexedStream(StreamPDB);
if (!InfoS)
return InfoS.takeError();
auto TempInfo = llvm::make_unique<InfoStream>(std::move(*InfoS));
@@ -285,7 +286,7 @@ Expected<InfoStream &> PDBFile::getPDBIn
Expected<DbiStream &> PDBFile::getPDBDbiStream() {
if (!Dbi) {
- auto DbiS = safelyCreateIndexedStream(ContainerLayout, *Buffer, StreamDBI);
+ auto DbiS = safelyCreateIndexedStream(StreamDBI);
if (!DbiS)
return DbiS.takeError();
auto TempDbi = llvm::make_unique<DbiStream>(std::move(*DbiS));
@@ -298,7 +299,7 @@ Expected<DbiStream &> PDBFile::getPDBDbi
Expected<TpiStream &> PDBFile::getPDBTpiStream() {
if (!Tpi) {
- auto TpiS = safelyCreateIndexedStream(ContainerLayout, *Buffer, StreamTPI);
+ auto TpiS = safelyCreateIndexedStream(StreamTPI);
if (!TpiS)
return TpiS.takeError();
auto TempTpi = llvm::make_unique<TpiStream>(*this, std::move(*TpiS));
@@ -314,7 +315,7 @@ Expected<TpiStream &> PDBFile::getPDBIpi
if (!hasPDBIpiStream())
return make_error<RawError>(raw_error_code::no_stream);
- auto IpiS = safelyCreateIndexedStream(ContainerLayout, *Buffer, StreamIPI);
+ auto IpiS = safelyCreateIndexedStream(StreamIPI);
if (!IpiS)
return IpiS.takeError();
auto TempIpi = llvm::make_unique<TpiStream>(*this, std::move(*IpiS));
@@ -331,8 +332,8 @@ Expected<PublicsStream &> PDBFile::getPD
if (!DbiS)
return DbiS.takeError();
- auto PublicS = safelyCreateIndexedStream(
- ContainerLayout, *Buffer, DbiS->getPublicSymbolStreamIndex());
+ auto PublicS =
+ safelyCreateIndexedStream(DbiS->getPublicSymbolStreamIndex());
if (!PublicS)
return PublicS.takeError();
auto TempPublics = llvm::make_unique<PublicsStream>(std::move(*PublicS));
@@ -350,8 +351,7 @@ Expected<SymbolStream &> PDBFile::getPDB
return DbiS.takeError();
uint32_t SymbolStreamNum = DbiS->getSymRecordStreamIndex();
- auto SymbolS =
- safelyCreateIndexedStream(ContainerLayout, *Buffer, SymbolStreamNum);
+ auto SymbolS = safelyCreateIndexedStream(SymbolStreamNum);
if (!SymbolS)
return SymbolS.takeError();
@@ -374,8 +374,7 @@ Expected<PDBStringTable &> PDBFile::getS
return ExpectedNSI.takeError();
uint32_t NameStreamIndex = *ExpectedNSI;
- auto NS =
- safelyCreateIndexedStream(ContainerLayout, *Buffer, NameStreamIndex);
+ auto NS = safelyCreateIndexedStream(NameStreamIndex);
if (!NS)
return NS.takeError();
@@ -463,11 +462,9 @@ bool PDBFile::hasPDBStringTable() {
/// will have an MSFError with code msf_error_code::no_stream. Else, the return
/// value will contain the stream returned by createIndexedStream().
Expected<std::unique_ptr<MappedBlockStream>>
-PDBFile::safelyCreateIndexedStream(const MSFLayout &Layout,
- BinaryStreamRef MsfData,
- uint32_t StreamIndex) const {
+PDBFile::safelyCreateIndexedStream(uint32_t StreamIndex) const {
if (StreamIndex >= getNumStreams())
+ // This rejects kInvalidStreamIndex with an error as well.
return make_error<RawError>(raw_error_code::no_stream);
- return MappedBlockStream::createIndexedStream(Layout, MsfData, StreamIndex,
- Allocator);
+ return createIndexedStream(StreamIndex);
}
Modified: llvm/trunk/lib/DebugInfo/PDB/Native/TpiStream.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/PDB/Native/TpiStream.cpp?rev=365936&r1=365935&r2=365936&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/PDB/Native/TpiStream.cpp (original)
+++ llvm/trunk/lib/DebugInfo/PDB/Native/TpiStream.cpp Fri Jul 12 11:24:38 2019
@@ -78,14 +78,13 @@ Error TpiStream::reload() {
// Hash indices, hash values, etc come from the hash stream.
if (Header->HashStreamIndex != kInvalidStreamIndex) {
- if (Header->HashStreamIndex >= Pdb.getNumStreams())
+ auto HS = Pdb.safelyCreateIndexedStream(Header->HashStreamIndex);
+ if (!HS) {
+ consumeError(HS.takeError());
return make_error<RawError>(raw_error_code::corrupt_file,
"Invalid TPI hash stream index.");
-
- auto HS = MappedBlockStream::createIndexedStream(
- Pdb.getMsfLayout(), Pdb.getMsfBuffer(), Header->HashStreamIndex,
- Pdb.getAllocator());
- BinaryStreamReader HSR(*HS);
+ }
+ BinaryStreamReader HSR(**HS);
// There should be a hash value for every type record, or no hashes at all.
uint32_t NumHashValues =
@@ -110,7 +109,7 @@ Error TpiStream::reload() {
return EC;
}
- HashStream = std::move(HS);
+ HashStream = std::move(*HS);
}
Types = llvm::make_unique<LazyRandomTypeCollection>(
Modified: llvm/trunk/tools/llvm-pdbutil/BytesOutputStyle.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-pdbutil/BytesOutputStyle.cpp?rev=365936&r1=365935&r2=365936&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-pdbutil/BytesOutputStyle.cpp (original)
+++ llvm/trunk/tools/llvm-pdbutil/BytesOutputStyle.cpp Fri Jul 12 11:24:38 2019
@@ -340,9 +340,7 @@ static void iterateOneModule(PDBFile &Fi
if (ModiStream == kInvalidStreamIndex)
return;
- auto ModStreamData = MappedBlockStream::createIndexedStream(
- File.getMsfLayout(), File.getMsfBuffer(), ModiStream,
- File.getAllocator());
+ auto ModStreamData = File.createIndexedStream(ModiStream);
ModuleDebugStreamRef ModStream(Modi, std::move(ModStreamData));
if (auto EC = ModStream.reload()) {
P.formatLine("Could not parse debug information.");
Modified: llvm/trunk/tools/llvm-pdbutil/LinePrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-pdbutil/LinePrinter.cpp?rev=365936&r1=365935&r2=365936&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-pdbutil/LinePrinter.cpp (original)
+++ llvm/trunk/tools/llvm-pdbutil/LinePrinter.cpp Fri Jul 12 11:24:38 2019
@@ -186,8 +186,7 @@ void LinePrinter::formatMsfStreamData(St
return;
}
- auto S = MappedBlockStream::createIndexedStream(
- File.getMsfLayout(), File.getMsfBuffer(), StreamIdx, File.getAllocator());
+ auto S = File.createIndexedStream(StreamIdx);
if (!S) {
NewLine();
formatLine("Stream {0}: Not present", StreamIdx);
Modified: llvm/trunk/tools/llvm-pdbutil/YAMLOutputStyle.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-pdbutil/YAMLOutputStyle.cpp?rev=365936&r1=365935&r2=365936&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-pdbutil/YAMLOutputStyle.cpp (original)
+++ llvm/trunk/tools/llvm-pdbutil/YAMLOutputStyle.cpp Fri Jul 12 11:24:38 2019
@@ -231,10 +231,7 @@ Error YAMLOutputStyle::dumpDbiStream() {
if (ModiStream == kInvalidStreamIndex)
continue;
- auto ModStreamData = msf::MappedBlockStream::createIndexedStream(
- File.getMsfLayout(), File.getMsfBuffer(), ModiStream,
- File.getAllocator());
-
+ auto ModStreamData = File.createIndexedStream(ModiStream);
pdb::ModuleDebugStreamRef ModS(MI, std::move(ModStreamData));
if (auto EC = ModS.reload())
return EC;
Modified: llvm/trunk/tools/llvm-pdbutil/llvm-pdbutil.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-pdbutil/llvm-pdbutil.cpp?rev=365936&r1=365935&r2=365936&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-pdbutil/llvm-pdbutil.cpp (original)
+++ llvm/trunk/tools/llvm-pdbutil/llvm-pdbutil.cpp Fri Jul 12 11:24:38 2019
@@ -1384,8 +1384,7 @@ static void exportStream() {
<< "' (index " << Index << ") to file " << OutFileName << ".\n";
}
- SourceStream = MappedBlockStream::createIndexedStream(
- File.getMsfLayout(), File.getMsfBuffer(), Index, File.getAllocator());
+ SourceStream = File.createIndexedStream(Index);
auto OutFile = ExitOnErr(
FileOutputBuffer::create(OutFileName, SourceStream->getLength()));
FileBufferByteStream DestStream(std::move(OutFile), llvm::support::little);
More information about the llvm-commits
mailing list