[lldb] Set result error state in 'frame variable'

Ensure that errors in `frame variable` are reflected in result object.

The statistics for `frame variable` show invocations as being successful, even
when executing one of the error paths.

This change replaces `result.GetErrorStream()` with `result.AppendError()`,
which also sets the status to `eReturnStatusFailed`.

Differential Revision: https://reviews.llvm.org/D116788

(cherry picked from commit 2c7d10c412)
This commit is contained in:
Dave Lee 2022-01-06 19:38:31 -08:00
parent a6f1d04665
commit 2bcff220bf
2 changed files with 20 additions and 19 deletions

View File

@ -558,18 +558,16 @@ protected:
} }
} }
} else if (num_matches == 0) { } else if (num_matches == 0) {
result.GetErrorStream().Printf("error: no variables matched " result.AppendErrorWithFormat(
"the regular expression '%s'.\n", "no variables matched the regular expression '%s'.",
entry.c_str()); entry.c_str());
} }
} else { } else {
if (llvm::Error err = regex.GetError()) if (llvm::Error err = regex.GetError())
result.GetErrorStream().Printf( result.AppendError(llvm::toString(std::move(err)));
"error: %s\n", llvm::toString(std::move(err)).c_str());
else else
result.GetErrorStream().Printf( result.AppendErrorWithFormat(
"error: unknown regex error when compiling '%s'\n", "unknown regex error when compiling '%s'", entry.c_str());
entry.c_str());
} }
} else // No regex, either exact variable names or variable } else // No regex, either exact variable names or variable
// expressions. // expressions.
@ -605,14 +603,13 @@ protected:
valobj_sp->GetParent() ? entry.c_str() : nullptr); valobj_sp->GetParent() ? entry.c_str() : nullptr);
valobj_sp->Dump(output_stream, options); valobj_sp->Dump(output_stream, options);
} else { } else {
const char *error_cstr = error.AsCString(nullptr); if (auto error_cstr = error.AsCString(nullptr))
if (error_cstr) result.AppendError(error_cstr);
result.GetErrorStream().Printf("error: %s\n", error_cstr);
else else
result.GetErrorStream().Printf("error: unable to find any " result.AppendErrorWithFormat(
"variable expression path that " "unable to find any variable expression path that matches "
"matches '%s'.\n", "'%s'.",
entry.c_str()); entry.c_str());
} }
} }
} }
@ -680,7 +677,8 @@ protected:
} }
} }
} }
result.SetStatus(eReturnStatusSuccessFinishResult); if (result.GetStatus() != eReturnStatusFailed)
result.SetStatus(eReturnStatusSuccessFinishResult);
} }
if (m_option_variable.show_recognized_args) { if (m_option_variable.show_recognized_args) {

View File

@ -30,6 +30,9 @@ class FrameVariableAnonymousUnionsTestCase(TestBase):
self.expect('frame variable c', substrs=["'A"]) self.expect('frame variable c', substrs=["'A"])
self.expect('frame variable x', matching=False, substrs=['3']) self.expect('frame variable x', error=True,
self.expect('frame variable y', matching=False, substrs=["'B'"]) substrs=["no variable named 'x' found"])
self.expect('frame variable z', matching=False, substrs=['14']) self.expect('frame variable y', error=True,
substrs=["no variable named 'y' found"])
self.expect('frame variable z', error=True,
substrs=["no variable named 'z' found"])