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/API/SBDebugger.cpp | |
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/API/SBDebugger.cpp')
-rw-r--r-- | lldb/source/API/SBDebugger.cpp | 52 |
1 files changed, 28 insertions, 24 deletions
diff --git a/lldb/source/API/SBDebugger.cpp b/lldb/source/API/SBDebugger.cpp index fb035a3..7250157 100644 --- a/lldb/source/API/SBDebugger.cpp +++ b/lldb/source/API/SBDebugger.cpp @@ -198,18 +198,21 @@ lldb::SBError SBDebugger::InitializeWithErrorHandling() { if (init_func(debugger_sb)) return dynlib; else - error.SetErrorString("plug-in refused to load " - "(lldb::PluginInitialize(lldb::SBDebugger) " - "returned false)"); + error = Status::FromErrorString( + "plug-in refused to load " + "(lldb::PluginInitialize(lldb::SBDebugger) " + "returned false)"); } else { - error.SetErrorString("plug-in is missing the required initialization: " - "lldb::PluginInitialize(lldb::SBDebugger)"); + error = Status::FromErrorString( + "plug-in is missing the required initialization: " + "lldb::PluginInitialize(lldb::SBDebugger)"); } } else { if (FileSystem::Instance().Exists(spec)) - error.SetErrorString("this file does not represent a loadable dylib"); + error = Status::FromErrorString( + "this file does not represent a loadable dylib"); else - error.SetErrorString("no such file"); + error = Status::FromErrorString("no such file"); } return llvm::sys::DynamicLibrary(); }; @@ -370,18 +373,18 @@ SBError SBDebugger::SetInputString(const char *data) { LLDB_INSTRUMENT_VA(this, data); SBError sb_error; if (data == nullptr) { - sb_error.SetErrorString("String data is null"); + sb_error = Status::FromErrorString("String data is null"); return sb_error; } size_t size = strlen(data); if (size == 0) { - sb_error.SetErrorString("String data is empty"); + sb_error = Status::FromErrorString("String data is empty"); return sb_error; } if (!m_opaque_sp) { - sb_error.SetErrorString("invalid debugger"); + sb_error = Status::FromErrorString("invalid debugger"); return sb_error; } @@ -397,11 +400,11 @@ SBError SBDebugger::SetInputFile(SBFile file) { SBError error; if (!m_opaque_sp) { - error.ref().SetErrorString("invalid debugger"); + error.ref() = Status::FromErrorString("invalid debugger"); return error; } if (!file) { - error.ref().SetErrorString("invalid file"); + error.ref() = Status::FromErrorString("invalid file"); return error; } m_opaque_sp->SetInputFile(file.m_opaque_sp); @@ -427,11 +430,11 @@ SBError SBDebugger::SetOutputFile(SBFile file) { LLDB_INSTRUMENT_VA(this, file); SBError error; if (!m_opaque_sp) { - error.ref().SetErrorString("invalid debugger"); + error.ref() = Status::FromErrorString("invalid debugger"); return error; } if (!file) { - error.ref().SetErrorString("invalid file"); + error.ref() = Status::FromErrorString("invalid file"); return error; } m_opaque_sp->SetOutputFile(file.m_opaque_sp); @@ -452,11 +455,11 @@ SBError SBDebugger::SetErrorFile(SBFile file) { LLDB_INSTRUMENT_VA(this, file); SBError error; if (!m_opaque_sp) { - error.ref().SetErrorString("invalid debugger"); + error.ref() = Status::FromErrorString("invalid debugger"); return error; } if (!file) { - error.ref().SetErrorString("invalid file"); + error.ref() = Status::FromErrorString("invalid file"); return error; } m_opaque_sp->SetErrorFile(file.m_opaque_sp); @@ -845,7 +848,7 @@ lldb::SBTarget SBDebugger::CreateTarget(const char *filename, if (sb_error.Success()) sb_target.SetSP(target_sp); } else { - sb_error.SetErrorString("invalid debugger"); + sb_error = Status::FromErrorString("invalid debugger"); } Log *log = GetLog(LLDBLog::API); @@ -913,7 +916,8 @@ SBTarget SBDebugger::CreateTargetWithFileAndArch(const char *filename, *m_opaque_sp, filename, arch, eLoadDependentsYes, platform_sp, target_sp); else - error.SetErrorStringWithFormat("invalid arch_cstr: %s", arch_cstr); + error = Status::FromErrorStringWithFormat("invalid arch_cstr: %s", + arch_cstr); } if (error.Success()) sb_target.SetSP(target_sp); @@ -1301,7 +1305,7 @@ SBError SBDebugger::RunREPL(lldb::LanguageType language, if (m_opaque_sp) error.ref() = m_opaque_sp->RunREPL(language, repl_options); else - error.SetErrorString("invalid debugger"); + error = Status::FromErrorString("invalid debugger"); return error; } @@ -1352,8 +1356,8 @@ SBError SBDebugger::SetInternalVariable(const char *var_name, const char *value, error = debugger_sp->SetPropertyValue(&exe_ctx, eVarSetOperationAssign, var_name, value); } else { - error.SetErrorStringWithFormat("invalid debugger instance name '%s'", - debugger_instance_name); + error = Status::FromErrorStringWithFormat( + "invalid debugger instance name '%s'", debugger_instance_name); } if (error.Fail()) sb_error.SetError(error); @@ -1521,12 +1525,12 @@ SBError SBDebugger::SetCurrentPlatform(const char *platform_name_cstr) { if (PlatformSP platform_sp = platforms.GetOrCreate(platform_name_cstr)) platforms.SetSelectedPlatform(platform_sp); else - sb_error.ref().SetErrorString("platform not found"); + sb_error.ref() = Status::FromErrorString("platform not found"); } else { - sb_error.ref().SetErrorString("invalid platform name"); + sb_error.ref() = Status::FromErrorString("invalid platform name"); } } else { - sb_error.ref().SetErrorString("invalid debugger"); + sb_error.ref() = Status::FromErrorString("invalid debugger"); } return sb_error; } |