mirror of
https://github.com/intel/llvm.git
synced 2026-01-16 13:35:38 +08:00
[lldb] Fix po alias by printing fix-its to the console. (#68452)
The `po` alias now matches the behavior of the `expression` command when the it can apply a Fix-It to an expression. Modifications - Add has `m_fixed_expression` to the `CommandObjectDWIMPrint` class a `protected` member that stores the post Fix-It expression, just like the `CommandObjectExpression` class. - Converted messages to present tense. - Add test cases that confirms a Fix-It for a C++ expression for both `po` and `expressions` rdar://115317419 Co-authored-by: Pete Lawrence <plawrence@apple.com>
This commit is contained in:
@@ -172,8 +172,19 @@ bool CommandObjectDWIMPrint::DoExecute(StringRef command,
|
||||
{
|
||||
auto *exe_scope = m_exe_ctx.GetBestExecutionContextScope();
|
||||
ValueObjectSP valobj_sp;
|
||||
ExpressionResults expr_result =
|
||||
target.EvaluateExpression(expr, exe_scope, valobj_sp, eval_options);
|
||||
std::string fixed_expression;
|
||||
|
||||
ExpressionResults expr_result = target.EvaluateExpression(
|
||||
expr, exe_scope, valobj_sp, eval_options, &fixed_expression);
|
||||
|
||||
// Only mention Fix-Its if the expression evaluator applied them.
|
||||
// Compiler errors refer to the final expression after applying Fix-It(s).
|
||||
if (!fixed_expression.empty() && target.GetEnableNotifyAboutFixIts()) {
|
||||
Stream &error_stream = result.GetErrorStream();
|
||||
error_stream << " Evaluated this expression after applying Fix-It(s):\n";
|
||||
error_stream << " " << fixed_expression << "\n";
|
||||
}
|
||||
|
||||
if (expr_result == eExpressionCompleted) {
|
||||
if (verbosity != eDWIMPrintVerbosityNone) {
|
||||
StringRef flags;
|
||||
|
||||
@@ -439,11 +439,11 @@ bool CommandObjectExpression::EvaluateExpression(llvm::StringRef expr,
|
||||
ExpressionResults success = target.EvaluateExpression(
|
||||
expr, frame, result_valobj_sp, eval_options, &m_fixed_expression);
|
||||
|
||||
// We only tell you about the FixIt if we applied it. The compiler errors
|
||||
// will suggest the FixIt if it parsed.
|
||||
// Only mention Fix-Its if the expression evaluator applied them.
|
||||
// Compiler errors refer to the final expression after applying Fix-It(s).
|
||||
if (!m_fixed_expression.empty() && target.GetEnableNotifyAboutFixIts()) {
|
||||
error_stream.Printf(" Fix-it applied, fixed expression was: \n %s\n",
|
||||
m_fixed_expression.c_str());
|
||||
error_stream << " Evaluated this expression after applying Fix-It(s):\n";
|
||||
error_stream << " " << m_fixed_expression << "\n";
|
||||
}
|
||||
|
||||
if (result_valobj_sp) {
|
||||
|
||||
3
lldb/test/API/lang/cpp/dwim-print-fixit/Makefile
Normal file
3
lldb/test/API/lang/cpp/dwim-print-fixit/Makefile
Normal file
@@ -0,0 +1,3 @@
|
||||
CXX_SOURCES := main.cpp
|
||||
|
||||
include Makefile.rules
|
||||
@@ -0,0 +1,24 @@
|
||||
"""
|
||||
Tests whether the do-what-I-mean (DWIM) print `po` alias applies FixIts like `expr` does
|
||||
"""
|
||||
import lldb
|
||||
from lldbsuite.test.decorators import *
|
||||
from lldbsuite.test.lldbtest import *
|
||||
from lldbsuite.test import lldbutil
|
||||
|
||||
|
||||
class TestCase(TestBase):
|
||||
def test_with_run_command(self):
|
||||
"""Confirms `po` shows an expression after applying Fix-It(s)."""
|
||||
|
||||
self.build()
|
||||
lldbutil.run_to_source_breakpoint(
|
||||
self, "// break here", lldb.SBFileSpec("main.cpp")
|
||||
)
|
||||
|
||||
self.expect(
|
||||
"dwim-print -O -- class C { int i; void f() { []() { ++i; }(); } }; 42",
|
||||
error = True,
|
||||
substrs=["Evaluated this expression after applying Fix-It(s)",
|
||||
"class C { int i; void f() { [this]() { ++i; }(); } }"],
|
||||
)
|
||||
5
lldb/test/API/lang/cpp/dwim-print-fixit/main.cpp
Normal file
5
lldb/test/API/lang/cpp/dwim-print-fixit/main.cpp
Normal file
@@ -0,0 +1,5 @@
|
||||
int main() {
|
||||
long foo = 1234;
|
||||
|
||||
return 0; // break here
|
||||
}
|
||||
3
lldb/test/API/lang/cpp/expression-fixit/Makefile
Normal file
3
lldb/test/API/lang/cpp/expression-fixit/Makefile
Normal file
@@ -0,0 +1,3 @@
|
||||
CXX_SOURCES := main.cpp
|
||||
|
||||
include Makefile.rules
|
||||
@@ -0,0 +1,24 @@
|
||||
"""
|
||||
Tests whether the expression command applies FixIts
|
||||
"""
|
||||
import lldb
|
||||
from lldbsuite.test.decorators import *
|
||||
from lldbsuite.test.lldbtest import *
|
||||
from lldbsuite.test import lldbutil
|
||||
|
||||
|
||||
class TestCase(TestBase):
|
||||
def test_with_run_command(self):
|
||||
"""Confirms `expression` shows an expression after applying Fix-It(s)."""
|
||||
|
||||
self.build()
|
||||
lldbutil.run_to_source_breakpoint(
|
||||
self, "// break here", lldb.SBFileSpec("main.cpp")
|
||||
)
|
||||
|
||||
self.expect(
|
||||
"expr class C { int i; void f() { []() { ++i; }(); } }; 42",
|
||||
error = True,
|
||||
substrs=["Evaluated this expression after applying Fix-It(s)",
|
||||
"class C { int i; void f() { [this]() { ++i; }(); } }"],
|
||||
)
|
||||
5
lldb/test/API/lang/cpp/expression-fixit/main.cpp
Normal file
5
lldb/test/API/lang/cpp/expression-fixit/main.cpp
Normal file
@@ -0,0 +1,5 @@
|
||||
int main() {
|
||||
long foo = 1234;
|
||||
|
||||
return 0; // break here
|
||||
}
|
||||
Reference in New Issue
Block a user