Skip to content

Commit 33bf08e

Browse files
authored
[lldb-dap] Correctly detect alias commands with arguments in repl (#92137)
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.
1 parent ee54c86 commit 33bf08e

File tree

4 files changed

+78
-3
lines changed

4 files changed

+78
-3
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
CXX_SOURCES := main.cpp
2+
3+
include Makefile.rules
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
"""
2+
Test lldb-dap repl mode detection
3+
"""
4+
5+
import lldbdap_testcase
6+
import dap_server
7+
from lldbsuite.test import lldbutil
8+
from lldbsuite.test.decorators import *
9+
from lldbsuite.test.lldbtest import *
10+
11+
12+
class TestDAP_repl_mode_detection(lldbdap_testcase.DAPTestCaseBase):
13+
def assertEvaluate(self, expression, regex):
14+
self.assertRegex(
15+
self.dap_server.request_evaluate(expression, context="repl")["body"][
16+
"result"
17+
],
18+
regex,
19+
)
20+
21+
def test_completions(self):
22+
program = self.getBuildArtifact("a.out")
23+
self.build_and_launch(program)
24+
25+
source = "main.cpp"
26+
breakpoint1_line = line_number(source, "// breakpoint 1")
27+
breakpoint2_line = line_number(source, "// breakpoint 2")
28+
29+
self.set_source_breakpoints(source, [breakpoint1_line, breakpoint2_line])
30+
31+
self.assertEvaluate(
32+
"`command regex user_command s/^$/platform/", r"\(lldb\) command regex"
33+
)
34+
self.assertEvaluate(
35+
"`command alias alias_command platform", r"\(lldb\) command alias"
36+
)
37+
self.assertEvaluate(
38+
"`command alias alias_command_with_arg platform select --sysroot %1 remote-linux",
39+
r"\(lldb\) command alias",
40+
)
41+
42+
self.continue_to_next_stop()
43+
self.assertEvaluate("user_command", "474747")
44+
self.assertEvaluate("alias_command", "474747")
45+
self.assertEvaluate("alias_command_with_arg", "474747")
46+
self.assertEvaluate("platform", "474747")
47+
48+
self.continue_to_next_stop()
49+
platform_help_needle = "Commands to manage and create platforms"
50+
self.assertEvaluate("user_command", platform_help_needle)
51+
self.assertEvaluate("alias_command", platform_help_needle)
52+
self.assertEvaluate(
53+
"alias_command_with_arg " + self.getBuildDir(), "Platform: remote-linux"
54+
)
55+
self.assertEvaluate("platform", platform_help_needle)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
void noop() {}
2+
3+
void fun() {
4+
int user_command = 474747;
5+
int alias_command = 474747;
6+
int alias_command_with_arg = 474747;
7+
int platform = 474747; // built-in command
8+
noop(); // breakpoint 1
9+
}
10+
11+
int main() {
12+
fun();
13+
noop(); // breakpoint 2
14+
return 0;
15+
}

lldb/tools/lldb-dap/DAP.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
#include "DAP.h"
1616
#include "LLDBUtils.h"
17+
#include "lldb/API/SBCommandInterpreter.h"
1718
#include "llvm/ADT/StringExtras.h"
1819
#include "llvm/Support/FormatVariadic.h"
1920

@@ -405,9 +406,10 @@ ExpressionContext DAP::DetectExpressionContext(lldb::SBFrame frame,
405406
std::pair<llvm::StringRef, llvm::StringRef> token =
406407
llvm::getToken(expression);
407408
std::string term = token.first.str();
408-
lldb::SBCommandReturnObject result;
409-
debugger.GetCommandInterpreter().ResolveCommand(term.c_str(), result);
410-
bool term_is_command = result.Succeeded();
409+
lldb::SBCommandInterpreter interpreter = debugger.GetCommandInterpreter();
410+
bool term_is_command = interpreter.CommandExists(term.c_str()) ||
411+
interpreter.UserCommandExists(term.c_str()) ||
412+
interpreter.AliasExists(term.c_str());
411413
bool term_is_variable = frame.FindVariable(term.c_str()).IsValid();
412414

413415
// If we have both a variable and command, warn the user about the conflict.

0 commit comments

Comments
 (0)