mirror of
https://github.com/intel/llvm.git
synced 2026-01-14 03:50:17 +08:00
[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:
@@ -298,7 +298,7 @@ ObjectFile *Module::GetMemoryObjectFile(const lldb::ProcessSP &process_sp,
|
||||
lldb::addr_t header_addr, Status &error,
|
||||
size_t size_to_read) {
|
||||
if (m_objfile_sp) {
|
||||
error.SetErrorString("object file already exists");
|
||||
error = Status::FromErrorString("object file already exists");
|
||||
} else {
|
||||
std::lock_guard<std::recursive_mutex> guard(m_mutex);
|
||||
if (process_sp) {
|
||||
@@ -330,14 +330,15 @@ ObjectFile *Module::GetMemoryObjectFile(const lldb::ProcessSP &process_sp,
|
||||
|
||||
m_unwind_table.ModuleWasUpdated();
|
||||
} else {
|
||||
error.SetErrorString("unable to find suitable object file plug-in");
|
||||
error = Status::FromErrorString(
|
||||
"unable to find suitable object file plug-in");
|
||||
}
|
||||
} else {
|
||||
error.SetErrorStringWithFormat("unable to read header from memory: %s",
|
||||
readmem_error.AsCString());
|
||||
error = Status::FromErrorStringWithFormat(
|
||||
"unable to read header from memory: %s", readmem_error.AsCString());
|
||||
}
|
||||
} else {
|
||||
error.SetErrorString("invalid process");
|
||||
error = Status::FromErrorString("invalid process");
|
||||
}
|
||||
}
|
||||
return m_objfile_sp.get();
|
||||
@@ -1427,7 +1428,7 @@ bool Module::IsLoadedInTarget(Target *target) {
|
||||
bool Module::LoadScriptingResourceInTarget(Target *target, Status &error,
|
||||
Stream &feedback_stream) {
|
||||
if (!target) {
|
||||
error.SetErrorString("invalid destination Target");
|
||||
error = Status::FromErrorString("invalid destination Target");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1444,7 +1445,7 @@ bool Module::LoadScriptingResourceInTarget(Target *target, Status &error,
|
||||
PlatformSP platform_sp(target->GetPlatform());
|
||||
|
||||
if (!platform_sp) {
|
||||
error.SetErrorString("invalid Platform");
|
||||
error = Status::FromErrorString("invalid Platform");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1482,7 +1483,7 @@ bool Module::LoadScriptingResourceInTarget(Target *target, Status &error,
|
||||
}
|
||||
}
|
||||
} else {
|
||||
error.SetErrorString("invalid ScriptInterpreter");
|
||||
error = Status::FromErrorString("invalid ScriptInterpreter");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user