131 lines · python
1"""2Test lldb-dap stepInTargets request3"""4 5import dap_server6from lldbsuite.test.decorators import *7from lldbsuite.test.lldbtest import *8import lldbdap_testcase9from lldbsuite.test import lldbutil10 11 12class TestDAP_stepInTargets(lldbdap_testcase.DAPTestCaseBase):13 @expectedFailureAll(oslist=["windows"])14 @skipIf(archs=no_match(["x86_64"]))15 # InstructionControlFlowKind for ARM is not supported yet.16 # On Windows, lldb-dap seems to ignore targetId when stepping into functions.17 # For more context, see https://github.com/llvm/llvm-project/issues/98509.18 def test_basic(self):19 """20 Tests the basic stepping in targets with directly calls.21 """22 program = self.getBuildArtifact("a.out")23 self.build_and_launch(program)24 source = "main.cpp"25 26 breakpoint_line = line_number(source, "// set breakpoint here")27 lines = [breakpoint_line]28 # Set breakpoint in the thread function so we can step the threads29 breakpoint_ids = self.set_source_breakpoints(source, lines)30 self.assertEqual(31 len(breakpoint_ids), len(lines), "expect correct number of breakpoints"32 )33 self.continue_to_breakpoints(breakpoint_ids)34 35 threads = self.dap_server.get_threads()36 self.assertEqual(len(threads), 1, "expect one thread")37 tid = threads[0]["id"]38 39 leaf_frame = self.dap_server.get_stackFrame()40 self.assertIsNotNone(leaf_frame, "expect a leaf frame")41 42 # Request all step in targets list and verify the response.43 step_in_targets_response = self.dap_server.request_stepInTargets(44 leaf_frame["id"]45 )46 self.assertEqual(step_in_targets_response["success"], True, "expect success")47 self.assertIn(48 "body", step_in_targets_response, "expect body field in response body"49 )50 self.assertIn(51 "targets",52 step_in_targets_response["body"],53 "expect targets field in response body",54 )55 56 step_in_targets = step_in_targets_response["body"]["targets"]57 self.assertEqual(len(step_in_targets), 3, "expect 3 step in targets")58 59 # Verify the target names are correct.60 # The order of funcA and funcB may change depending on the compiler ABI.61 funcA_target = None62 funcB_target = None63 for target in step_in_targets[0:2]:64 if "funcB" in target["label"]:65 funcB_target = target66 elif "funcA" in target["label"]:67 funcA_target = target68 else:69 self.fail(f"Unexpected step in target: {target}")70 71 self.assertIsNotNone(funcA_target, "expect funcA")72 self.assertIsNotNone(funcB_target, "expect funcB")73 self.assertIn("foo", step_in_targets[2]["label"], "expect foo")74 75 # Choose to step into second target and verify that we are in the second target,76 # be it funcA or funcB.77 self.stepIn(threadId=tid, targetId=step_in_targets[1]["id"], waitForStop=True)78 leaf_frame = self.dap_server.get_stackFrame()79 self.assertIsNotNone(leaf_frame, "expect a leaf frame")80 self.assertEqual(step_in_targets[1]["label"], leaf_frame["name"])81 82 @skipIf(archs=no_match(["x86", "x86_64"]))83 def test_supported_capability_x86_arch(self):84 program = self.getBuildArtifact("a.out")85 self.build_and_launch(program)86 source = "main.cpp"87 bp_lines = [line_number(source, "// set breakpoint here")]88 breakpoint_ids = self.set_source_breakpoints(source, bp_lines)89 self.assertEqual(90 len(breakpoint_ids), len(bp_lines), "expect correct number of breakpoints"91 )92 self.continue_to_breakpoints(breakpoint_ids)93 is_supported = self.dap_server.get_capability("supportsStepInTargetsRequest")94 95 self.assertEqual(96 is_supported,97 True,98 f"expect capability `stepInTarget` is supported with architecture {self.getArchitecture()}",99 )100 # clear breakpoints.101 self.set_source_breakpoints(source, [])102 self.continue_to_exit()103 104 @skipIf(archs=["x86", "x86_64"])105 def test_supported_capability_other_archs(self):106 program = self.getBuildArtifact("a.out")107 self.build_and_launch(program)108 source = "main.cpp"109 bp_lines = [line_number(source, "// set breakpoint here")]110 breakpoint_ids = self.set_source_breakpoints(source, bp_lines)111 self.assertEqual(112 len(breakpoint_ids), len(bp_lines), "expect correct number of breakpoints"113 )114 self.continue_to_breakpoints(breakpoint_ids)115 116 try:117 is_supported = self.dap_server.get_capability(118 "supportsStepInTargetsRequest"119 )120 except dap_server.NotSupportedError:121 is_supported = False122 123 self.assertEqual(124 is_supported,125 False,126 f"expect capability `stepInTarget` is not supported with architecture {self.getArchitecture()}",127 )128 # clear breakpoints.129 self.set_source_breakpoints(source, [])130 self.continue_to_exit()131