[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:
Adrian Prantl authored and GitHub committed 2024-08-27 10:59:31 -07:00
1 parent acb33a0c9b
commit 0642cd768b
270 files changed
+3659 -3421

No files matched your search

@@ -48,7 +48,8 @@ Status ScriptedPythonInterface::ExtractValueFromPythonObject<Status>(
if (lldb::SBError *sb_error = reinterpret_cast<lldb::SBError *>(
python::LLDBSWIGPython_CastPyObjectToSBError(p.get())))
return m_interpreter.GetStatusFromSBError(*sb_error);
error.SetErrorString("Couldn't cast lldb::SBError to lldb::Status.");
error =
Status::FromErrorString("Couldn't cast lldb::SBError to lldb::Status.");
return {};
}
@@ -59,7 +60,8 @@ Event *ScriptedPythonInterface::ExtractValueFromPythonObject<Event *>(
if (lldb::SBEvent *sb_event = reinterpret_cast<lldb::SBEvent *>(
python::LLDBSWIGPython_CastPyObjectToSBEvent(p.get())))
return m_interpreter.GetOpaqueTypeFromSBEvent(*sb_event);
error.SetErrorString("Couldn't cast lldb::SBEvent to lldb_private::Event.");
error = Status::FromErrorString(
"Couldn't cast lldb::SBEvent to lldb_private::Event.");
return nullptr;
}
@@ -71,7 +73,8 @@ ScriptedPythonInterface::ExtractValueFromPythonObject<lldb::StreamSP>(
if (lldb::SBStream *sb_stream = reinterpret_cast<lldb::SBStream *>(
python::LLDBSWIGPython_CastPyObjectToSBStream(p.get())))
return m_interpreter.GetOpaqueTypeFromSBStream(*sb_stream);
error.SetErrorString("Couldn't cast lldb::SBStream to lldb_private::Stream.");
error = Status::FromErrorString(
"Couldn't cast lldb::SBStream to lldb_private::Stream.");
return nullptr;
}
@@ -84,7 +87,7 @@ ScriptedPythonInterface::ExtractValueFromPythonObject<lldb::DataExtractorSP>(
python::LLDBSWIGPython_CastPyObjectToSBData(p.get()));
if (!sb_data) {
error.SetErrorString(
error = Status::FromErrorStringWithFormat(
"Couldn't cast lldb::SBData to lldb::DataExtractorSP.");
return nullptr;
}
@@ -100,7 +103,7 @@ ScriptedPythonInterface::ExtractValueFromPythonObject<lldb::BreakpointSP>(
python::LLDBSWIGPython_CastPyObjectToSBBreakpoint(p.get()));
if (!sb_breakpoint) {
error.SetErrorString(
error = Status::FromErrorStringWithFormat(
"Couldn't cast lldb::SBBreakpoint to lldb::BreakpointSP.");
return nullptr;
}
@@ -115,7 +118,7 @@ lldb::ProcessAttachInfoSP ScriptedPythonInterface::ExtractValueFromPythonObject<
python::LLDBSWIGPython_CastPyObjectToSBAttachInfo(p.get()));
if (!sb_attach_info) {
error.SetErrorString(
error = Status::FromErrorStringWithFormat(
"Couldn't cast lldb::SBAttachInfo to lldb::ProcessAttachInfoSP.");
return nullptr;
}
@@ -130,7 +133,7 @@ lldb::ProcessLaunchInfoSP ScriptedPythonInterface::ExtractValueFromPythonObject<
python::LLDBSWIGPython_CastPyObjectToSBLaunchInfo(p.get()));
if (!sb_launch_info) {
error.SetErrorString(
error = Status::FromErrorStringWithFormat(
"Couldn't cast lldb::SBLaunchInfo to lldb::ProcessLaunchInfoSP.");
return nullptr;
}
@@ -148,7 +151,7 @@ ScriptedPythonInterface::ExtractValueFromPythonObject<
python::LLDBSWIGPython_CastPyObjectToSBMemoryRegionInfo(p.get()));
if (!sb_mem_reg_info) {
error.SetErrorString(
error = Status::FromErrorStringWithFormat(
"Couldn't cast lldb::SBMemoryRegionInfo to lldb::MemoryRegionInfoSP.");
return {};
}