summaryrefslogtreecommitdiffstats
path: root/llvm/lib/DebugInfo/MSF
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/DebugInfo/MSF')
-rw-r--r--llvm/lib/DebugInfo/MSF/BinaryStreamError.cpp58
-rw-r--r--llvm/lib/DebugInfo/MSF/BinaryStreamReader.cpp7
-rw-r--r--llvm/lib/DebugInfo/MSF/CMakeLists.txt1
-rw-r--r--llvm/lib/DebugInfo/MSF/MappedBlockStream.cpp26
4 files changed, 72 insertions, 20 deletions
diff --git a/llvm/lib/DebugInfo/MSF/BinaryStreamError.cpp b/llvm/lib/DebugInfo/MSF/BinaryStreamError.cpp
new file mode 100644
index 00000000000..2f299dc5b5e
--- /dev/null
+++ b/llvm/lib/DebugInfo/MSF/BinaryStreamError.cpp
@@ -0,0 +1,58 @@
+//===- BinaryStreamError.cpp - Error extensions for streams -----*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/DebugInfo/MSF/BinaryStreamError.h"
+#include "llvm/Support/ErrorHandling.h"
+
+using namespace llvm;
+
+char BinaryStreamError::ID = 0;
+
+BinaryStreamError::BinaryStreamError(stream_error_code C)
+ : BinaryStreamError(C, "") {}
+
+BinaryStreamError::BinaryStreamError(StringRef Context)
+ : BinaryStreamError(stream_error_code::unspecified, Context) {}
+
+BinaryStreamError::BinaryStreamError(stream_error_code C, StringRef Context)
+ : Code(C) {
+ ErrMsg = "Stream Error: ";
+ switch (C) {
+ case stream_error_code::unspecified:
+ ErrMsg += "An unspecified error has occurred.";
+ break;
+ case stream_error_code::stream_too_short:
+ ErrMsg += "The stream is too short to perform the requested operation.";
+ break;
+ case stream_error_code::invalid_array_size:
+ ErrMsg += "The buffer size is not a multiple of the array element size.";
+ break;
+ case stream_error_code::invalid_offset:
+ ErrMsg += "The specified offset is invalid for the current stream.";
+ break;
+ case stream_error_code::filesystem_error:
+ ErrMsg += "An I/O error occurred on the file system.";
+ break;
+ default:
+ llvm_unreachable("Unreachable!");
+ }
+
+ if (!Context.empty()) {
+ ErrMsg += " ";
+ ErrMsg += Context;
+ }
+}
+
+void BinaryStreamError::log(raw_ostream &OS) const { OS << ErrMsg << "\n"; }
+
+StringRef BinaryStreamError::getErrorMessage() const { return ErrMsg; }
+
+std::error_code BinaryStreamError::convertToErrorCode() const {
+ return inconvertibleErrorCode();
+}
diff --git a/llvm/lib/DebugInfo/MSF/BinaryStreamReader.cpp b/llvm/lib/DebugInfo/MSF/BinaryStreamReader.cpp
index 170cc4cbeef..b6d7ee9d0b0 100644
--- a/llvm/lib/DebugInfo/MSF/BinaryStreamReader.cpp
+++ b/llvm/lib/DebugInfo/MSF/BinaryStreamReader.cpp
@@ -9,11 +9,10 @@
#include "llvm/DebugInfo/MSF/BinaryStreamReader.h"
+#include "llvm/DebugInfo/MSF/BinaryStreamError.h"
#include "llvm/DebugInfo/MSF/BinaryStreamRef.h"
-#include "llvm/DebugInfo/MSF/MSFError.h"
using namespace llvm;
-using namespace llvm::msf;
BinaryStreamReader::BinaryStreamReader(BinaryStreamRef S)
: Stream(S), Offset(0) {}
@@ -74,7 +73,7 @@ Error BinaryStreamReader::readStreamRef(BinaryStreamRef &Ref) {
Error BinaryStreamReader::readStreamRef(BinaryStreamRef &Ref, uint32_t Length) {
if (bytesRemaining() < Length)
- return make_error<MSFError>(msf_error_code::insufficient_buffer);
+ return make_error<BinaryStreamError>(stream_error_code::stream_too_short);
Ref = Stream.slice(Offset, Length);
Offset += Length;
return Error::success();
@@ -82,7 +81,7 @@ Error BinaryStreamReader::readStreamRef(BinaryStreamRef &Ref, uint32_t Length) {
Error BinaryStreamReader::skip(uint32_t Amount) {
if (Amount > bytesRemaining())
- return make_error<MSFError>(msf_error_code::insufficient_buffer);
+ return make_error<BinaryStreamError>(stream_error_code::stream_too_short);
Offset += Amount;
return Error::success();
}
diff --git a/llvm/lib/DebugInfo/MSF/CMakeLists.txt b/llvm/lib/DebugInfo/MSF/CMakeLists.txt
index 6938513fcde..5537b7008ce 100644
--- a/llvm/lib/DebugInfo/MSF/CMakeLists.txt
+++ b/llvm/lib/DebugInfo/MSF/CMakeLists.txt
@@ -1,4 +1,5 @@
add_llvm_library(LLVMDebugInfoMSF
+ BinaryStreamError.cpp
BinaryStreamReader.cpp
BinaryStreamWriter.cpp
MappedBlockStream.cpp
diff --git a/llvm/lib/DebugInfo/MSF/MappedBlockStream.cpp b/llvm/lib/DebugInfo/MSF/MappedBlockStream.cpp
index c9ba25c0d7d..242088c9391 100644
--- a/llvm/lib/DebugInfo/MSF/MappedBlockStream.cpp
+++ b/llvm/lib/DebugInfo/MSF/MappedBlockStream.cpp
@@ -9,9 +9,9 @@
#include "llvm/DebugInfo/MSF/MappedBlockStream.h"
+#include "llvm/DebugInfo/MSF/BinaryStreamError.h"
#include "llvm/DebugInfo/MSF/IMSFFile.h"
#include "llvm/DebugInfo/MSF/MSFCommon.h"
-#include "llvm/DebugInfo/MSF/MSFError.h"
#include "llvm/DebugInfo/MSF/MSFStreamLayout.h"
using namespace llvm;
@@ -89,10 +89,8 @@ MappedBlockStream::createFpmStream(const MSFLayout &Layout,
Error MappedBlockStream::readBytes(uint32_t Offset, uint32_t Size,
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();
@@ -169,8 +167,9 @@ Error MappedBlockStream::readBytes(uint32_t Offset, uint32_t Size,
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;
@@ -244,10 +243,8 @@ Error MappedBlockStream::readBytes(uint32_t Offset,
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;
@@ -374,11 +371,8 @@ uint32_t WritableMappedBlockStream::getLength() {
Error WritableMappedBlockStream::writeBytes(uint32_t Offset,
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();
OpenPOWER on IntegriCloud