[Lldb-commits] [lldb] 25bf137 - Also display the underlying error message when displaying a fixit
Adrian Prantl via lldb-commits
lldb-commits at lists.llvm.org
Tue Apr 27 10:40:55 PDT 2021
Author: Adrian Prantl
Date: 2021-04-27T10:40:42-07:00
New Revision: 25bf137b1ea33ff9c76834f44b10f4e1ae677d5e
URL: https://github.com/llvm/llvm-project/commit/25bf137b1ea33ff9c76834f44b10f4e1ae677d5e
DIFF: https://github.com/llvm/llvm-project/commit/25bf137b1ea33ff9c76834f44b10f4e1ae677d5e.diff
LOG: Also display the underlying error message when displaying a fixit
When the user running LLDB with default settings sees the fixit
notification it means that the auto-applied fixit didn't work. This
patch shows the underlying error message instead of just the fixit to
make it easier to understand what the error in the expression was.
Differential Revision: https://reviews.llvm.org/D101333
Added:
Modified:
lldb/source/Expression/UserExpression.cpp
lldb/test/API/commands/expression/fixits/TestFixIts.py
Removed:
################################################################################
diff --git a/lldb/source/Expression/UserExpression.cpp b/lldb/source/Expression/UserExpression.cpp
index 25931b1232b40..6d39950679441 100644
--- a/lldb/source/Expression/UserExpression.cpp
+++ b/lldb/source/Expression/UserExpression.cpp
@@ -302,19 +302,19 @@ UserExpression::Evaluate(ExecutionContext &exe_ctx,
}
if (!parse_success) {
- if (!fixed_expression->empty() && target->GetEnableNotifyAboutFixIts()) {
- error.SetExpressionErrorWithFormat(
- execution_results,
- "expression failed to parse, fixed expression suggested:\n %s",
- fixed_expression->c_str());
- } else {
- if (!diagnostic_manager.Diagnostics().size())
- error.SetExpressionError(execution_results,
- "expression failed to parse, unknown error");
+ 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
- error.SetExpressionError(execution_results,
- diagnostic_manager.GetString().c_str());
+ os << "unknown error";
+ if (target->GetEnableNotifyAboutFixIts() && fixed_expression &&
+ !fixed_expression->empty())
+ os << "\nfixed expression suggested:\n " << *fixed_expression;
}
+ error.SetExpressionError(execution_results, msg.c_str());
}
}
diff --git a/lldb/test/API/commands/expression/fixits/TestFixIts.py b/lldb/test/API/commands/expression/fixits/TestFixIts.py
index 754e517a855dd..a2e4564f70787 100644
--- a/lldb/test/API/commands/expression/fixits/TestFixIts.py
+++ b/lldb/test/API/commands/expression/fixits/TestFixIts.py
@@ -132,25 +132,25 @@ def test_with_multiple_retries(self):
# Disable retries which will fail.
multiple_runs_options.SetRetriesWithFixIts(0)
value = frame.EvaluateExpression(two_runs_expr, multiple_runs_options)
- self.assertIn("expression failed to parse, fixed expression suggested:",
- value.GetError().GetCString())
- self.assertIn("using typename T::TypeDef",
- value.GetError().GetCString())
+ 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)
# The second Fix-It shouldn't be suggested here as Clang should have
# aborted the parsing process.
- self.assertNotIn("i->m",
- value.GetError().GetCString())
+ self.assertNotIn("i->m", errmsg)
# Retry once, but the expression needs two retries.
multiple_runs_options.SetRetriesWithFixIts(1)
value = frame.EvaluateExpression(two_runs_expr, multiple_runs_options)
- self.assertIn("expression failed to parse, fixed expression suggested:",
- value.GetError().GetCString())
+ 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",
- value.GetError().GetCString())
- self.assertIn("i->m",
- value.GetError().GetCString())
+ self.assertIn("using typename T::TypeDef", errmsg)
+ self.assertIn("i->m", errmsg)
# Retry twice, which will get the expression working.
multiple_runs_options.SetRetriesWithFixIts(2)
More information about the lldb-commits
mailing list