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/SBThread.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/SBThread.cpp')
-rw-r--r-- | lldb/source/API/SBThread.cpp | 70 |
1 files changed, 36 insertions, 34 deletions
diff --git a/lldb/source/API/SBThread.cpp b/lldb/source/API/SBThread.cpp index 140a292..9286813 100644 --- a/lldb/source/API/SBThread.cpp +++ b/lldb/source/API/SBThread.cpp @@ -499,13 +499,13 @@ SBError SBThread::ResumeNewPlan(ExecutionContext &exe_ctx, Process *process = exe_ctx.GetProcessPtr(); if (!process) { - sb_error.SetErrorString("No process in SBThread::ResumeNewPlan"); + sb_error = Status::FromErrorString("No process in SBThread::ResumeNewPlan"); return sb_error; } Thread *thread = exe_ctx.GetThreadPtr(); if (!thread) { - sb_error.SetErrorString("No thread in SBThread::ResumeNewPlan"); + sb_error = Status::FromErrorString("No thread in SBThread::ResumeNewPlan"); return sb_error; } @@ -541,7 +541,7 @@ void SBThread::StepOver(lldb::RunMode stop_other_threads, SBError &error) { ExecutionContext exe_ctx(m_opaque_sp.get(), lock); if (!exe_ctx.HasThreadScope()) { - error.SetErrorString("this SBThread object is invalid"); + error = Status::FromErrorString("this SBThread object is invalid"); return; } @@ -588,7 +588,7 @@ void SBThread::StepInto(const char *target_name, uint32_t end_line, ExecutionContext exe_ctx(m_opaque_sp.get(), lock); if (!exe_ctx.HasThreadScope()) { - error.SetErrorString("this SBThread object is invalid"); + error = Status::FromErrorString("this SBThread object is invalid"); return; } @@ -625,7 +625,7 @@ void SBThread::StepInto(const char *target_name, uint32_t end_line, if (new_plan_status.Success()) error = ResumeNewPlan(exe_ctx, new_plan_sp.get()); else - error.SetErrorString(new_plan_status.AsCString()); + error = Status::FromErrorString(new_plan_status.AsCString()); } void SBThread::StepOut() { @@ -642,7 +642,7 @@ void SBThread::StepOut(SBError &error) { ExecutionContext exe_ctx(m_opaque_sp.get(), lock); if (!exe_ctx.HasThreadScope()) { - error.SetErrorString("this SBThread object is invalid"); + error = Status::FromErrorString("this SBThread object is invalid"); return; } @@ -660,7 +660,7 @@ void SBThread::StepOut(SBError &error) { if (new_plan_status.Success()) error = ResumeNewPlan(exe_ctx, new_plan_sp.get()); else - error.SetErrorString(new_plan_status.AsCString()); + error = Status::FromErrorString(new_plan_status.AsCString()); } void SBThread::StepOutOfFrame(SBFrame &sb_frame) { @@ -677,14 +677,14 @@ void SBThread::StepOutOfFrame(SBFrame &sb_frame, SBError &error) { ExecutionContext exe_ctx(m_opaque_sp.get(), lock); if (!sb_frame.IsValid()) { - error.SetErrorString("passed invalid SBFrame object"); + error = Status::FromErrorString("passed invalid SBFrame object"); return; } StackFrameSP frame_sp(sb_frame.GetFrameSP()); if (!exe_ctx.HasThreadScope()) { - error.SetErrorString("this SBThread object is invalid"); + error = Status::FromErrorString("this SBThread object is invalid"); return; } @@ -692,7 +692,7 @@ void SBThread::StepOutOfFrame(SBFrame &sb_frame, SBError &error) { bool stop_other_threads = false; Thread *thread = exe_ctx.GetThreadPtr(); if (sb_frame.GetThread().GetThreadID() != thread->GetID()) { - error.SetErrorString("passed a frame from another thread"); + error = Status::FromErrorString("passed a frame from another thread"); return; } @@ -704,7 +704,7 @@ void SBThread::StepOutOfFrame(SBFrame &sb_frame, SBError &error) { if (new_plan_status.Success()) error = ResumeNewPlan(exe_ctx, new_plan_sp.get()); else - error.SetErrorString(new_plan_status.AsCString()); + error = Status::FromErrorString(new_plan_status.AsCString()); } void SBThread::StepInstruction(bool step_over) { @@ -721,7 +721,7 @@ void SBThread::StepInstruction(bool step_over, SBError &error) { ExecutionContext exe_ctx(m_opaque_sp.get(), lock); if (!exe_ctx.HasThreadScope()) { - error.SetErrorString("this SBThread object is invalid"); + error = Status::FromErrorString("this SBThread object is invalid"); return; } @@ -733,7 +733,7 @@ void SBThread::StepInstruction(bool step_over, SBError &error) { if (new_plan_status.Success()) error = ResumeNewPlan(exe_ctx, new_plan_sp.get()); else - error.SetErrorString(new_plan_status.AsCString()); + error = Status::FromErrorString(new_plan_status.AsCString()); } void SBThread::RunToAddress(lldb::addr_t addr) { @@ -750,7 +750,7 @@ void SBThread::RunToAddress(lldb::addr_t addr, SBError &error) { ExecutionContext exe_ctx(m_opaque_sp.get(), lock); if (!exe_ctx.HasThreadScope()) { - error.SetErrorString("this SBThread object is invalid"); + error = Status::FromErrorString("this SBThread object is invalid"); return; } @@ -768,7 +768,7 @@ void SBThread::RunToAddress(lldb::addr_t addr, SBError &error) { if (new_plan_status.Success()) error = ResumeNewPlan(exe_ctx, new_plan_sp.get()); else - error.SetErrorString(new_plan_status.AsCString()); + error = Status::FromErrorString(new_plan_status.AsCString()); } SBError SBThread::StepOverUntil(lldb::SBFrame &sb_frame, @@ -788,7 +788,7 @@ SBError SBThread::StepOverUntil(lldb::SBFrame &sb_frame, Thread *thread = exe_ctx.GetThreadPtr(); if (line == 0) { - sb_error.SetErrorString("invalid line argument"); + sb_error = Status::FromErrorString("invalid line argument"); return sb_error; } @@ -804,7 +804,7 @@ SBError SBThread::StepOverUntil(lldb::SBFrame &sb_frame, SymbolContext frame_sc; if (!frame_sp) { - sb_error.SetErrorString("no valid frames in thread to step"); + sb_error = Status::FromErrorString("no valid frames in thread to step"); return sb_error; } @@ -814,7 +814,7 @@ SBError SBThread::StepOverUntil(lldb::SBFrame &sb_frame, eSymbolContextLineEntry | eSymbolContextSymbol); if (frame_sc.comp_unit == nullptr) { - sb_error.SetErrorStringWithFormat( + sb_error = Status::FromErrorStringWithFormat( "frame %u doesn't have debug information", frame_sp->GetFrameIndex()); return sb_error; } @@ -827,7 +827,8 @@ SBError SBThread::StepOverUntil(lldb::SBFrame &sb_frame, if (frame_sc.line_entry.IsValid()) step_file_spec = frame_sc.line_entry.GetFile(); else { - sb_error.SetErrorString("invalid file argument or no file for frame"); + sb_error = Status::FromErrorString( + "invalid file argument or no file for frame"); return sb_error; } } @@ -865,10 +866,11 @@ SBError SBThread::StepOverUntil(lldb::SBFrame &sb_frame, if (step_over_until_addrs.empty()) { if (all_in_function) { step_file_spec.GetPath(path, sizeof(path)); - sb_error.SetErrorStringWithFormat("No line entries for %s:%u", path, - line); + sb_error = Status::FromErrorStringWithFormat( + "No line entries for %s:%u", path, line); } else - sb_error.SetErrorString("step until target not in current function"); + sb_error = Status::FromErrorString( + "step until target not in current function"); } else { Status new_plan_status; ThreadPlanSP new_plan_sp(thread->QueueThreadPlanForStepUntil( @@ -879,10 +881,10 @@ SBError SBThread::StepOverUntil(lldb::SBFrame &sb_frame, if (new_plan_status.Success()) sb_error = ResumeNewPlan(exe_ctx, new_plan_sp.get()); else - sb_error.SetErrorString(new_plan_status.AsCString()); + sb_error = Status::FromErrorString(new_plan_status.AsCString()); } } else { - sb_error.SetErrorString("this SBThread object is invalid"); + sb_error = Status::FromErrorString("this SBThread object is invalid"); } return sb_error; } @@ -913,7 +915,7 @@ SBError SBThread::StepUsingScriptedThreadPlan(const char *script_class_name, ExecutionContext exe_ctx(m_opaque_sp.get(), lock); if (!exe_ctx.HasThreadScope()) { - error.SetErrorString("this SBThread object is invalid"); + error = Status::FromErrorString("this SBThread object is invalid"); return error; } @@ -925,7 +927,7 @@ SBError SBThread::StepUsingScriptedThreadPlan(const char *script_class_name, false, script_class_name, obj_sp, false, new_plan_status); if (new_plan_status.Fail()) { - error.SetErrorString(new_plan_status.AsCString()); + error = Status::FromErrorString(new_plan_status.AsCString()); return error; } @@ -935,7 +937,7 @@ SBError SBThread::StepUsingScriptedThreadPlan(const char *script_class_name, if (new_plan_status.Success()) error = ResumeNewPlan(exe_ctx, new_plan_sp.get()); else - error.SetErrorString(new_plan_status.AsCString()); + error = Status::FromErrorString(new_plan_status.AsCString()); return error; } @@ -949,7 +951,7 @@ SBError SBThread::JumpToLine(lldb::SBFileSpec &file_spec, uint32_t line) { ExecutionContext exe_ctx(m_opaque_sp.get(), lock); if (!exe_ctx.HasThreadScope()) { - sb_error.SetErrorString("this SBThread object is invalid"); + sb_error = Status::FromErrorString("this SBThread object is invalid"); return sb_error; } @@ -1015,10 +1017,10 @@ bool SBThread::Suspend(SBError &error) { exe_ctx.GetThreadPtr()->SetResumeState(eStateSuspended); result = true; } else { - error.SetErrorString("process is running"); + error = Status::FromErrorString("process is running"); } } else - error.SetErrorString("this SBThread object is invalid"); + error = Status::FromErrorString("this SBThread object is invalid"); return result; } @@ -1043,10 +1045,10 @@ bool SBThread::Resume(SBError &error) { exe_ctx.GetThreadPtr()->SetResumeState(eStateRunning, override_suspend); result = true; } else { - error.SetErrorString("process is running"); + error = Status::FromErrorString("process is running"); } } else - error.SetErrorString("this SBThread object is invalid"); + error = Status::FromErrorString("this SBThread object is invalid"); return result; } @@ -1245,7 +1247,7 @@ SBError SBThread::GetDescriptionWithFormat(const SBFormat &format, SBError error; if (!format) { - error.SetErrorString("The provided SBFormat object is invalid"); + error = Status::FromErrorString("The provided SBFormat object is invalid"); return error; } @@ -1259,7 +1261,7 @@ SBError SBThread::GetDescriptionWithFormat(const SBFormat &format, } } - error.SetErrorStringWithFormat( + error = Status::FromErrorStringWithFormat( "It was not possible to generate a thread description with the given " "format string '%s'", format.GetFormatEntrySP()->string.c_str()); |