Skip to content

Commit 8789c96

Browse files
[lldb] Unify implementation of CommandReturnObject::SetError(NFC) (#110707)
This is a cleanup that moves the API towards value semantics.
1 parent b50ce4c commit 8789c96

9 files changed

+17
-19
lines changed

lldb/include/lldb/Interpreter/CommandReturnObject.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ class CommandReturnObject {
131131
AppendError(llvm::formatv(format, std::forward<Args>(args)...).str());
132132
}
133133

134-
void SetError(const Status &error, const char *fallback_error_cstr = nullptr);
134+
void SetError(Status error);
135135

136136
void SetError(llvm::Error error);
137137

lldb/source/API/SBCommandReturnObject.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -326,10 +326,10 @@ void SBCommandReturnObject::SetError(lldb::SBError &error,
326326
const char *fallback_error_cstr) {
327327
LLDB_INSTRUMENT_VA(this, error, fallback_error_cstr);
328328

329-
if (error.IsValid())
330-
ref().SetError(error.ref(), fallback_error_cstr);
329+
if (error.IsValid() && !error.Fail())
330+
ref().SetError(error.ref().Clone());
331331
else if (fallback_error_cstr)
332-
ref().SetError(Status(), fallback_error_cstr);
332+
ref().SetError(Status::FromErrorString(fallback_error_cstr));
333333
}
334334

335335
void SBCommandReturnObject::SetError(const char *error_cstr) {

lldb/source/Commands/CommandObjectBreakpointCommand.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ are no syntax errors may indicate that a function was declared but never called.
389389
m_bp_options_vec, result);
390390
}
391391
if (!error.Success())
392-
result.SetError(error);
392+
result.SetError(std::move(error));
393393
} else {
394394
// Special handling for one-liner specified inline.
395395
if (m_options.m_use_one_liner)

lldb/source/Commands/CommandObjectDWIMPrint.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ void CommandObjectDWIMPrint::DoExecute(StringRef command,
202202
// If the expression failed, return an error.
203203
if (expr_result != eExpressionCompleted) {
204204
if (valobj_sp)
205-
result.SetError(valobj_sp->GetError());
205+
result.SetError(valobj_sp->GetError().Clone());
206206
else
207207
result.AppendErrorWithFormatv(
208208
"unknown error evaluating expression `{0}`", expr);

lldb/source/Commands/CommandObjectExpression.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -647,8 +647,8 @@ void CommandObjectExpression::DoExecute(llvm::StringRef command,
647647
initialize = true;
648648
repl_sp = target.GetREPL(repl_error, m_command_options.language,
649649
nullptr, true);
650-
if (!repl_error.Success()) {
651-
result.SetError(repl_error);
650+
if (repl_error.Fail()) {
651+
result.SetError(std::move(repl_error));
652652
return;
653653
}
654654
}
@@ -668,7 +668,7 @@ void CommandObjectExpression::DoExecute(llvm::StringRef command,
668668
repl_error = Status::FromErrorStringWithFormat(
669669
"Couldn't create a REPL for %s",
670670
Language::GetNameForLanguageType(m_command_options.language));
671-
result.SetError(repl_error);
671+
result.SetError(std::move(repl_error));
672672
return;
673673
}
674674
}

lldb/source/Commands/CommandObjectMemoryTag.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ class CommandObjectMemoryTagWrite : public CommandObjectParsed {
290290
tagged_range->GetByteSize(), tags);
291291

292292
if (status.Fail()) {
293-
result.SetError(status);
293+
result.SetError(std::move(status));
294294
return;
295295
}
296296

lldb/source/Commands/CommandObjectTarget.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2775,7 +2775,7 @@ class CommandObjectTargetModulesAdd : public CommandObjectParsed {
27752775
result.AppendErrorWithFormat(
27762776
"Unable to locate the executable or symbol file with UUID %s",
27772777
strm.GetData());
2778-
result.SetError(error);
2778+
result.SetError(std::move(error));
27792779
return;
27802780
}
27812781
} else {
@@ -4409,7 +4409,7 @@ class CommandObjectTargetSymbolsAdd : public CommandObjectParsed {
44094409
return AddModuleSymbols(m_exe_ctx.GetTargetPtr(), module_spec, flush,
44104410
result);
44114411
} else {
4412-
result.SetError(error);
4412+
result.SetError(std::move(error));
44134413
}
44144414
return false;
44154415
}

lldb/source/Commands/CommandObjectThread.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ class CommandObjectThreadStepWithTypeAndScope : public CommandObjectParsed {
622622
result.SetStatus(eReturnStatusSuccessContinuingNoResult);
623623
}
624624
} else {
625-
result.SetError(new_plan_status);
625+
result.SetError(std::move(new_plan_status));
626626
}
627627
}
628628

@@ -1046,7 +1046,7 @@ class CommandObjectThreadUntil : public CommandObjectParsed {
10461046
new_plan_sp->SetIsControllingPlan(true);
10471047
new_plan_sp->SetOkayToDiscard(false);
10481048
} else {
1049-
result.SetError(new_plan_status);
1049+
result.SetError(std::move(new_plan_status));
10501050
return;
10511051
}
10521052
} else {
@@ -1734,7 +1734,7 @@ class CommandObjectThreadJump : public CommandObjectParsed {
17341734
Status err = thread->JumpToLine(file, line, m_options.m_force, &warnings);
17351735

17361736
if (err.Fail()) {
1737-
result.SetError(err);
1737+
result.SetError(std::move(err));
17381738
return;
17391739
}
17401740

lldb/source/Interpreter/CommandReturnObject.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,8 @@ void CommandReturnObject::AppendError(llvm::StringRef in_string) {
107107
error(GetErrorStream()) << msg << '\n';
108108
}
109109

110-
void CommandReturnObject::SetError(const Status &error,
111-
const char *fallback_error_cstr) {
112-
if (error.Fail())
113-
AppendError(error.AsCString(fallback_error_cstr));
110+
void CommandReturnObject::SetError(Status error) {
111+
SetError(error.takeError());
114112
}
115113

116114
void CommandReturnObject::SetError(llvm::Error error) {

0 commit comments

Comments
 (0)