diff options
author | Adrian Prantl <aprantl@apple.com> | 2024-08-27 10:59:31 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-27 10:59:31 -0700 |
commit | 0642cd768b80665585c8500bed2933a3b99123dc (patch) | |
tree | a412a5eafff54ef9a7cb884e01907a4f521f5140 /lldb/source/Plugins/ScriptInterpreter/Python/Interfaces | |
parent | acb33a0c9bc902dc1aef703c02b8fd3a1132cb14 (diff) | |
download | llvm-0642cd768b80665585c8500bed2933a3b99123dc.zip llvm-0642cd768b80665585c8500bed2933a3b99123dc.tar.gz llvm-0642cd768b80665585c8500bed2933a3b99123dc.tar.bz2 |
[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/Plugins/ScriptInterpreter/Python/Interfaces')
-rw-r--r-- | lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.cpp | 19 | ||||
-rw-r--r-- | lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.h | 7 |
2 files changed, 14 insertions, 12 deletions
diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.cpp index 699412e..a8e1d09 100644 --- a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.cpp +++ b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.cpp @@ -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 {}; } diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.h b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.h index e1a3156..cbb6cd4 100644 --- a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.h +++ b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.h @@ -269,7 +269,7 @@ protected: transformed_args); if (llvm::Error e = expected_return_object.takeError()) { - error.SetErrorString(llvm::toString(std::move(e)).c_str()); + error = Status(std::move(e)); return ErrorWithMessage<T>(caller_signature, "Python method could not be called.", error); } @@ -368,9 +368,8 @@ protected: if (boolean_arg.IsValid()) original_arg = boolean_arg.GetValue(); else - error.SetErrorString( - llvm::formatv("{}: Invalid boolean argument.", LLVM_PRETTY_FUNCTION) - .str()); + error = Status::FromErrorStringWithFormatv( + "{}: Invalid boolean argument.", LLVM_PRETTY_FUNCTION); } template <std::size_t... I, typename... Args> |