brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.1 KiB · 7e60dd2 Raw
90 lines · python
1"""2Test lldb-dap start-debugging reverse requests.3"""4 5from lldbsuite.test.decorators import *6from lldbsuite.test.lldbtest import *7import lldbdap_testcase8 9 10class TestDAP_startDebugging(lldbdap_testcase.DAPTestCaseBase):11    def test_startDebugging(self):12        """13        Tests the "startDebugging" reverse request. It makes sure that the IDE can14        start a child debug session.15        """16        program = self.getBuildArtifact("a.out")17        source = "main.c"18        self.build_and_launch(program)19 20        breakpoint_line = line_number(source, "// breakpoint")21 22        self.set_source_breakpoints(source, [breakpoint_line])23        self.continue_to_next_stop()24        self.dap_server.request_evaluate(25            "`lldb-dap start-debugging attach '{\"pid\":321}'", context="repl"26        )27 28        self.continue_to_exit()29 30        self.assertEqual(31            len(self.dap_server.reverse_requests),32            1,33            "make sure we got a reverse request",34        )35 36        request = self.dap_server.reverse_requests[0]37        self.assertEqual(request["arguments"]["configuration"]["pid"], 321)38        self.assertEqual(request["arguments"]["request"], "attach")39 40    def test_startDebugging_debugger_reuse(self):41        """42        Tests that debugger and target IDs can be passed through startDebugging43        for debugger reuse. This verifies the infrastructure for child DAP44        sessions to reuse the parent's debugger and attach to an existing target.45        """46        program = self.getBuildArtifact("a.out")47        source = "main.c"48        self.build_and_launch(program)49 50        breakpoint_line = line_number(source, "// breakpoint")51        self.set_source_breakpoints(source, [breakpoint_line])52        self.continue_to_next_stop()53 54        # Use mock IDs to test the infrastructure55        # In a real scenario, these would come from the parent session56        test_debugger_id = 157        test_target_id = 10058 59        # Send a startDebugging request with debuggerId and targetId60        # This simulates creating a child DAP session that reuses the debugger61        self.dap_server.request_evaluate(62            f'`lldb-dap start-debugging attach \'{{"debuggerId":{test_debugger_id},"targetId":{test_target_id}}}\'',63            context="repl",64        )65 66        self.continue_to_exit()67 68        # Verify the reverse request was sent with the correct IDs69        self.assertEqual(70            len(self.dap_server.reverse_requests),71            1,72            "Should have received one startDebugging reverse request",73        )74 75        request = self.dap_server.reverse_requests[0]76        self.assertEqual(request["command"], "startDebugging")77        self.assertEqual(request["arguments"]["request"], "attach")78 79        config = request["arguments"]["configuration"]80        self.assertEqual(81            config["debuggerId"],82            test_debugger_id,83            "Reverse request should include debugger ID",84        )85        self.assertEqual(86            config["targetId"],87            test_target_id,88            "Reverse request should include target ID",89        )90