[Lldb-commits] [lldb] [lldb][lldb-dap] Implement jump to cursor (PR #130503)

Adrian Vogelsgesang via lldb-commits lldb-commits at lists.llvm.org
Tue Mar 11 05:41:58 PDT 2025


================
@@ -0,0 +1,59 @@
+"""
+Test lldb-dap gotoTarget request
+"""
+
+from lldbsuite.test.lldbtest import line_number
+import lldbdap_testcase
+import os
+
+
+class TestDAP_gotoTarget(lldbdap_testcase.DAPTestCaseBase):
+    def test_default(self):
+        """
+        Tests the jump to cursor of a simple program. No arguments,
+        environment, or anything else is specified.
+        This does not run any statement between the current breakpoint
+        and the jump line location.
+        """
+        program = self.getBuildArtifact("a.out")
+        self.build_and_launch(program)
+
+        source_file = "main.c"
+        self.source_path = os.path.join(os.getcwd(), source_file)
+        self.set_source_breakpoints(
+            source_file, [line_number(source_file, "// breakpoint 1")]
+        )
+        self.continue_to_next_stop()
+
+        first_var_1_object = self.dap_server.get_local_variable("var_1")
+        self.assertEqual(first_var_1_object["value"], "10")
+
+        goto_line = line_number(source_file, "// goto 1")
+        goto_column = 1
+        response = self.dap_server.request_gotoTargets(
+            source_file, self.source_path, goto_line, goto_column
+        )
+
+        self.assertEqual(
+            response["success"], True, "expects success when request for targets"
+        )
+        target = response["body"]["targets"][0]
+        self.assertGreaterEqual(
+            target["id"], 0, "targetId should be greater than or equal to zero"
+        )
+
+        target_id = target["id"]
+        thread_id = self.dap_server.get_thread_id()
+        self.assertIsNotNone(thread_id, "thread Id should not be none")
+
+        response = self.dap_server.request_goto(thread_id, target_id)
+
+        self.assertEqual(
+            response["success"], True, "expects success to go to a target id"
+        )
+
+        var_1_object = self.dap_server.get_local_variable("var_1")
+        self.assertEqual(first_var_1_object["value"], var_1_object["value"])
----------------
vogelsgesang wrote:

Currently, this test case does not really verify where code execution continues after the go-to. It only verifies that `var1` stays unchanged, but it does not check that `var_2 = 40` is indeed executed next.

Can we write this test case to check for `var_1 = 10, var_2 = 40`, i.e. a state which should not normally be reachable, except if the goto skipped over line 6?

https://github.com/llvm/llvm-project/pull/130503


More information about the lldb-commits mailing list