[lldb] Turn lldb_private::Status into a value type. (#106163)
This patch removes all of the Set.* methods from Status. This cleanup is part of a series of patches that make it harder use the anti-pattern of keeping a long-lives Status object around and updating it while dropping any errors it contains on the floor. This patch is largely NFC, the more interesting next steps this enables is to: 1. remove Status.Clear() 2. assert that Status::operator=() never overwrites an error 3. remove Status::operator=() Note that step (2) will bring 90% of the benefits for users, and step (3) will dramatically clean up the error handling code in various places. In the end my goal is to convert all APIs that are of the form ` ResultTy DoFoo(Status& error) ` to ` llvm::Expected<ResultTy> DoFoo() ` How to read this patch? The interesting changes are in Status.h and Status.cpp, all other changes are mostly ` perl -pi -e 's/\.SetErrorString/ = Status::FromErrorString/g' $(git grep -l SetErrorString lldb/source) ` plus the occasional manual cleanup.
This commit is contained in:
@@ -81,8 +81,8 @@ ScriptedProcess::ScriptedProcess(lldb::TargetSP target_sp,
|
||||
: Process(target_sp, listener_sp), m_scripted_metadata(scripted_metadata) {
|
||||
|
||||
if (!target_sp) {
|
||||
error.SetErrorStringWithFormat("ScriptedProcess::%s () - ERROR: %s",
|
||||
__FUNCTION__, "Invalid target");
|
||||
error = Status::FromErrorStringWithFormat(
|
||||
"ScriptedProcess::%s () - ERROR: %s", __FUNCTION__, "Invalid target");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -90,16 +90,16 @@ ScriptedProcess::ScriptedProcess(lldb::TargetSP target_sp,
|
||||
target_sp->GetDebugger().GetScriptInterpreter();
|
||||
|
||||
if (!interpreter) {
|
||||
error.SetErrorStringWithFormat("ScriptedProcess::%s () - ERROR: %s",
|
||||
__FUNCTION__,
|
||||
"Debugger has no Script Interpreter");
|
||||
error = Status::FromErrorStringWithFormat(
|
||||
"ScriptedProcess::%s () - ERROR: %s", __FUNCTION__,
|
||||
"Debugger has no Script Interpreter");
|
||||
return;
|
||||
}
|
||||
|
||||
// Create process instance interface
|
||||
m_interface_up = interpreter->CreateScriptedProcessInterface();
|
||||
if (!m_interface_up) {
|
||||
error.SetErrorStringWithFormat(
|
||||
error = Status::FromErrorStringWithFormat(
|
||||
"ScriptedProcess::%s () - ERROR: %s", __FUNCTION__,
|
||||
"Script interpreter couldn't create Scripted Process Interface");
|
||||
return;
|
||||
@@ -114,16 +114,16 @@ ScriptedProcess::ScriptedProcess(lldb::TargetSP target_sp,
|
||||
|
||||
if (!obj_or_err) {
|
||||
llvm::consumeError(obj_or_err.takeError());
|
||||
error.SetErrorString("Failed to create script object.");
|
||||
error = Status::FromErrorString("Failed to create script object.");
|
||||
return;
|
||||
}
|
||||
|
||||
StructuredData::GenericSP object_sp = *obj_or_err;
|
||||
|
||||
if (!object_sp || !object_sp->IsValid()) {
|
||||
error.SetErrorStringWithFormat("ScriptedProcess::%s () - ERROR: %s",
|
||||
__FUNCTION__,
|
||||
"Failed to create valid script object");
|
||||
error = Status::FromErrorStringWithFormat(
|
||||
"ScriptedProcess::%s () - ERROR: %s", __FUNCTION__,
|
||||
"Failed to create valid script object");
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -270,7 +270,8 @@ Status ScriptedProcess::EnableBreakpointSite(BreakpointSite *bp_site) {
|
||||
}
|
||||
|
||||
if (bp_site->HardwareRequired()) {
|
||||
return Status("Scripted Processes don't support hardware breakpoints");
|
||||
return Status::FromErrorString(
|
||||
"Scripted Processes don't support hardware breakpoints");
|
||||
}
|
||||
|
||||
Status error;
|
||||
|
||||
Reference in New Issue
Block a user