@@ -26,6 +26,36 @@ class raw_ostream;
2626
2727namespace lldb_private {
2828
29+ class MachKernelError
30+ : public llvm::ErrorInfo<MachKernelError, llvm::StringError> {
31+ public:
32+ using llvm::ErrorInfo<MachKernelError, llvm::StringError>::ErrorInfo;
33+ MachKernelError (std::error_code ec, const llvm::Twine &msg = {})
34+ : ErrorInfo(msg, ec) {}
35+ std::string message () const override ;
36+ static char ID;
37+ };
38+
39+ class Win32Error : public llvm ::ErrorInfo<Win32Error, llvm::StringError> {
40+ public:
41+ using llvm::ErrorInfo<Win32Error, llvm::StringError>::ErrorInfo;
42+ Win32Error (std::error_code ec, const llvm::Twine &msg = {})
43+ : ErrorInfo(msg, ec) {}
44+ std::string message () const override ;
45+ static char ID;
46+ };
47+
48+ class ExpressionError
49+ : public llvm::ErrorInfo<ExpressionError, llvm::StringError> {
50+ public:
51+ using llvm::ErrorInfo<ExpressionError, llvm::StringError>::ErrorInfo;
52+ ExpressionError (std::error_code ec, std::string msg = {})
53+ : ErrorInfo(msg, ec) {}
54+ static char ID;
55+ };
56+
57+ const char *ExecutionResultAsCString (lldb::ExpressionResults result);
58+
2959// / \class Status Status.h "lldb/Utility/Status.h" An error handling class.
3060// /
3161// / This class is designed to be able to hold any error code that can be
@@ -41,13 +71,32 @@ namespace lldb_private {
4171// / of themselves for printing results and error codes. The string value will
4272// / be fetched on demand and its string value will be cached until the error
4373// / is cleared of the value of the error changes.
74+ // /
75+ // / API design notes:
76+ // /
77+ // / Most APIs that currently vend a Status would be better served by
78+ // / returning llvm::Expected<> instead. If possibles APIs should be
79+ // / refactored to avoid Status. The only legitimate long-term uses of
80+ // / Status are objects that need to store an error for a long time
81+ // / (which should be questioned as a design decision, too).
82+ // /
83+ // / Implementation notes:
84+ // /
85+ // / Internally, Status stores an llvm::Error.
86+ // / eErrorTypeInvalid
87+ // / eErrorTypeGeneric llvm::StringError
88+ // / eErrorTypePOSIX llvm::ECError
89+ // / eErrorTypeMachKernel MachKernelError
90+ // / eErrorTypeExpression llvm::ErrorList<ExpressionError>
91+ // / eErrorTypeWin32 Win32Error
92+
4493class Status {
4594public:
46- // / Every error value that this object can contain needs to be able to fit
4795 // / into ValueType.
4896 typedef uint32_t ValueType;
4997
5098 Status ();
99+ Status (Status &&other) = default ;
51100
52101 // / Initialize the error object with a generic success value.
53102 // /
@@ -91,10 +140,14 @@ class Status {
91140
92141 ~Status ();
93142
143+ const Status &operator =(Status &&);
94144 // / Avoid using this in new code. Migrate APIs to llvm::Expected instead.
95145 static Status FromError (llvm::Error &&error);
96- // / FIXME: Replace this with a takeError method.
146+ // / FIXME: Replace this with a takeError() method.
97147 llvm::Error ToError () const ;
148+ // / Don't call this function in new code. Instead, redesign the API
149+ // / to use llvm::Expected instead of Status.
150+ Status Clone () const { return Status (ToError ()); }
98151
99152 // / Get the error string associated with the current error.
100153 //
0 commit comments