@@ -28,6 +28,67 @@ namespace lldb_private {
28
28
29
29
const char *ExpressionResultAsCString (lldb::ExpressionResults result);
30
30
31
+ // / Going a bit against the spirit of llvm::Error,
32
+ // / lldb_private::Status need to store errors long-term and sometimes
33
+ // / copy them. This base class defines an interface for this
34
+ // / operation.
35
+ class CloneableError
36
+ : public llvm::ErrorInfo<CloneableError, llvm::ErrorInfoBase> {
37
+ public:
38
+ using llvm::ErrorInfo<CloneableError, llvm::ErrorInfoBase>::ErrorInfo;
39
+ CloneableError () : ErrorInfo() {}
40
+ virtual std::unique_ptr<CloneableError> Clone () const = 0;
41
+ static char ID;
42
+ };
43
+
44
+ // / Common base class for all error-code errors.
45
+ class CloneableECError
46
+ : public llvm::ErrorInfo<CloneableECError, CloneableError> {
47
+ public:
48
+ using llvm::ErrorInfo<CloneableECError, CloneableError>::ErrorInfo;
49
+ std::error_code convertToErrorCode () const override { return EC; }
50
+ void log (llvm::raw_ostream &OS) const override { OS << EC.message (); }
51
+ static char ID;
52
+
53
+ protected:
54
+ CloneableECError () = delete ;
55
+ CloneableECError (std::error_code ec) : ErrorInfo(), EC(ec) {}
56
+ std::error_code EC;
57
+ };
58
+ // / FIXME: Move these declarations closer to where they're used.
59
+ class MachKernelError
60
+ : public llvm::ErrorInfo<MachKernelError, CloneableECError> {
61
+ public:
62
+ using llvm::ErrorInfo<MachKernelError, CloneableECError>::ErrorInfo;
63
+ MachKernelError (std::error_code ec) : ErrorInfo(ec) {}
64
+ std::string message () const override ;
65
+ std::unique_ptr<CloneableError> Clone () const override ;
66
+ static char ID;
67
+ };
68
+
69
+ class Win32Error : public llvm ::ErrorInfo<Win32Error, CloneableECError> {
70
+ public:
71
+ using llvm::ErrorInfo<Win32Error, CloneableECError>::ErrorInfo;
72
+ Win32Error (std::error_code ec, const llvm::Twine &msg = {}) : ErrorInfo(ec) {}
73
+ std::string message () const override ;
74
+ std::unique_ptr<CloneableError> Clone () const override ;
75
+ static char ID;
76
+ };
77
+
78
+ class ExpressionError
79
+ : public llvm::ErrorInfo<ExpressionError, CloneableECError> {
80
+ public:
81
+ using llvm::ErrorInfo<ExpressionError, CloneableECError>::ErrorInfo;
82
+ ExpressionError (std::error_code ec, std::string msg = {})
83
+ : ErrorInfo(ec), m_string(msg) {}
84
+ std::unique_ptr<CloneableError> Clone () const override ;
85
+ std::string message () const override { return m_string; }
86
+ static char ID;
87
+
88
+ protected:
89
+ std::string m_string;
90
+ };
91
+
31
92
// / \class Status Status.h "lldb/Utility/Status.h" An error handling class.
32
93
// /
33
94
// / This class is designed to be able to hold any error code that can be
@@ -100,9 +161,7 @@ class Status {
100
161
}
101
162
102
163
static Status FromExpressionError (lldb::ExpressionResults result,
103
- std::string msg) {
104
- return Status (result, lldb::eErrorTypeExpression, msg);
105
- }
164
+ std::string msg);
106
165
107
166
// / Set the current error to errno.
108
167
// /
@@ -115,6 +174,7 @@ class Status {
115
174
const Status &operator =(Status &&);
116
175
// / Avoid using this in new code. Migrate APIs to llvm::Expected instead.
117
176
static Status FromError (llvm::Error error);
177
+
118
178
// / FIXME: Replace this with a takeError() method.
119
179
llvm::Error ToError () const ;
120
180
// / Don't call this function in new code. Instead, redesign the API
@@ -149,12 +209,20 @@ class Status {
149
209
150
210
// / Access the error value.
151
211
// /
212
+ // / If the internally stored \ref llvm::Error is an \ref
213
+ // / llvm::ErrorList then this returns the error value of the first
214
+ // / error.
215
+ // /
152
216
// / \return
153
217
// / The error value.
154
218
ValueType GetError () const ;
155
219
156
220
// / Access the error type.
157
221
// /
222
+ // / If the internally stored \ref llvm::Error is an \ref
223
+ // / llvm::ErrorList then this returns the error value of the first
224
+ // / error.
225
+ // /
158
226
// / \return
159
227
// / The error type enumeration value.
160
228
lldb::ErrorType GetType () const ;
@@ -170,12 +238,9 @@ class Status {
170
238
bool Success () const ;
171
239
172
240
protected:
173
- Status (llvm::Error error);
174
- // / Status code as an integer value.
175
- ValueType m_code = 0 ;
176
- // / The type of the above error code.
177
- lldb::ErrorType m_type = lldb::eErrorTypeInvalid;
178
- // / A string representation of the error code.
241
+ Status (llvm::Error error) : m_error(std::move(error)) {}
242
+ llvm::Error m_error;
243
+ // / TODO: Replace this with just calling toString(m_error).
179
244
mutable std::string m_string;
180
245
};
181
246
0 commit comments