aboutsummaryrefslogtreecommitdiff
path: root/lib/DebugInfo/MSF/MappedBlockStream.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/DebugInfo/MSF/MappedBlockStream.cpp')
-rw-r--r--lib/DebugInfo/MSF/MappedBlockStream.cpp74
1 files changed, 32 insertions, 42 deletions
diff --git a/lib/DebugInfo/MSF/MappedBlockStream.cpp b/lib/DebugInfo/MSF/MappedBlockStream.cpp
index e52c88a5bfb8..57953cfa338e 100644
--- a/lib/DebugInfo/MSF/MappedBlockStream.cpp
+++ b/lib/DebugInfo/MSF/MappedBlockStream.cpp
@@ -11,8 +11,8 @@
#include "llvm/DebugInfo/MSF/IMSFFile.h"
#include "llvm/DebugInfo/MSF/MSFCommon.h"
-#include "llvm/DebugInfo/MSF/MSFError.h"
#include "llvm/DebugInfo/MSF/MSFStreamLayout.h"
+#include "llvm/Support/BinaryStreamError.h"
using namespace llvm;
using namespace llvm::msf;
@@ -47,22 +47,20 @@ static Interval intersect(const Interval &I1, const Interval &I2) {
MappedBlockStream::MappedBlockStream(uint32_t BlockSize, uint32_t NumBlocks,
const MSFStreamLayout &Layout,
- const ReadableStream &MsfData)
+ BinaryStreamRef MsfData)
: BlockSize(BlockSize), NumBlocks(NumBlocks), StreamLayout(Layout),
MsfData(MsfData) {}
std::unique_ptr<MappedBlockStream>
MappedBlockStream::createStream(uint32_t BlockSize, uint32_t NumBlocks,
const MSFStreamLayout &Layout,
- const ReadableStream &MsfData) {
+ BinaryStreamRef MsfData) {
return llvm::make_unique<MappedBlockStreamImpl<MappedBlockStream>>(
BlockSize, NumBlocks, Layout, MsfData);
}
-std::unique_ptr<MappedBlockStream>
-MappedBlockStream::createIndexedStream(const MSFLayout &Layout,
- const ReadableStream &MsfData,
- uint32_t StreamIndex) {
+std::unique_ptr<MappedBlockStream> MappedBlockStream::createIndexedStream(
+ const MSFLayout &Layout, BinaryStreamRef MsfData, uint32_t StreamIndex) {
assert(StreamIndex < Layout.StreamMap.size() && "Invalid stream index");
MSFStreamLayout SL;
SL.Blocks = Layout.StreamMap[StreamIndex];
@@ -73,7 +71,7 @@ MappedBlockStream::createIndexedStream(const MSFLayout &Layout,
std::unique_ptr<MappedBlockStream>
MappedBlockStream::createDirectoryStream(const MSFLayout &Layout,
- const ReadableStream &MsfData) {
+ BinaryStreamRef MsfData) {
MSFStreamLayout SL;
SL.Blocks = Layout.DirectoryBlocks;
SL.Length = Layout.SB->NumDirectoryBytes;
@@ -82,19 +80,17 @@ MappedBlockStream::createDirectoryStream(const MSFLayout &Layout,
std::unique_ptr<MappedBlockStream>
MappedBlockStream::createFpmStream(const MSFLayout &Layout,
- const ReadableStream &MsfData) {
+ BinaryStreamRef MsfData) {
MSFStreamLayout SL;
initializeFpmStreamLayout(Layout, SL);
return createStream(Layout.SB->BlockSize, Layout.SB->NumBlocks, SL, MsfData);
}
Error MappedBlockStream::readBytes(uint32_t Offset, uint32_t Size,
- ArrayRef<uint8_t> &Buffer) const {
+ ArrayRef<uint8_t> &Buffer) {
// Make sure we aren't trying to read beyond the end of the stream.
- if (Size > StreamLayout.Length)
- return make_error<MSFError>(msf_error_code::insufficient_buffer);
- if (Offset > StreamLayout.Length - Size)
- return make_error<MSFError>(msf_error_code::insufficient_buffer);
+ if (auto EC = checkOffset(Offset, Size))
+ return EC;
if (tryReadContiguously(Offset, Size, Buffer))
return Error::success();
@@ -168,11 +164,12 @@ Error MappedBlockStream::readBytes(uint32_t Offset, uint32_t Size,
return Error::success();
}
-Error MappedBlockStream::readLongestContiguousChunk(
- uint32_t Offset, ArrayRef<uint8_t> &Buffer) const {
+Error MappedBlockStream::readLongestContiguousChunk(uint32_t Offset,
+ ArrayRef<uint8_t> &Buffer) {
// Make sure we aren't trying to read beyond the end of the stream.
- if (Offset >= StreamLayout.Length)
- return make_error<MSFError>(msf_error_code::insufficient_buffer);
+ if (auto EC = checkOffset(Offset, 1))
+ return EC;
+
uint32_t First = Offset / BlockSize;
uint32_t Last = First;
@@ -197,10 +194,10 @@ Error MappedBlockStream::readLongestContiguousChunk(
return Error::success();
}
-uint32_t MappedBlockStream::getLength() const { return StreamLayout.Length; }
+uint32_t MappedBlockStream::getLength() { return StreamLayout.Length; }
bool MappedBlockStream::tryReadContiguously(uint32_t Offset, uint32_t Size,
- ArrayRef<uint8_t> &Buffer) const {
+ ArrayRef<uint8_t> &Buffer) {
if (Size == 0) {
Buffer = ArrayRef<uint8_t>();
return true;
@@ -241,15 +238,13 @@ bool MappedBlockStream::tryReadContiguously(uint32_t Offset, uint32_t Size,
}
Error MappedBlockStream::readBytes(uint32_t Offset,
- MutableArrayRef<uint8_t> Buffer) const {
+ MutableArrayRef<uint8_t> Buffer) {
uint32_t BlockNum = Offset / BlockSize;
uint32_t OffsetInBlock = Offset % BlockSize;
// Make sure we aren't trying to read beyond the end of the stream.
- if (Buffer.size() > StreamLayout.Length)
- return make_error<MSFError>(msf_error_code::insufficient_buffer);
- if (Offset > StreamLayout.Length - Buffer.size())
- return make_error<MSFError>(msf_error_code::insufficient_buffer);
+ if (auto EC = checkOffset(Offset, Buffer.size()))
+ return EC;
uint32_t BytesLeft = Buffer.size();
uint32_t BytesWritten = 0;
@@ -319,21 +314,21 @@ void MappedBlockStream::fixCacheAfterWrite(uint32_t Offset,
WritableMappedBlockStream::WritableMappedBlockStream(
uint32_t BlockSize, uint32_t NumBlocks, const MSFStreamLayout &Layout,
- const WritableStream &MsfData)
+ WritableBinaryStreamRef MsfData)
: ReadInterface(BlockSize, NumBlocks, Layout, MsfData),
WriteInterface(MsfData) {}
std::unique_ptr<WritableMappedBlockStream>
WritableMappedBlockStream::createStream(uint32_t BlockSize, uint32_t NumBlocks,
const MSFStreamLayout &Layout,
- const WritableStream &MsfData) {
+ WritableBinaryStreamRef MsfData) {
return llvm::make_unique<MappedBlockStreamImpl<WritableMappedBlockStream>>(
BlockSize, NumBlocks, Layout, MsfData);
}
std::unique_ptr<WritableMappedBlockStream>
WritableMappedBlockStream::createIndexedStream(const MSFLayout &Layout,
- const WritableStream &MsfData,
+ WritableBinaryStreamRef MsfData,
uint32_t StreamIndex) {
assert(StreamIndex < Layout.StreamMap.size() && "Invalid stream index");
MSFStreamLayout SL;
@@ -344,7 +339,7 @@ WritableMappedBlockStream::createIndexedStream(const MSFLayout &Layout,
std::unique_ptr<WritableMappedBlockStream>
WritableMappedBlockStream::createDirectoryStream(
- const MSFLayout &Layout, const WritableStream &MsfData) {
+ const MSFLayout &Layout, WritableBinaryStreamRef MsfData) {
MSFStreamLayout SL;
SL.Blocks = Layout.DirectoryBlocks;
SL.Length = Layout.SB->NumDirectoryBytes;
@@ -353,34 +348,31 @@ WritableMappedBlockStream::createDirectoryStream(
std::unique_ptr<WritableMappedBlockStream>
WritableMappedBlockStream::createFpmStream(const MSFLayout &Layout,
- const WritableStream &MsfData) {
+ WritableBinaryStreamRef MsfData) {
MSFStreamLayout SL;
initializeFpmStreamLayout(Layout, SL);
return createStream(Layout.SB->BlockSize, Layout.SB->NumBlocks, SL, MsfData);
}
Error WritableMappedBlockStream::readBytes(uint32_t Offset, uint32_t Size,
- ArrayRef<uint8_t> &Buffer) const {
+ ArrayRef<uint8_t> &Buffer) {
return ReadInterface.readBytes(Offset, Size, Buffer);
}
Error WritableMappedBlockStream::readLongestContiguousChunk(
- uint32_t Offset, ArrayRef<uint8_t> &Buffer) const {
+ uint32_t Offset, ArrayRef<uint8_t> &Buffer) {
return ReadInterface.readLongestContiguousChunk(Offset, Buffer);
}
-uint32_t WritableMappedBlockStream::getLength() const {
+uint32_t WritableMappedBlockStream::getLength() {
return ReadInterface.getLength();
}
Error WritableMappedBlockStream::writeBytes(uint32_t Offset,
- ArrayRef<uint8_t> Buffer) const {
+ ArrayRef<uint8_t> Buffer) {
// Make sure we aren't trying to write beyond the end of the stream.
- if (Buffer.size() > getStreamLength())
- return make_error<MSFError>(msf_error_code::insufficient_buffer);
-
- if (Offset > getStreamLayout().Length - Buffer.size())
- return make_error<MSFError>(msf_error_code::insufficient_buffer);
+ if (auto EC = checkOffset(Offset, Buffer.size()))
+ return EC;
uint32_t BlockNum = Offset / getBlockSize();
uint32_t OffsetInBlock = Offset % getBlockSize();
@@ -410,6 +402,4 @@ Error WritableMappedBlockStream::writeBytes(uint32_t Offset,
return Error::success();
}
-Error WritableMappedBlockStream::commit() const {
- return WriteInterface.commit();
-}
+Error WritableMappedBlockStream::commit() { return WriteInterface.commit(); }