aboutsummaryrefslogtreecommitdiff
path: root/lldb/source/Expression/IRExecutionUnit.cpp
diff options
context:
space:
mode:
authorAdrian Prantl <aprantl@apple.com>2024-08-27 10:59:31 -0700
committerGitHub <noreply@github.com>2024-08-27 10:59:31 -0700
commit0642cd768b80665585c8500bed2933a3b99123dc (patch)
treea412a5eafff54ef9a7cb884e01907a4f521f5140 /lldb/source/Expression/IRExecutionUnit.cpp
parentacb33a0c9bc902dc1aef703c02b8fd3a1132cb14 (diff)
downloadllvm-0642cd768b80665585c8500bed2933a3b99123dc.tar.gz
llvm-0642cd768b80665585c8500bed2933a3b99123dc.tar.bz2
llvm-0642cd768b80665585c8500bed2933a3b99123dc.zip
[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.
Diffstat (limited to 'lldb/source/Expression/IRExecutionUnit.cpp')
-rw-r--r--lldb/source/Expression/IRExecutionUnit.cpp43
1 files changed, 17 insertions, 26 deletions
diff --git a/lldb/source/Expression/IRExecutionUnit.cpp b/lldb/source/Expression/IRExecutionUnit.cpp
index f22070442362..d2f2ee26fd43 100644
--- a/lldb/source/Expression/IRExecutionUnit.cpp
+++ b/lldb/source/Expression/IRExecutionUnit.cpp
@@ -120,9 +120,8 @@ Status IRExecutionUnit::DisassembleFunction(Stream &stream,
}
if (func_local_addr == LLDB_INVALID_ADDRESS) {
- ret.SetErrorToGenericError();
- ret.SetErrorStringWithFormat("Couldn't find function %s for disassembly",
- m_name.AsCString());
+ ret = Status::FromErrorStringWithFormat(
+ "Couldn't find function %s for disassembly", m_name.AsCString());
return ret;
}
@@ -136,9 +135,8 @@ Status IRExecutionUnit::DisassembleFunction(Stream &stream,
func_range = GetRemoteRangeForLocal(func_local_addr);
if (func_range.first == 0 && func_range.second == 0) {
- ret.SetErrorToGenericError();
- ret.SetErrorStringWithFormat("Couldn't find code range for function %s",
- m_name.AsCString());
+ ret = Status::FromErrorStringWithFormat(
+ "Couldn't find code range for function %s", m_name.AsCString());
return ret;
}
@@ -147,8 +145,7 @@ Status IRExecutionUnit::DisassembleFunction(Stream &stream,
Target *target = exe_ctx.GetTargetPtr();
if (!target) {
- ret.SetErrorToGenericError();
- ret.SetErrorString("Couldn't find the target");
+ ret = Status::FromErrorString("Couldn't find the target");
return ret;
}
@@ -161,9 +158,8 @@ Status IRExecutionUnit::DisassembleFunction(Stream &stream,
buffer_sp->GetByteSize(), err);
if (!err.Success()) {
- ret.SetErrorToGenericError();
- ret.SetErrorStringWithFormat("Couldn't read from process: %s",
- err.AsCString("unknown error"));
+ ret = Status::FromErrorStringWithFormat("Couldn't read from process: %s",
+ err.AsCString("unknown error"));
return ret;
}
@@ -175,16 +171,14 @@ Status IRExecutionUnit::DisassembleFunction(Stream &stream,
Disassembler::FindPlugin(arch, flavor_string, plugin_name);
if (!disassembler_sp) {
- ret.SetErrorToGenericError();
- ret.SetErrorStringWithFormat(
+ ret = Status::FromErrorStringWithFormat(
"Unable to find disassembler plug-in for %s architecture.",
arch.GetArchitectureName());
return ret;
}
if (!process) {
- ret.SetErrorToGenericError();
- ret.SetErrorString("Couldn't find the process");
+ ret = Status::FromErrorString("Couldn't find the process");
return ret;
}
@@ -215,8 +209,7 @@ struct IRExecDiagnosticHandler : public llvm::DiagnosticHandler {
if (DI.getSeverity() == llvm::DS_Error) {
const auto &DISM = llvm::cast<llvm::DiagnosticInfoSrcMgr>(DI);
if (err && err->Success()) {
- err->SetErrorToGenericError();
- err->SetErrorStringWithFormat(
+ *err = Status::FromErrorStringWithFormat(
"IRExecution error: %s",
DISM.getSMDiag().getMessage().str().c_str());
}
@@ -241,9 +234,9 @@ void IRExecutionUnit::GetRunnableInfo(Status &error, lldb::addr_t &func_addr,
func_end = LLDB_INVALID_ADDRESS;
if (!process_sp) {
- error.SetErrorToGenericError();
- error.SetErrorString("Couldn't write the JIT compiled code into the "
- "process because the process is invalid");
+ error =
+ Status::FromErrorString("Couldn't write the JIT compiled code into the "
+ "process because the process is invalid");
return;
}
@@ -299,9 +292,8 @@ void IRExecutionUnit::GetRunnableInfo(Status &error, lldb::addr_t &func_addr,
m_execution_engine_up.reset(builder.create(target_machine));
if (!m_execution_engine_up) {
- error.SetErrorToGenericError();
- error.SetErrorStringWithFormat("Couldn't JIT the function: %s",
- error_string.c_str());
+ error = Status::FromErrorStringWithFormat("Couldn't JIT the function: %s",
+ error_string.c_str());
return;
}
@@ -364,8 +356,7 @@ void IRExecutionUnit::GetRunnableInfo(Status &error, lldb::addr_t &func_addr,
}
if (!fun_ptr) {
- error.SetErrorToGenericError();
- error.SetErrorStringWithFormat(
+ error = Status::FromErrorStringWithFormat(
"'%s' was in the JITted module but wasn't lowered",
function.getName().str().c_str());
return;
@@ -434,7 +425,7 @@ void IRExecutionUnit::GetRunnableInfo(Status &error, lldb::addr_t &func_addr,
ss.PutCString(
"\nHint: The expression tried to call a function that is not present "
"in the target, perhaps because it was optimized out by the compiler.");
- error.SetErrorString(ss.GetString());
+ error = Status(ss.GetString().str());
return;
}