summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2017-05-22 19:44:21 +0000
committerDimitry Andric <dim@FreeBSD.org>2017-05-22 19:44:21 +0000
commitfb19dde5bfd42a03786ee50e6b300e47c45ace47 (patch)
tree55abc09b92b053d2b0e643e9451e3aded53defd3
parent5a5de6ea3962782b02221b96b27dd064b25d381f (diff)
downloadsrc-test2-fb19dde5bfd42a03786ee50e6b300e47c45ace47.tar.gz
src-test2-fb19dde5bfd42a03786ee50e6b300e47c45ace47.zip
Notes
-rw-r--r--include/lldb/Utility/Status.h20
-rw-r--r--packages/Python/lldbsuite/test/configuration.py2
-rw-r--r--source/Core/IOHandler.cpp2
-rw-r--r--source/Utility/Status.cpp31
-rw-r--r--unittests/Utility/StatusTest.cpp31
5 files changed, 74 insertions, 12 deletions
diff --git a/include/lldb/Utility/Status.h b/include/lldb/Utility/Status.h
index 4ac191b1f613..d8fd41707f8c 100644
--- a/include/lldb/Utility/Status.h
+++ b/include/lldb/Utility/Status.h
@@ -1,5 +1,4 @@
-//===-- Status.h -------------------------------------------------*- C++
-//-*-===//
+//===-- Status.h ------------------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
@@ -8,22 +7,20 @@
//
//===----------------------------------------------------------------------===//
-#ifndef __DCError_h__
-#define __DCError_h__
-#if defined(__cplusplus)
+#ifndef LLDB_UTILITY_STATUS_H
+#define LLDB_UTILITY_STATUS_H
#include "lldb/lldb-defines.h"
#include "lldb/lldb-enumerations.h" // for ErrorType, ErrorType...
#include "llvm/ADT/StringRef.h" // for StringRef
+#include "llvm/Support/Error.h"
#include "llvm/Support/FormatVariadic.h"
-
#include <cstdarg>
+#include <stdint.h> // for uint32_t
#include <string>
#include <system_error> // for error_code
#include <type_traits> // for forward
-#include <stdint.h> // for uint32_t
-
namespace llvm {
class raw_ostream;
}
@@ -106,6 +103,10 @@ public:
~Status();
+ // llvm::Error support
+ explicit Status(llvm::Error error);
+ llvm::Error ToError() const;
+
//------------------------------------------------------------------
/// Get the error string associated with the current error.
//
@@ -274,5 +275,4 @@ template <> struct format_provider<lldb_private::Status> {
};
}
-#endif // #if defined(__cplusplus)
-#endif // #ifndef __DCError_h__
+#endif // #ifndef LLDB_UTILITY_STATUS_H
diff --git a/packages/Python/lldbsuite/test/configuration.py b/packages/Python/lldbsuite/test/configuration.py
index 120f8247c695..a49948c02050 100644
--- a/packages/Python/lldbsuite/test/configuration.py
+++ b/packages/Python/lldbsuite/test/configuration.py
@@ -44,7 +44,7 @@ def setupCrashInfoHook():
if not os.path.isfile(dylib_dst) or os.path.getmtime(
dylib_dst) < os.path.getmtime(dylib_src):
# we need to compile
- cmd = "SDKROOT= xcrun clang %s -o %s -framework Python -Xlinker -dylib -iframework /System/Library/Frameworks/ -Xlinker -F /System/Library/Frameworks/" % (
+ cmd = "SDKROOT= xcrun clang %s -o %s -framework Python -Xlinker -dylib" % (
dylib_src, dylib_dst)
if subprocess.call(
cmd, shell=True) != 0 or not os.path.isfile(dylib_dst):
diff --git a/source/Core/IOHandler.cpp b/source/Core/IOHandler.cpp
index e5fe490991f9..3cb1ffab3a0e 100644
--- a/source/Core/IOHandler.cpp
+++ b/source/Core/IOHandler.cpp
@@ -4640,7 +4640,7 @@ void IOHandlerCursesGUI::Activate() {
WindowSP threads_window_sp(
main_window_sp->CreateSubWindow("Threads", threads_bounds, false));
WindowSP status_window_sp(
- main_window_sp->CreateSubWindow("Error", status_bounds, false));
+ main_window_sp->CreateSubWindow("Status", status_bounds, false));
status_window_sp->SetCanBeActive(
false); // Don't let the status bar become the active window
main_window_sp->SetDelegate(
diff --git a/source/Utility/Status.cpp b/source/Utility/Status.cpp
index 5996be1e4e05..ba87d3e5144f 100644
--- a/source/Utility/Status.cpp
+++ b/source/Utility/Status.cpp
@@ -56,6 +56,37 @@ Status::Status(const char *format, ...)
va_end(args);
}
+Status::Status(llvm::Error error)
+ : m_code(0), m_type(ErrorType::eErrorTypeGeneric) {
+ if (!error)
+ return;
+
+ // if the error happens to be a errno error, preserve the error code
+ error = llvm::handleErrors(
+ std::move(error), [&](std::unique_ptr<llvm::ECError> e) -> llvm::Error {
+ std::error_code ec = e->convertToErrorCode();
+ if (ec.category() == std::generic_category()) {
+ m_code = ec.value();
+ m_type = ErrorType::eErrorTypePOSIX;
+ return llvm::Error::success();
+ }
+ return llvm::Error(std::move(e));
+ });
+
+ // Otherwise, just preserve the message
+ if (error)
+ SetErrorString(llvm::toString(std::move(error)));
+}
+
+llvm::Error Status::ToError() const {
+ if (Success())
+ return llvm::Error::success();
+ if (m_type == ErrorType::eErrorTypePOSIX)
+ return llvm::errorCodeToError(std::error_code(m_code, std::generic_category()));
+ return llvm::make_error<llvm::StringError>(AsCString(),
+ llvm::inconvertibleErrorCode());
+}
+
//----------------------------------------------------------------------
// Assignment operator
//----------------------------------------------------------------------
diff --git a/unittests/Utility/StatusTest.cpp b/unittests/Utility/StatusTest.cpp
index 9655610e4aa3..03e2368c7b1b 100644
--- a/unittests/Utility/StatusTest.cpp
+++ b/unittests/Utility/StatusTest.cpp
@@ -11,9 +11,40 @@
#include "gtest/gtest.h"
using namespace lldb_private;
+using namespace lldb;
TEST(StatusTest, Formatv) {
EXPECT_EQ("", llvm::formatv("{0}", Status()).str());
EXPECT_EQ("Hello Status", llvm::formatv("{0}", Status("Hello Status")).str());
EXPECT_EQ("Hello", llvm::formatv("{0:5}", Status("Hello Error")).str());
}
+
+TEST(StatusTest, ErrorConstructor) {
+ EXPECT_TRUE(Status(llvm::Error::success()).Success());
+
+ Status eagain(
+ llvm::errorCodeToError(std::error_code(EAGAIN, std::generic_category())));
+ EXPECT_TRUE(eagain.Fail());
+ EXPECT_EQ(eErrorTypePOSIX, eagain.GetType());
+ EXPECT_EQ(Status::ValueType(EAGAIN), eagain.GetError());
+
+ Status foo(llvm::make_error<llvm::StringError>(
+ "foo", llvm::inconvertibleErrorCode()));
+ EXPECT_TRUE(foo.Fail());
+ EXPECT_EQ(eErrorTypeGeneric, foo.GetType());
+ EXPECT_STREQ("foo", foo.AsCString());
+}
+
+TEST(StatusTest, ErrorConversion) {
+ EXPECT_FALSE(bool(Status().ToError()));
+
+ llvm::Error eagain = Status(EAGAIN, ErrorType::eErrorTypePOSIX).ToError();
+ EXPECT_TRUE(bool(eagain));
+ std::error_code ec = llvm::errorToErrorCode(std::move(eagain));
+ EXPECT_EQ(EAGAIN, ec.value());
+ EXPECT_EQ(std::generic_category(), ec.category());
+
+ llvm::Error foo = Status("foo").ToError();
+ EXPECT_TRUE(bool(foo));
+ EXPECT_EQ("foo", llvm::toString(std::move(foo)));
+}