diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2017-05-16 19:47:58 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2017-05-16 19:47:58 +0000 |
commit | b76161e41bc2c07cd47f9c61f875d1be95e26d10 (patch) | |
tree | d03c19ce10dec6419f97df1d4dac9d47eb88982f /source/Utility | |
parent | 8b4000f13b303cc154136abc74c55670673e2a96 (diff) |
Notes
Diffstat (limited to 'source/Utility')
-rw-r--r-- | source/Utility/CMakeLists.txt | 2 | ||||
-rw-r--r-- | source/Utility/JSON.cpp | 22 | ||||
-rw-r--r-- | source/Utility/SelectHelper.cpp | 8 | ||||
-rw-r--r-- | source/Utility/Status.cpp (renamed from source/Utility/Error.cpp) | 61 | ||||
-rw-r--r-- | source/Utility/UUID.cpp | 16 |
5 files changed, 57 insertions, 52 deletions
diff --git a/source/Utility/CMakeLists.txt b/source/Utility/CMakeLists.txt index d4e8e361017cd..a1675670f0b45 100644 --- a/source/Utility/CMakeLists.txt +++ b/source/Utility/CMakeLists.txt @@ -5,7 +5,6 @@ add_lldb_library(lldbUtility DataBufferLLVM.cpp DataEncoder.cpp DataExtractor.cpp - Error.cpp FastDemangle.cpp FileSpec.cpp History.cpp @@ -18,6 +17,7 @@ add_lldb_library(lldbUtility RegularExpression.cpp SelectHelper.cpp SharingPtr.cpp + Status.cpp Stream.cpp StreamCallback.cpp StreamGDBRemote.cpp diff --git a/source/Utility/JSON.cpp b/source/Utility/JSON.cpp index d20d9e46fefd6..cb23f140cbfe0 100644 --- a/source/Utility/JSON.cpp +++ b/source/Utility/JSON.cpp @@ -246,7 +246,7 @@ JSONParser::Token JSONParser::GetToken(std::string &value) { "error: an error occurred getting a character from offset %" PRIu64, start_index); value = std::move(error.GetString()); - return Token::Error; + return Token::Status; } else { const bool is_end_quote = escaped_ch == '"'; @@ -259,13 +259,13 @@ JSONParser::Token JSONParser::GetToken(std::string &value) { "character 0x%4.4x at offset %" PRIu64, escaped_ch, start_index); value = std::move(error.GetString()); - return Token::Error; + return Token::Status; } } else if (is_end_quote) { return Token::String; } else if (is_null) { value = "error: missing end quote for string"; - return Token::Error; + return Token::Status; } } } @@ -316,7 +316,7 @@ JSONParser::Token JSONParser::GetToken(std::string &value) { error.Printf("error: extra decimal point found at offset %" PRIu64, start_index); value = std::move(error.GetString()); - return Token::Error; + return Token::Status; } else { got_decimal_point = true; ++m_index; // Skip this character @@ -330,7 +330,7 @@ JSONParser::Token JSONParser::GetToken(std::string &value) { "error: extra exponent character found at offset %" PRIu64, start_index); value = std::move(error.GetString()); - return Token::Error; + return Token::Status; } else { exp_index = m_index; ++m_index; // Skip this character @@ -346,7 +346,7 @@ JSONParser::Token JSONParser::GetToken(std::string &value) { error.Printf("error: unexpected %c character at offset %" PRIu64, next_ch, start_index); value = std::move(error.GetString()); - return Token::Error; + return Token::Status; } break; @@ -368,7 +368,7 @@ JSONParser::Token JSONParser::GetToken(std::string &value) { "at offset in float value \"%s\"", value.c_str()); value = std::move(error.GetString()); - return Token::Error; + return Token::Status; } } else { // No exponent, but we need at least one decimal after the decimal @@ -379,7 +379,7 @@ JSONParser::Token JSONParser::GetToken(std::string &value) { error.Printf("error: no digits after decimal point \"%s\"", value.c_str()); value = std::move(error.GetString()); - return Token::Error; + return Token::Status; } } } else { @@ -390,14 +390,14 @@ JSONParser::Token JSONParser::GetToken(std::string &value) { } else { error.Printf("error: no digits negate sign \"%s\"", value.c_str()); value = std::move(error.GetString()); - return Token::Error; + return Token::Status; } } } else { error.Printf("error: invalid number found at offset %" PRIu64, start_index); value = std::move(error.GetString()); - return Token::Error; + return Token::Status; } } break; default: @@ -407,7 +407,7 @@ JSONParser::Token JSONParser::GetToken(std::string &value) { " (around character '%c')", start_index, ch); value = std::move(error.GetString()); - return Token::Error; + return Token::Status; } int JSONParser::GetEscapedChar(bool &was_escaped) { diff --git a/source/Utility/SelectHelper.cpp b/source/Utility/SelectHelper.cpp index 7b0557ea192ca..a46213f8bfcb8 100644 --- a/source/Utility/SelectHelper.cpp +++ b/source/Utility/SelectHelper.cpp @@ -15,8 +15,8 @@ #endif #include "lldb/Utility/SelectHelper.h" -#include "lldb/Utility/Error.h" #include "lldb/Utility/LLDBAssert.h" +#include "lldb/Utility/Status.h" #include "lldb/lldb-enumerations.h" // for ErrorType::eErrorTypePOSIX #include "lldb/lldb-types.h" // for socket_t @@ -90,14 +90,14 @@ static void updateMaxFd(llvm::Optional<lldb::socket_t> &vold, vold = std::max(*vold, vnew); } -lldb_private::Error SelectHelper::Select() { - lldb_private::Error error; +lldb_private::Status SelectHelper::Select() { + lldb_private::Status error; #ifdef _MSC_VER // On windows FD_SETSIZE limits the number of file descriptors, not their // numeric value. lldbassert(m_fd_map.size() <= FD_SETSIZE); if (m_fd_map.size() > FD_SETSIZE) - return lldb_private::Error("Too many file descriptors for select()"); + return lldb_private::Status("Too many file descriptors for select()"); #endif llvm::Optional<lldb::socket_t> max_read_fd; diff --git a/source/Utility/Error.cpp b/source/Utility/Status.cpp index b21ee57b61aff..5996be1e4e059 100644 --- a/source/Utility/Error.cpp +++ b/source/Utility/Status.cpp @@ -1,4 +1,5 @@ -//===-- Error.cpp -----------------------------------------------*- C++ -*-===// +//===-- Status.cpp -----------------------------------------------*- C++ +//-*-===// // // The LLVM Compiler Infrastructure // @@ -7,7 +8,7 @@ // //===----------------------------------------------------------------------===// -#include "lldb/Utility/Error.h" +#include "lldb/Utility/Status.h" #include "lldb/Utility/VASPrintf.h" #include "lldb/lldb-defines.h" // for LLDB_GENERIC_ERROR @@ -35,18 +36,18 @@ class raw_ostream; using namespace lldb; using namespace lldb_private; -Error::Error() : m_code(0), m_type(eErrorTypeInvalid), m_string() {} +Status::Status() : m_code(0), m_type(eErrorTypeInvalid), m_string() {} -Error::Error(ValueType err, ErrorType type) +Status::Status(ValueType err, ErrorType type) : m_code(err), m_type(type), m_string() {} -Error::Error(std::error_code EC) +Status::Status(std::error_code EC) : m_code(EC.value()), m_type(ErrorType::eErrorTypeGeneric), m_string(EC.message()) {} -Error::Error(const Error &rhs) = default; +Status::Status(const Status &rhs) = default; -Error::Error(const char *format, ...) +Status::Status(const char *format, ...) : m_code(0), m_type(eErrorTypeInvalid), m_string() { va_list args; va_start(args, format); @@ -58,7 +59,7 @@ Error::Error(const char *format, ...) //---------------------------------------------------------------------- // Assignment operator //---------------------------------------------------------------------- -const Error &Error::operator=(const Error &rhs) { +const Status &Status::operator=(const Status &rhs) { if (this != &rhs) { m_code = rhs.m_code; m_type = rhs.m_type; @@ -70,21 +71,21 @@ const Error &Error::operator=(const Error &rhs) { //---------------------------------------------------------------------- // Assignment operator //---------------------------------------------------------------------- -const Error &Error::operator=(uint32_t err) { +const Status &Status::operator=(uint32_t err) { m_code = err; m_type = eErrorTypeMachKernel; m_string.clear(); return *this; } -Error::~Error() = default; +Status::~Status() = default; //---------------------------------------------------------------------- // Get the error value as a NULL C string. The error string will be // fetched and cached on demand. The cached error string value will // remain until the error value is changed or cleared. //---------------------------------------------------------------------- -const char *Error::AsCString(const char *default_error_str) const { +const char *Status::AsCString(const char *default_error_str) const { if (Success()) return nullptr; @@ -119,7 +120,7 @@ const char *Error::AsCString(const char *default_error_str) const { //---------------------------------------------------------------------- // Clear the error and any cached error string that it might contain. //---------------------------------------------------------------------- -void Error::Clear() { +void Status::Clear() { m_code = 0; m_type = eErrorTypeInvalid; m_string.clear(); @@ -128,38 +129,38 @@ void Error::Clear() { //---------------------------------------------------------------------- // Access the error value. //---------------------------------------------------------------------- -Error::ValueType Error::GetError() const { return m_code; } +Status::ValueType Status::GetError() const { return m_code; } //---------------------------------------------------------------------- // Access the error type. //---------------------------------------------------------------------- -ErrorType Error::GetType() const { return m_type; } +ErrorType Status::GetType() const { return m_type; } //---------------------------------------------------------------------- // Returns true if this object contains a value that describes an // error or otherwise non-success result. //---------------------------------------------------------------------- -bool Error::Fail() const { return m_code != 0; } +bool Status::Fail() const { return m_code != 0; } //---------------------------------------------------------------------- // Set accesssor for the error value to "err" and the type to // "eErrorTypeMachKernel" //---------------------------------------------------------------------- -void Error::SetMachError(uint32_t err) { +void Status::SetMachError(uint32_t err) { m_code = err; m_type = eErrorTypeMachKernel; m_string.clear(); } -void Error::SetExpressionError(lldb::ExpressionResults result, - const char *mssg) { +void Status::SetExpressionError(lldb::ExpressionResults result, + const char *mssg) { m_code = result; m_type = eErrorTypeExpression; m_string = mssg; } -int Error::SetExpressionErrorWithFormat(lldb::ExpressionResults result, - const char *format, ...) { +int Status::SetExpressionErrorWithFormat(lldb::ExpressionResults result, + const char *format, ...) { int length = 0; if (format != nullptr && format[0]) { @@ -178,7 +179,7 @@ int Error::SetExpressionErrorWithFormat(lldb::ExpressionResults result, //---------------------------------------------------------------------- // Set accesssor for the error value and type. //---------------------------------------------------------------------- -void Error::SetError(ValueType err, ErrorType type) { +void Status::SetError(ValueType err, ErrorType type) { m_code = err; m_type = type; m_string.clear(); @@ -188,7 +189,7 @@ void Error::SetError(ValueType err, ErrorType type) { // Update the error value to be "errno" and update the type to // be "POSIX". //---------------------------------------------------------------------- -void Error::SetErrorToErrno() { +void Status::SetErrorToErrno() { m_code = errno; m_type = eErrorTypePOSIX; m_string.clear(); @@ -198,7 +199,7 @@ void Error::SetErrorToErrno() { // Update the error value to be LLDB_GENERIC_ERROR and update the type // to be "Generic". //---------------------------------------------------------------------- -void Error::SetErrorToGenericError() { +void Status::SetErrorToGenericError() { m_code = LLDB_GENERIC_ERROR; m_type = eErrorTypeGeneric; m_string.clear(); @@ -210,7 +211,7 @@ void Error::SetErrorToGenericError() { // The error string value will remain until the error value is // cleared or a new error value/type is assigned. //---------------------------------------------------------------------- -void Error::SetErrorString(llvm::StringRef err_str) { +void Status::SetErrorString(llvm::StringRef err_str) { if (!err_str.empty()) { // If we have an error string, we should always at least have an error // set to a generic value. @@ -226,7 +227,7 @@ void Error::SetErrorString(llvm::StringRef err_str) { /// @param format /// A printf style format string //------------------------------------------------------------------ -int Error::SetErrorStringWithFormat(const char *format, ...) { +int Status::SetErrorStringWithFormat(const char *format, ...) { if (format != nullptr && format[0]) { va_list args; va_start(args, format); @@ -239,7 +240,7 @@ int Error::SetErrorStringWithFormat(const char *format, ...) { return 0; } -int Error::SetErrorStringWithVarArg(const char *format, va_list args) { +int Status::SetErrorStringWithVarArg(const char *format, va_list args) { if (format != nullptr && format[0]) { // If we have an error string, we should always at least have // an error set to a generic value. @@ -260,14 +261,14 @@ int Error::SetErrorStringWithVarArg(const char *format, va_list args) { // Returns true if the error code in this object is considered a // successful return value. //---------------------------------------------------------------------- -bool Error::Success() const { return m_code == 0; } +bool Status::Success() const { return m_code == 0; } -bool Error::WasInterrupted() const { +bool Status::WasInterrupted() const { return (m_type == eErrorTypePOSIX && m_code == EINTR); } -void llvm::format_provider<lldb_private::Error>::format( - const lldb_private::Error &error, llvm::raw_ostream &OS, +void llvm::format_provider<lldb_private::Status>::format( + const lldb_private::Status &error, llvm::raw_ostream &OS, llvm::StringRef Options) { llvm::format_provider<llvm::StringRef>::format(error.AsCString(), OS, Options); diff --git a/source/Utility/UUID.cpp b/source/Utility/UUID.cpp index d82f4d41215e3..b47f8b52f1c24 100644 --- a/source/Utility/UUID.cpp +++ b/source/Utility/UUID.cpp @@ -160,12 +160,9 @@ llvm::StringRef UUID::DecodeUUIDBytesFromString(llvm::StringRef p, bytes_decoded = uuid_byte_idx; return p; } -size_t UUID::SetFromCString(const char *cstr, uint32_t num_uuid_bytes) { - if (cstr == NULL) - return 0; - llvm::StringRef orig(cstr); - llvm::StringRef p = orig; +size_t UUID::SetFromStringRef(llvm::StringRef str, uint32_t num_uuid_bytes) { + llvm::StringRef p = str; // Skip leading whitespace characters p = p.ltrim(); @@ -178,12 +175,19 @@ size_t UUID::SetFromCString(const char *cstr, uint32_t num_uuid_bytes) { // were consumed if (bytes_decoded == num_uuid_bytes) { m_num_uuid_bytes = num_uuid_bytes; - return orig.size() - rest.size(); + return str.size() - rest.size(); } // Else return zero to indicate we were not able to parse a UUID value return 0; } + +size_t UUID::SetFromCString(const char *cstr, uint32_t num_uuid_bytes) { + if (cstr == NULL) + return 0; + + return SetFromStringRef(cstr, num_uuid_bytes); +} } bool lldb_private::operator==(const lldb_private::UUID &lhs, |