https://github.com/labath updated https://github.com/llvm/llvm-project/pull/92137
>From 6d4df820e84e84a871a6d24a196608047470d7d7 Mon Sep 17 00:00:00 2001 From: Pavel Labath <pa...@labath.sk> Date: Tue, 14 May 2024 15:32:15 +0000 Subject: [PATCH 1/2] [lldb-dap] Correctly detect alias commands with arguments in repl ResolveCommand will not succeed for an alias command with arguments, and the code wasn't providing any. Replace that with explicit query(ies) for the existence of a command with the given name. --- .../API/tools/lldb-dap/repl-mode/Makefile | 3 + .../repl-mode/TestDAP_repl_mode_detection.py | 56 +++++++++++++++++++ .../API/tools/lldb-dap/repl-mode/main.cpp | 15 +++++ lldb/tools/lldb-dap/DAP.cpp | 8 ++- 4 files changed, 79 insertions(+), 3 deletions(-) create mode 100644 lldb/test/API/tools/lldb-dap/repl-mode/Makefile create mode 100644 lldb/test/API/tools/lldb-dap/repl-mode/TestDAP_repl_mode_detection.py create mode 100644 lldb/test/API/tools/lldb-dap/repl-mode/main.cpp diff --git a/lldb/test/API/tools/lldb-dap/repl-mode/Makefile b/lldb/test/API/tools/lldb-dap/repl-mode/Makefile new file mode 100644 index 0000000000000..99998b20bcb05 --- /dev/null +++ b/lldb/test/API/tools/lldb-dap/repl-mode/Makefile @@ -0,0 +1,3 @@ +CXX_SOURCES := main.cpp + +include Makefile.rules diff --git a/lldb/test/API/tools/lldb-dap/repl-mode/TestDAP_repl_mode_detection.py b/lldb/test/API/tools/lldb-dap/repl-mode/TestDAP_repl_mode_detection.py new file mode 100644 index 0000000000000..8beecac26160e --- /dev/null +++ b/lldb/test/API/tools/lldb-dap/repl-mode/TestDAP_repl_mode_detection.py @@ -0,0 +1,56 @@ +""" +Test lldb-dap repl mode detection +""" + +import lldbdap_testcase +import dap_server +from lldbsuite.test import lldbutil +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * + + +class TestDAP_repl_mode_detection(lldbdap_testcase.DAPTestCaseBase): + + def assertEvaluate(self, expression, regex): + self.assertRegex( + self.dap_server.request_evaluate(expression, context="repl")["body"][ + "result" + ], + regex, + ) + + def test_completions(self): + program = self.getBuildArtifact("a.out") + self.build_and_launch(program) + + source = "main.cpp" + breakpoint1_line = line_number(source, "// breakpoint 1") + breakpoint2_line = line_number(source, "// breakpoint 2") + + self.set_source_breakpoints(source, [breakpoint1_line, breakpoint2_line]) + + self.assertEvaluate( + "`command regex user_command s/^$/platform/", r"\(lldb\) command regex" + ) + self.assertEvaluate( + "`command alias alias_command platform", r"\(lldb\) command alias" + ) + self.assertEvaluate( + "`command alias alias_command_with_arg platform select --sysroot %1 remote-linux", + r"\(lldb\) command alias", + ) + + self.continue_to_next_stop() + self.assertEvaluate("user_command", "474747") + self.assertEvaluate("alias_command", "474747") + self.assertEvaluate("alias_command_with_arg", "474747") + self.assertEvaluate("platform", "474747") + + self.continue_to_next_stop() + platform_help_needle = "Commands to manage and create platforms" + self.assertEvaluate("user_command", platform_help_needle) + self.assertEvaluate("alias_command", platform_help_needle) + self.assertEvaluate( + "alias_command_with_arg " + self.getBuildDir(), "Platform: remote-linux" + ) + self.assertEvaluate("platform", platform_help_needle) diff --git a/lldb/test/API/tools/lldb-dap/repl-mode/main.cpp b/lldb/test/API/tools/lldb-dap/repl-mode/main.cpp new file mode 100644 index 0000000000000..52561d3471abf --- /dev/null +++ b/lldb/test/API/tools/lldb-dap/repl-mode/main.cpp @@ -0,0 +1,15 @@ +void noop() {} + +void fun() { + int user_command = 474747; + int alias_command = 474747; + int alias_command_with_arg = 474747; + int platform = 474747; // built-in command + noop(); // breakpoint 1 +} + +int main() { + fun(); + noop(); // breakpoint 2 + return 0; +} diff --git a/lldb/tools/lldb-dap/DAP.cpp b/lldb/tools/lldb-dap/DAP.cpp index 55ff1493c1011..c7eb3db4304a9 100644 --- a/lldb/tools/lldb-dap/DAP.cpp +++ b/lldb/tools/lldb-dap/DAP.cpp @@ -14,6 +14,7 @@ #include "DAP.h" #include "LLDBUtils.h" +#include "lldb/API/SBCommandInterpreter.h" #include "llvm/ADT/StringExtras.h" #include "llvm/Support/FormatVariadic.h" @@ -405,9 +406,10 @@ ExpressionContext DAP::DetectExpressionContext(lldb::SBFrame frame, std::pair<llvm::StringRef, llvm::StringRef> token = llvm::getToken(expression); std::string term = token.first.str(); - lldb::SBCommandReturnObject result; - debugger.GetCommandInterpreter().ResolveCommand(term.c_str(), result); - bool term_is_command = result.Succeeded(); + lldb::SBCommandInterpreter interpreter = debugger.GetCommandInterpreter(); + bool term_is_command = interpreter.CommandExists(term.c_str()) || + interpreter.UserCommandExists(term.c_str()) || + interpreter.AliasExists(term.c_str()); bool term_is_variable = frame.FindVariable(term.c_str()).IsValid(); // If we have both a variable and command, warn the user about the conflict. >From 44364cdcc876f837b682a95eb5fa0da7f144b91e Mon Sep 17 00:00:00 2001 From: Pavel Labath <pa...@labath.sk> Date: Wed, 15 May 2024 07:14:45 +0000 Subject: [PATCH 2/2] fix formatting --- .../API/tools/lldb-dap/repl-mode/TestDAP_repl_mode_detection.py | 1 - 1 file changed, 1 deletion(-) diff --git a/lldb/test/API/tools/lldb-dap/repl-mode/TestDAP_repl_mode_detection.py b/lldb/test/API/tools/lldb-dap/repl-mode/TestDAP_repl_mode_detection.py index 8beecac26160e..7c77fc8541b93 100644 --- a/lldb/test/API/tools/lldb-dap/repl-mode/TestDAP_repl_mode_detection.py +++ b/lldb/test/API/tools/lldb-dap/repl-mode/TestDAP_repl_mode_detection.py @@ -10,7 +10,6 @@ class TestDAP_repl_mode_detection(lldbdap_testcase.DAPTestCaseBase): - def assertEvaluate(self, expression, regex): self.assertRegex( self.dap_server.request_evaluate(expression, context="repl")["body"][ _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits