[llvm] r275009 - [llvm-pdbdump] Propagate errors a little more consistently
David Majnemer via llvm-commits
llvm-commits at lists.llvm.org
Sat Jul 9 20:34:47 PDT 2016
Author: majnemer
Date: Sat Jul 9 22:34:47 2016
New Revision: 275009
URL: http://llvm.org/viewvc/llvm-project?rev=275009&view=rev
Log:
[llvm-pdbdump] Propagate errors a little more consistently
PDBFile::getBlockData didn't really return any indication that it
failed. It merely returned an empty buffer.
Modified:
llvm/trunk/include/llvm/DebugInfo/CodeView/StreamRef.h
llvm/trunk/include/llvm/DebugInfo/PDB/Raw/IPDBFile.h
llvm/trunk/include/llvm/DebugInfo/PDB/Raw/PDBFile.h
llvm/trunk/lib/DebugInfo/PDB/Raw/MappedBlockStream.cpp
llvm/trunk/lib/DebugInfo/PDB/Raw/PDBFile.cpp
llvm/trunk/unittests/DebugInfo/PDB/MappedBlockStreamTest.cpp
Modified: llvm/trunk/include/llvm/DebugInfo/CodeView/StreamRef.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/CodeView/StreamRef.h?rev=275009&r1=275008&r2=275009&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/CodeView/StreamRef.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/CodeView/StreamRef.h Sat Jul 9 22:34:47 2016
@@ -29,6 +29,8 @@ public:
Error readBytes(uint32_t Offset, uint32_t Size,
ArrayRef<uint8_t> &Buffer) const override {
+ if (ViewOffset + Offset < Offset)
+ return make_error<CodeViewError>(cv_error_code::insufficient_buffer);
if (Size + Offset > Length)
return make_error<CodeViewError>(cv_error_code::insufficient_buffer);
return Stream->readBytes(ViewOffset + Offset, Size, Buffer);
Modified: llvm/trunk/include/llvm/DebugInfo/PDB/Raw/IPDBFile.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/PDB/Raw/IPDBFile.h?rev=275009&r1=275008&r2=275009&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/PDB/Raw/IPDBFile.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/PDB/Raw/IPDBFile.h Sat Jul 9 22:34:47 2016
@@ -33,8 +33,8 @@ public:
virtual ArrayRef<support::ulittle32_t>
getStreamBlockList(uint32_t StreamIndex) const = 0;
- virtual ArrayRef<uint8_t> getBlockData(uint32_t BlockIndex,
- uint32_t NumBytes) const = 0;
+ virtual Expected<ArrayRef<uint8_t>> getBlockData(uint32_t BlockIndex,
+ uint32_t NumBytes) const = 0;
virtual Error setBlockData(uint32_t BlockIndex, uint32_t Offset,
ArrayRef<uint8_t> Data) const = 0;
};
Modified: llvm/trunk/include/llvm/DebugInfo/PDB/Raw/PDBFile.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/PDB/Raw/PDBFile.h?rev=275009&r1=275008&r2=275009&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/PDB/Raw/PDBFile.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/PDB/Raw/PDBFile.h Sat Jul 9 22:34:47 2016
@@ -84,8 +84,8 @@ public:
getStreamBlockList(uint32_t StreamIndex) const override;
size_t getFileSize() const;
- ArrayRef<uint8_t> getBlockData(uint32_t BlockIndex,
- uint32_t NumBytes) const override;
+ Expected<ArrayRef<uint8_t>> getBlockData(uint32_t BlockIndex,
+ uint32_t NumBytes) const override;
Error setBlockData(uint32_t BlockIndex, uint32_t Offset,
ArrayRef<uint8_t> Data) const override;
Modified: llvm/trunk/lib/DebugInfo/PDB/Raw/MappedBlockStream.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/PDB/Raw/MappedBlockStream.cpp?rev=275009&r1=275008&r2=275009&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/PDB/Raw/MappedBlockStream.cpp (original)
+++ llvm/trunk/lib/DebugInfo/PDB/Raw/MappedBlockStream.cpp Sat Jul 9 22:34:47 2016
@@ -139,8 +139,10 @@ Error MappedBlockStream::readLongestCont
uint32_t BlockSpan = Last - First + 1;
uint32_t ByteSpan =
BytesFromFirstBlock + (BlockSpan - 1) * Pdb.getBlockSize();
- Buffer = Pdb.getBlockData(BlockList[First], Pdb.getBlockSize());
- Buffer = Buffer.drop_front(OffsetInFirstBlock);
+ auto Result = Pdb.getBlockData(BlockList[First], Pdb.getBlockSize());
+ if (!Result)
+ return Result.takeError();
+ Buffer = Result->drop_front(OffsetInFirstBlock);
Buffer = ArrayRef<uint8_t>(Buffer.data(), ByteSpan);
return Error::success();
}
@@ -173,8 +175,12 @@ bool MappedBlockStream::tryReadContiguou
}
uint32_t FirstBlockAddr = BlockList[BlockNum];
- auto Data = Pdb.getBlockData(FirstBlockAddr, Pdb.getBlockSize());
- Data = Data.drop_front(OffsetInBlock);
+ auto Result = Pdb.getBlockData(FirstBlockAddr, Pdb.getBlockSize());
+ if (!Result) {
+ consumeError(Result.takeError());
+ return false;
+ }
+ auto Data = Result->drop_front(OffsetInBlock);
Buffer = ArrayRef<uint8_t>(Data.data(), Size);
return true;
}
@@ -197,8 +203,11 @@ Error MappedBlockStream::readBytes(uint3
while (BytesLeft > 0) {
uint32_t StreamBlockAddr = BlockList[BlockNum];
- auto Data = Pdb.getBlockData(StreamBlockAddr, Pdb.getBlockSize());
+ auto Result = Pdb.getBlockData(StreamBlockAddr, Pdb.getBlockSize());
+ if (!Result)
+ return Result.takeError();
+ auto Data = *Result;
const uint8_t *ChunkStart = Data.data() + OffsetInBlock;
uint32_t BytesInChunk =
std::min(BytesLeft, Pdb.getBlockSize() - OffsetInBlock);
Modified: llvm/trunk/lib/DebugInfo/PDB/Raw/PDBFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/PDB/Raw/PDBFile.cpp?rev=275009&r1=275008&r2=275009&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/PDB/Raw/PDBFile.cpp (original)
+++ llvm/trunk/lib/DebugInfo/PDB/Raw/PDBFile.cpp Sat Jul 9 22:34:47 2016
@@ -73,13 +73,13 @@ PDBFile::getStreamBlockList(uint32_t Str
size_t PDBFile::getFileSize() const { return Buffer->getLength(); }
-ArrayRef<uint8_t> PDBFile::getBlockData(uint32_t BlockIndex,
- uint32_t NumBytes) const {
+Expected<ArrayRef<uint8_t>> PDBFile::getBlockData(uint32_t BlockIndex,
+ uint32_t NumBytes) const {
uint64_t StreamBlockOffset = blockToOffset(BlockIndex, getBlockSize());
ArrayRef<uint8_t> Result;
if (auto EC = Buffer->readBytes(StreamBlockOffset, NumBytes, Result))
- consumeError(std::move(EC));
+ return std::move(EC);
return Result;
}
@@ -460,4 +460,4 @@ Error PDBFile::commit() {
}
return Buffer->commit();
-}
\ No newline at end of file
+}
Modified: llvm/trunk/unittests/DebugInfo/PDB/MappedBlockStreamTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/DebugInfo/PDB/MappedBlockStreamTest.cpp?rev=275009&r1=275008&r2=275009&view=diff
==============================================================================
--- llvm/trunk/unittests/DebugInfo/PDB/MappedBlockStreamTest.cpp (original)
+++ llvm/trunk/unittests/DebugInfo/PDB/MappedBlockStreamTest.cpp Sat Jul 9 22:34:47 2016
@@ -61,8 +61,8 @@ public:
return ArrayRef<support::ulittle32_t>();
return Blocks;
}
- ArrayRef<uint8_t> getBlockData(uint32_t BlockIndex,
- uint32_t NumBytes) const override {
+ Expected<ArrayRef<uint8_t>> getBlockData(uint32_t BlockIndex,
+ uint32_t NumBytes) const override {
return ArrayRef<uint8_t>(&Data[BlockIndex], NumBytes);
}
More information about the llvm-commits
mailing list