Skip to content

Commit 61daa29

Browse files
committed
[lldb] Unify implementation of CommandReturnObject::SetError(NFC) (llvm#110707)
This is a cleanup that moves the API towards value semantics. (cherry picked from commit 8789c96)
1 parent 8a50c39 commit 61daa29

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
@@ -241,7 +241,7 @@ void CommandObjectDWIMPrint::DoExecute(StringRef command,
241241
// If the expression failed, return an error.
242242
if (expr_result != eExpressionCompleted) {
243243
if (valobj_sp)
244-
result.SetError(valobj_sp->GetError());
244+
result.SetError(valobj_sp->GetError().Clone());
245245
else
246246
result.AppendErrorWithFormatv(
247247
"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
@@ -697,8 +697,8 @@ void CommandObjectExpression::DoExecute(llvm::StringRef command,
697697
initialize = true;
698698
repl_sp = target.GetREPL(repl_error, m_command_options.language,
699699
nullptr, true);
700-
if (!repl_error.Success()) {
701-
result.SetError(repl_error);
700+
if (repl_error.Fail()) {
701+
result.SetError(std::move(repl_error));
702702
return;
703703
}
704704
}
@@ -718,7 +718,7 @@ void CommandObjectExpression::DoExecute(llvm::StringRef command,
718718
repl_error = Status::FromErrorStringWithFormat(
719719
"Couldn't create a REPL for %s",
720720
Language::GetNameForLanguageType(m_command_options.language));
721-
result.SetError(repl_error);
721+
result.SetError(std::move(repl_error));
722722
return;
723723
}
724724
}

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
@@ -2776,7 +2776,7 @@ class CommandObjectTargetModulesAdd : public CommandObjectParsed {
27762776
result.AppendErrorWithFormat(
27772777
"Unable to locate the executable or symbol file with UUID %s",
27782778
strm.GetData());
2779-
result.SetError(error);
2779+
result.SetError(std::move(error));
27802780
return;
27812781
}
27822782
} else {
@@ -4425,7 +4425,7 @@ class CommandObjectTargetSymbolsAdd : public CommandObjectParsed {
44254425
return AddModuleSymbols(m_exe_ctx.GetTargetPtr(), module_spec, flush,
44264426
result);
44274427
} else {
4428-
result.SetError(error);
4428+
result.SetError(std::move(error));
44294429
}
44304430
return false;
44314431
}

lldb/source/Commands/CommandObjectThread.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ class CommandObjectThreadStepWithTypeAndScope : public CommandObjectParsed {
626626
result.SetStatus(eReturnStatusSuccessContinuingNoResult);
627627
}
628628
} else {
629-
result.SetError(new_plan_status);
629+
result.SetError(std::move(new_plan_status));
630630
}
631631
}
632632

@@ -1051,7 +1051,7 @@ class CommandObjectThreadUntil : public CommandObjectParsed {
10511051
new_plan_sp->SetIsControllingPlan(true);
10521052
new_plan_sp->SetOkayToDiscard(false);
10531053
} else {
1054-
result.SetError(new_plan_status);
1054+
result.SetError(std::move(new_plan_status));
10551055
return;
10561056
}
10571057
} else {
@@ -1739,7 +1739,7 @@ class CommandObjectThreadJump : public CommandObjectParsed {
17391739
Status err = thread->JumpToLine(file, line, m_options.m_force, &warnings);
17401740

17411741
if (err.Fail()) {
1742-
result.SetError(err);
1742+
result.SetError(std::move(err));
17431743
return;
17441744
}
17451745

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)