Skip to content

Commit cb6d531

Browse files
committed
Revert "[lldb] Change the implementation of Status to store an llvm::Error (NFC) (#106774)"
This reverts commit 06939fa.
1 parent 2730373 commit cb6d531

File tree

5 files changed

+108
-285
lines changed

5 files changed

+108
-285
lines changed

lldb/include/lldb/Utility/Status.h

Lines changed: 9 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -28,69 +28,6 @@ namespace lldb_private {
2828

2929
const char *ExpressionResultAsCString(lldb::ExpressionResults result);
3030

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-
CloneableECError() = delete;
50-
CloneableECError(std::error_code ec) : ErrorInfo(), EC(ec) {}
51-
std::error_code convertToErrorCode() const override { return EC; }
52-
void log(llvm::raw_ostream &OS) const override { OS << EC.message(); }
53-
std::unique_ptr<CloneableError> Clone() const override;
54-
static char ID;
55-
56-
protected:
57-
std::error_code EC;
58-
};
59-
60-
/// FIXME: Move these declarations closer to where they're used.
61-
class MachKernelError
62-
: public llvm::ErrorInfo<MachKernelError, CloneableECError> {
63-
public:
64-
using llvm::ErrorInfo<MachKernelError, CloneableECError>::ErrorInfo;
65-
MachKernelError(std::error_code ec) : ErrorInfo(ec) {}
66-
std::string message() const override;
67-
std::unique_ptr<CloneableError> Clone() const override;
68-
static char ID;
69-
};
70-
71-
class Win32Error : public llvm::ErrorInfo<Win32Error, CloneableECError> {
72-
public:
73-
using llvm::ErrorInfo<Win32Error, CloneableECError>::ErrorInfo;
74-
Win32Error(std::error_code ec, const llvm::Twine &msg = {}) : ErrorInfo(ec) {}
75-
std::string message() const override;
76-
std::unique_ptr<CloneableError> Clone() const override;
77-
static char ID;
78-
};
79-
80-
class ExpressionError
81-
: public llvm::ErrorInfo<ExpressionError, CloneableECError> {
82-
public:
83-
using llvm::ErrorInfo<ExpressionError, CloneableECError>::ErrorInfo;
84-
ExpressionError(std::error_code ec, std::string msg = {})
85-
: ErrorInfo(ec), m_string(msg) {}
86-
std::unique_ptr<CloneableError> Clone() const override;
87-
std::string message() const override { return m_string; }
88-
static char ID;
89-
90-
protected:
91-
std::string m_string;
92-
};
93-
9431
/// \class Status Status.h "lldb/Utility/Status.h" An error handling class.
9532
///
9633
/// This class is designed to be able to hold any error code that can be
@@ -163,7 +100,9 @@ class Status {
163100
}
164101

165102
static Status FromExpressionError(lldb::ExpressionResults result,
166-
std::string msg);
103+
std::string msg) {
104+
return Status(result, lldb::eErrorTypeExpression, msg);
105+
}
167106

168107
/// Set the current error to errno.
169108
///
@@ -176,7 +115,6 @@ class Status {
176115
const Status &operator=(Status &&);
177116
/// Avoid using this in new code. Migrate APIs to llvm::Expected instead.
178117
static Status FromError(llvm::Error error);
179-
180118
/// FIXME: Replace this with a takeError() method.
181119
llvm::Error ToError() const;
182120
/// Don't call this function in new code. Instead, redesign the API
@@ -211,20 +149,12 @@ class Status {
211149

212150
/// Access the error value.
213151
///
214-
/// If the internally stored \ref llvm::Error is an \ref
215-
/// llvm::ErrorList then this returns the error value of the first
216-
/// error.
217-
///
218152
/// \return
219153
/// The error value.
220154
ValueType GetError() const;
221155

222156
/// Access the error type.
223157
///
224-
/// If the internally stored \ref llvm::Error is an \ref
225-
/// llvm::ErrorList then this returns the error value of the first
226-
/// error.
227-
///
228158
/// \return
229159
/// The error type enumeration value.
230160
lldb::ErrorType GetType() const;
@@ -240,9 +170,12 @@ class Status {
240170
bool Success() const;
241171

242172
protected:
243-
Status(llvm::Error error) : m_error(std::move(error)) {}
244-
llvm::Error m_error;
245-
/// TODO: Replace this with just callling toString(m_error).
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.
246179
mutable std::string m_string;
247180
};
248181

lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -993,8 +993,8 @@ void PythonException::Restore() {
993993
}
994994

995995
PythonException::~PythonException() {
996-
Py_XDECREF(m_exception);
997996
Py_XDECREF(m_exception_type);
997+
Py_XDECREF(m_exception);
998998
Py_XDECREF(m_traceback);
999999
Py_XDECREF(m_repr_bytes);
10001000
}
@@ -1108,10 +1108,9 @@ template <typename Base> class OwnedPythonFile : public Base {
11081108
py_error = Status::FromError(r.takeError());
11091109
}
11101110
base_error = Base::Close();
1111-
// Cloning since the wrapped exception may still reference the PyThread.
11121111
if (py_error.Fail())
1113-
return py_error.Clone();
1114-
return base_error.Clone();
1112+
return py_error;
1113+
return base_error;
11151114
};
11161115

11171116
PyObject *GetPythonObject() const {
@@ -1197,17 +1196,15 @@ class PythonIOFile : public OwnedPythonFile<File> {
11971196
return Flush();
11981197
auto r = m_py_obj.CallMethod("close");
11991198
if (!r)
1200-
// Cloning since the wrapped exception may still reference the PyThread.
1201-
return Status::FromError(r.takeError()).Clone();
1199+
return Status::FromError(r.takeError());
12021200
return Status();
12031201
}
12041202

12051203
Status Flush() override {
12061204
GIL takeGIL;
12071205
auto r = m_py_obj.CallMethod("flush");
12081206
if (!r)
1209-
// Cloning since the wrapped exception may still reference the PyThread.
1210-
return Status::FromError(r.takeError()).Clone();
1207+
return Status::FromError(r.takeError());
12111208
return Status();
12121209
}
12131210

@@ -1243,8 +1240,7 @@ class BinaryPythonFile : public PythonIOFile {
12431240
PyObject *pybuffer_p = PyMemoryView_FromMemory(
12441241
const_cast<char *>((const char *)buf), num_bytes, PyBUF_READ);
12451242
if (!pybuffer_p)
1246-
// Cloning since the wrapped exception may still reference the PyThread.
1247-
return Status::FromError(llvm::make_error<PythonException>()).Clone();
1243+
return Status::FromError(llvm::make_error<PythonException>());
12481244
auto pybuffer = Take<PythonObject>(pybuffer_p);
12491245
num_bytes = 0;
12501246
auto bytes_written = As<long long>(m_py_obj.CallMethod("write", pybuffer));
@@ -1264,8 +1260,7 @@ class BinaryPythonFile : public PythonIOFile {
12641260
auto pybuffer_obj =
12651261
m_py_obj.CallMethod("read", (unsigned long long)num_bytes);
12661262
if (!pybuffer_obj)
1267-
// Cloning since the wrapped exception may still reference the PyThread.
1268-
return Status::FromError(pybuffer_obj.takeError()).Clone();
1263+
return Status::FromError(pybuffer_obj.takeError());
12691264
num_bytes = 0;
12701265
if (pybuffer_obj.get().IsNone()) {
12711266
// EOF
@@ -1274,8 +1269,7 @@ class BinaryPythonFile : public PythonIOFile {
12741269
}
12751270
auto pybuffer = PythonBuffer::Create(pybuffer_obj.get());
12761271
if (!pybuffer)
1277-
// Cloning since the wrapped exception may still reference the PyThread.
1278-
return Status::FromError(pybuffer.takeError()).Clone();
1272+
return Status::FromError(pybuffer.takeError());
12791273
memcpy(buf, pybuffer.get().get().buf, pybuffer.get().get().len);
12801274
num_bytes = pybuffer.get().get().len;
12811275
return Status();
@@ -1306,8 +1300,7 @@ class TextPythonFile : public PythonIOFile {
13061300
auto bytes_written =
13071301
As<long long>(m_py_obj.CallMethod("write", pystring.get()));
13081302
if (!bytes_written)
1309-
// Cloning since the wrapped exception may still reference the PyThread.
1310-
return Status::FromError(bytes_written.takeError()).Clone();
1303+
return Status::FromError(bytes_written.takeError());
13111304
if (bytes_written.get() < 0)
13121305
return Status::FromErrorString(
13131306
".write() method returned a negative number!");
@@ -1328,16 +1321,14 @@ class TextPythonFile : public PythonIOFile {
13281321
auto pystring = As<PythonString>(
13291322
m_py_obj.CallMethod("read", (unsigned long long)num_chars));
13301323
if (!pystring)
1331-
// Cloning since the wrapped exception may still reference the PyThread.
1332-
return Status::FromError(pystring.takeError()).Clone();
1324+
return Status::FromError(pystring.takeError());
13331325
if (pystring.get().IsNone()) {
13341326
// EOF
13351327
return Status();
13361328
}
13371329
auto stringref = pystring.get().AsUTF8();
13381330
if (!stringref)
1339-
// Cloning since the wrapped exception may still reference the PyThread.
1340-
return Status::FromError(stringref.takeError()).Clone();
1331+
return Status::FromError(stringref.takeError());
13411332
num_bytes = stringref.get().size();
13421333
memcpy(buf, stringref.get().begin(), num_bytes);
13431334
return Status();

0 commit comments

Comments
 (0)