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
std::string msg;
{
llvm::raw_string_ostream os(msg);
- os << "expression failed to parse:\n";
if (!diagnostic_manager.Diagnostics().empty())
os << diagnostic_manager.GetString();
else
- os << "unknown error";
+ os << "expression failed to parse (no further compiler diagnostics)";
if (target->GetEnableNotifyAboutFixIts() && fixed_expression &&
!fixed_expression->empty())
os << "\nfixed expression suggested:\n " << *fixed_expression;
SetStatus(eReturnStatusFailed);
if (in_string.empty())
return;
- error(GetErrorStream()) << in_string.rtrim() << '\n';
+ // Workaround to deal with already fully formatted compiler diagnostics.
+ llvm::StringRef msg(in_string.rtrim());
+ msg.consume_front("error: ");
+ error(GetErrorStream()) << msg << '\n';
}
void CommandReturnObject::SetError(const Status &error,
value = frame.EvaluateExpression("struct Redef { float y; };", top_level_opts)
self.assertFalse(value.GetError().Success())
self.assertIn(
- """
-error: <user expression 9>:1:8: redefinition of 'Redef'
+ """error: <user expression 9>:1:8: redefinition of 'Redef'
1 | struct Redef { float y; };
| ^
<user expression 8>:1:8: previous definition is here
multiple_runs_options.SetRetriesWithFixIts(0)
value = frame.EvaluateExpression(two_runs_expr, multiple_runs_options)
errmsg = value.GetError().GetCString()
- self.assertIn("expression failed to parse", errmsg)
self.assertIn("using declaration resolved to type without 'typename'", errmsg)
self.assertIn("fixed expression suggested:", errmsg)
self.assertIn("using typename T::TypeDef", errmsg)
multiple_runs_options.SetRetriesWithFixIts(1)
value = frame.EvaluateExpression(two_runs_expr, multiple_runs_options)
errmsg = value.GetError().GetCString()
- self.assertIn("expression failed to parse", errmsg)
self.assertIn("fixed expression suggested:", errmsg)
# Both our fixed expressions should be in the suggested expression.
self.assertIn("using typename T::TypeDef", errmsg)