Skip to content

Commit f388e67

Browse files
committed
[lldb] Fix dwim-print error message for missing expr
(cherry picked from commit 4d18d97)
1 parent 182443f commit f388e67

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

lldb/source/Commands/CommandObjectDWIMPrint.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,16 @@ bool CommandObjectDWIMPrint::DoExecute(StringRef command,
6363
OptionsWithRaw args{command};
6464
StringRef expr = args.GetRawPart();
6565

66+
if (expr.empty()) {
67+
result.AppendErrorWithFormatv("'{0}' takes a variable or expression",
68+
m_cmd_name);
69+
return false;
70+
}
71+
6672
if (args.HasArgs()) {
6773
if (!ParseOptionsAndNotify(args.GetArgs(), result, m_option_group,
6874
m_exe_ctx))
6975
return false;
70-
} else if (command.empty()) {
71-
result.AppendErrorWithFormatv("'{0}' takes a variable or expression",
72-
m_cmd_name);
73-
return false;
7476
}
7577

7678
auto verbosity = GetDebugger().GetDWIMPrintVerbosity();

lldb/test/API/commands/dwim-print/TestDWIMPrint.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,13 @@ def test_expression_language(self):
113113
self._expect_cmd(f"dwim-print -l c++ -- argc", "frame variable")
114114
self._expect_cmd(f"dwim-print -l c++ -- argc + 1", "expression")
115115

116+
def test_empty_expression(self):
117+
self.build()
118+
lldbutil.run_to_name_breakpoint(self, "main")
119+
error_msg = "error: 'dwim-print' takes a variable or expression"
120+
self.expect(f"dwim-print", error=True, startstr=error_msg)
121+
self.expect(f"dwim-print -- ", error=True, startstr=error_msg)
122+
116123
def test_nested_values(self):
117124
"""Test dwim-print with nested values (structs, etc)."""
118125
self.build()

0 commit comments

Comments
 (0)