Skip to content

Commit 3038036

Browse files
committed
[lldb][lldb-dap] add jump to cursor tests
1 parent 63c0d50 commit 3038036

File tree

4 files changed

+101
-0
lines changed

4 files changed

+101
-0
lines changed

lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,33 @@ def request_exceptionInfo(self, threadId=None):
753753
}
754754
return self.send_recv(command_dict)
755755

756+
def request_goto(self, threadId: int, targetId: int):
757+
command_dict = {
758+
"command": "goto",
759+
"type": "request",
760+
"arguments": {
761+
"threadId": threadId,
762+
"targetId": targetId,
763+
},
764+
}
765+
return self.send_recv(command_dict)
766+
767+
def request_gotoTargets(self, filename: str, path: str, line: int, column: int):
768+
arguments = {
769+
"source": {
770+
"name": filename,
771+
"path": path,
772+
},
773+
"line": line,
774+
"column": column,
775+
}
776+
command_dict = {
777+
"command": "gotoTargets",
778+
"type": "request",
779+
"arguments": arguments,
780+
}
781+
return self.send_recv(command_dict)
782+
756783
def request_initialize(self, sourceInitFile):
757784
command_dict = {
758785
"command": "initialize",
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
C_SOURCES := main.c
2+
3+
include Makefile.rules
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
"""
2+
Test lldb-dap gotoTarget request
3+
"""
4+
5+
from lldbsuite.test.lldbtest import line_number
6+
import lldbdap_testcase
7+
import os
8+
9+
10+
class TestDAP_gotoTarget(lldbdap_testcase.DAPTestCaseBase):
11+
12+
def test_default(self):
13+
"""
14+
Tests the jump to cursor of a simple program. No arguments,
15+
environment, or anything else is specified.
16+
This does not run any statement between the current breakpoint
17+
and the jump line location.
18+
"""
19+
program = self.getBuildArtifact("a.out")
20+
self.build_and_launch(program)
21+
22+
source_file = "main.c"
23+
self.source_path = os.path.join(os.getcwd(), source_file)
24+
self.set_source_breakpoints(
25+
source_file, [line_number(source_file, "// breakpoint 1")]
26+
)
27+
self.continue_to_next_stop()
28+
29+
first_var_1_object = self.dap_server.get_local_variable("var_1")
30+
self.assertEqual(first_var_1_object["value"], "10")
31+
32+
goto_line = line_number(source_file, "// goto 1")
33+
goto_column = 1
34+
response = self.dap_server.request_gotoTargets(
35+
source_file, self.source_path, goto_line, goto_column
36+
)
37+
38+
self.assertEqual(
39+
response["success"], True, "expects success when request for targets"
40+
)
41+
target = response["body"]["targets"][0]
42+
self.assertGreaterEqual(
43+
target["id"], 0, "targetId should be greater than or equal to zero"
44+
)
45+
46+
target_id = target["id"]
47+
thread_id = self.dap_server.get_thread_id()
48+
self.assertIsNotNone(thread_id, "thread Id should not be none")
49+
50+
response = self.dap_server.request_goto(thread_id, target_id)
51+
52+
self.assertEqual(
53+
response["success"], True, "expects success to go to a target id"
54+
)
55+
56+
var_1_object = self.dap_server.get_local_variable("var_1")
57+
self.assertEqual(first_var_1_object["value"], var_1_object["value"])
58+
59+
self.continue_to_next_stop() # a stop event is sent after a successful goto response
60+
self.continue_to_exit()
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
int main() {
3+
4+
int var_1 = 10;
5+
6+
var_1 = 20; // breakpoint 1
7+
8+
int var_2 = 40; // goto 1
9+
10+
return 0;
11+
}

0 commit comments

Comments
 (0)