Skip to content

Commit a8bf10a

Browse files
committed
Streamline expression parser error messages.
Currently the expression parser prints a mostly useless generic error before printing the compiler error: (lldb) p 1+x) error: expression failed to parse: error: <user expression 18>:1:3: use of undeclared identifier 'x' 1+x) ^ This is distracting and as far as I can tell only exists to work around the fact that the first "error: " is unconditionally injected by CommandReturnObject. The solution is not very elegant, but the result looks much better. (Partially addresses rdar://110492710) Differential Revision: https://reviews.llvm.org/D152590 (cherry picked from commit 133c3ea)
1 parent ce97507 commit a8bf10a

File tree

4 files changed

+7
-7
lines changed

4 files changed

+7
-7
lines changed

lldb/source/Expression/UserExpression.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,11 +341,10 @@ UserExpression::Evaluate(ExecutionContext &exe_ctx,
341341
std::string msg;
342342
{
343343
llvm::raw_string_ostream os(msg);
344-
os << "expression failed to parse:\n";
345344
if (!diagnostic_manager.Diagnostics().empty())
346345
os << diagnostic_manager.GetString();
347346
else
348-
os << "unknown error";
347+
os << "expression failed to parse (no further compiler diagnostics)";
349348
if (target->GetEnableNotifyAboutFixIts() && fixed_expression &&
350349
!fixed_expression->empty())
351350
os << "\nfixed expression suggested:\n " << *fixed_expression;

lldb/source/Interpreter/CommandReturnObject.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,10 @@ void CommandReturnObject::AppendError(llvm::StringRef in_string) {
101101
SetStatus(eReturnStatusFailed);
102102
if (in_string.empty())
103103
return;
104-
error(GetErrorStream()) << in_string.rtrim() << '\n';
104+
// Workaround to deal with already fully formatted compiler diagnostics.
105+
llvm::StringRef msg(in_string.rtrim());
106+
msg.consume_front("error: ");
107+
error(GetErrorStream()) << msg << '\n';
105108
}
106109

107110
void CommandReturnObject::SetError(const Status &error,

lldb/test/API/commands/expression/diagnostics/TestExprDiagnostics.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ def test_source_and_caret_printing(self):
9898
value = frame.EvaluateExpression("struct Redef { double x; };", top_level_opts)
9999
value = frame.EvaluateExpression("struct Redef { float y; };", top_level_opts)
100100
self.assertFalse(value.GetError().Success())
101-
self.assertIn(
102-
"error: <user expression 9>:1:8: redefinition of 'Redef'\nstruct Redef { float y; };\n ^\n<user expression 8>:1:8: previous definition is here\nstruct Redef { double x; };\n ^",
101+
self.assertIn(
102+
"error: <user expression 9>:1:8: redefinition of 'Redef'\nstruct Redef { float y; };\n ^\n<user expression 8>:1:8: previous definition is here\nstruct Redef { double x; };\n ^\n\n",
103103
value.GetError().GetCString(),
104104
)
105105

lldb/test/API/commands/expression/fixits/TestFixIts.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,6 @@ def test_with_multiple_retries(self):
154154
multiple_runs_options.SetRetriesWithFixIts(0)
155155
value = frame.EvaluateExpression(two_runs_expr, multiple_runs_options)
156156
errmsg = value.GetError().GetCString()
157-
self.assertIn("expression failed to parse", errmsg)
158157
self.assertIn("using declaration resolved to type without 'typename'", errmsg)
159158
self.assertIn("fixed expression suggested:", errmsg)
160159
self.assertIn("using typename T::TypeDef", errmsg)
@@ -166,7 +165,6 @@ def test_with_multiple_retries(self):
166165
multiple_runs_options.SetRetriesWithFixIts(1)
167166
value = frame.EvaluateExpression(two_runs_expr, multiple_runs_options)
168167
errmsg = value.GetError().GetCString()
169-
self.assertIn("expression failed to parse", errmsg)
170168
self.assertIn("fixed expression suggested:", errmsg)
171169
# Both our fixed expressions should be in the suggested expression.
172170
self.assertIn("using typename T::TypeDef", errmsg)

0 commit comments

Comments
 (0)