Skip to content

[lldb] Unify implementation of CommandReturnObject::SetError(NFC) #110707

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lldb/include/lldb/Interpreter/CommandReturnObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ class CommandReturnObject {
AppendError(llvm::formatv(format, std::forward<Args>(args)...).str());
}

void SetError(const Status &error, const char *fallback_error_cstr = nullptr);
void SetError(Status error);

void SetError(llvm::Error error);

Expand Down
6 changes: 3 additions & 3 deletions lldb/source/API/SBCommandReturnObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,10 +326,10 @@ void SBCommandReturnObject::SetError(lldb::SBError &error,
const char *fallback_error_cstr) {
LLDB_INSTRUMENT_VA(this, error, fallback_error_cstr);

if (error.IsValid())
ref().SetError(error.ref(), fallback_error_cstr);
if (error.IsValid() && !error.Fail())
ref().SetError(error.ref().Clone());
else if (fallback_error_cstr)
ref().SetError(Status(), fallback_error_cstr);
ref().SetError(Status::FromErrorString(fallback_error_cstr));
}

void SBCommandReturnObject::SetError(const char *error_cstr) {
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Commands/CommandObjectBreakpointCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ are no syntax errors may indicate that a function was declared but never called.
m_bp_options_vec, result);
}
if (!error.Success())
result.SetError(error);
result.SetError(std::move(error));
} else {
// Special handling for one-liner specified inline.
if (m_options.m_use_one_liner)
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Commands/CommandObjectDWIMPrint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ void CommandObjectDWIMPrint::DoExecute(StringRef command,
// If the expression failed, return an error.
if (expr_result != eExpressionCompleted) {
if (valobj_sp)
result.SetError(valobj_sp->GetError());
result.SetError(valobj_sp->GetError().Clone());
else
result.AppendErrorWithFormatv(
"unknown error evaluating expression `{0}`", expr);
Expand Down
6 changes: 3 additions & 3 deletions lldb/source/Commands/CommandObjectExpression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -647,8 +647,8 @@ void CommandObjectExpression::DoExecute(llvm::StringRef command,
initialize = true;
repl_sp = target.GetREPL(repl_error, m_command_options.language,
nullptr, true);
if (!repl_error.Success()) {
result.SetError(repl_error);
if (repl_error.Fail()) {
result.SetError(std::move(repl_error));
return;
}
}
Expand All @@ -668,7 +668,7 @@ void CommandObjectExpression::DoExecute(llvm::StringRef command,
repl_error = Status::FromErrorStringWithFormat(
"Couldn't create a REPL for %s",
Language::GetNameForLanguageType(m_command_options.language));
result.SetError(repl_error);
result.SetError(std::move(repl_error));
return;
}
}
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Commands/CommandObjectMemoryTag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ class CommandObjectMemoryTagWrite : public CommandObjectParsed {
tagged_range->GetByteSize(), tags);

if (status.Fail()) {
result.SetError(status);
result.SetError(std::move(status));
return;
}

Expand Down
4 changes: 2 additions & 2 deletions lldb/source/Commands/CommandObjectTarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2775,7 +2775,7 @@ class CommandObjectTargetModulesAdd : public CommandObjectParsed {
result.AppendErrorWithFormat(
"Unable to locate the executable or symbol file with UUID %s",
strm.GetData());
result.SetError(error);
result.SetError(std::move(error));
return;
}
} else {
Expand Down Expand Up @@ -4409,7 +4409,7 @@ class CommandObjectTargetSymbolsAdd : public CommandObjectParsed {
return AddModuleSymbols(m_exe_ctx.GetTargetPtr(), module_spec, flush,
result);
} else {
result.SetError(error);
result.SetError(std::move(error));
}
return false;
}
Expand Down
6 changes: 3 additions & 3 deletions lldb/source/Commands/CommandObjectThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ class CommandObjectThreadStepWithTypeAndScope : public CommandObjectParsed {
result.SetStatus(eReturnStatusSuccessContinuingNoResult);
}
} else {
result.SetError(new_plan_status);
result.SetError(std::move(new_plan_status));
}
}

Expand Down Expand Up @@ -1046,7 +1046,7 @@ class CommandObjectThreadUntil : public CommandObjectParsed {
new_plan_sp->SetIsControllingPlan(true);
new_plan_sp->SetOkayToDiscard(false);
} else {
result.SetError(new_plan_status);
result.SetError(std::move(new_plan_status));
return;
}
} else {
Expand Down Expand Up @@ -1734,7 +1734,7 @@ class CommandObjectThreadJump : public CommandObjectParsed {
Status err = thread->JumpToLine(file, line, m_options.m_force, &warnings);

if (err.Fail()) {
result.SetError(err);
result.SetError(std::move(err));
return;
}

Expand Down
6 changes: 2 additions & 4 deletions lldb/source/Interpreter/CommandReturnObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,8 @@ void CommandReturnObject::AppendError(llvm::StringRef in_string) {
error(GetErrorStream()) << msg << '\n';
}

void CommandReturnObject::SetError(const Status &error,
const char *fallback_error_cstr) {
if (error.Fail())
AppendError(error.AsCString(fallback_error_cstr));
void CommandReturnObject::SetError(Status error) {
SetError(error.takeError());
}

void CommandReturnObject::SetError(llvm::Error error) {
Expand Down
Loading