[lldb] Fix dwim-print error message for missing expr

This commit is contained in:
Dave Lee 2023-03-09 11:10:32 -08:00
parent 71a5958406
commit 4d18d97b59
2 changed files with 13 additions and 4 deletions

View File

@ -61,14 +61,16 @@ bool CommandObjectDWIMPrint::DoExecute(StringRef command,
OptionsWithRaw args{command};
StringRef expr = args.GetRawPart();
if (expr.empty()) {
result.AppendErrorWithFormatv("'{0}' takes a variable or expression",
m_cmd_name);
return false;
}
if (args.HasArgs()) {
if (!ParseOptionsAndNotify(args.GetArgs(), result, m_option_group,
m_exe_ctx))
return false;
} else if (command.empty()) {
result.AppendErrorWithFormatv("'{0}' takes a variable or expression",
m_cmd_name);
return false;
}
// If the user has not specified, default to disabling persistent results.

View File

@ -107,3 +107,10 @@ class TestCase(TestBase):
lldbutil.run_to_name_breakpoint(self, "main")
self._expect_cmd(f"dwim-print -l c++ -- argc", "frame variable")
self._expect_cmd(f"dwim-print -l c++ -- argc + 1", "expression")
def test_empty_expression(self):
self.build()
lldbutil.run_to_name_breakpoint(self, "main")
error_msg = "error: 'dwim-print' takes a variable or expression"
self.expect(f"dwim-print", error=True, startstr=error_msg)
self.expect(f"dwim-print -- ", error=True, startstr=error_msg)