161 lines · python
1"""2Test lldb-dap setBreakpoints request in assembly source references.3"""4 5from lldbsuite.test.decorators import *6from dap_server import Source7import lldbdap_testcase8 9 10class TestDAP_setBreakpointsAssembly(lldbdap_testcase.DAPTestCaseBase):11 # When using PDB, we need to have debug information to break on assembly_func,12 # but this test relies on us not having debug information for that function.13 @skipIfWindows14 def test_can_break_in_source_references(self):15 """Tests hitting assembly source breakpoints"""16 program = self.getBuildArtifact("a.out")17 self.build_and_launch(program)18 19 assmebly_func_breakpoints = self.set_function_breakpoints(["assembly_func"])20 self.continue_to_breakpoints(assmebly_func_breakpoints)21 22 assembly_func_frame = self.get_stackFrames()[0]23 self.assertIn(24 "sourceReference",25 assembly_func_frame.get("source"),26 "Expected assembly source frame",27 )28 29 line = assembly_func_frame["line"]30 31 # Set an assembly breakpoint in the next line and check that it's hit32 source_reference = assembly_func_frame["source"]["sourceReference"]33 assembly_breakpoint_ids = self.set_source_breakpoints_assembly(34 source_reference, [line + 1]35 )36 self.continue_to_breakpoints(assembly_breakpoint_ids)37 38 # Continue again and verify it hits in the next function call39 self.continue_to_breakpoints(assmebly_func_breakpoints)40 self.continue_to_breakpoints(assembly_breakpoint_ids)41 42 # Clear the breakpoint and then check that the assembly breakpoint does not hit next time43 self.set_source_breakpoints_assembly(source_reference, [])44 self.continue_to_breakpoints(assmebly_func_breakpoints)45 self.continue_to_exit()46 47 def test_break_on_invalid_source_reference(self):48 """Tests hitting assembly source breakpoints"""49 program = self.getBuildArtifact("a.out")50 self.build_and_launch(program)51 52 # Verify that setting a breakpoint on an invalid source reference fails53 response = self.dap_server.request_setBreakpoints(54 Source.build(source_reference=-1), [1]55 )56 self.assertIsNotNone(response)57 breakpoints = response["body"]["breakpoints"]58 self.assertEqual(len(breakpoints), 1)59 breakpoint = breakpoints[0]60 self.assertFalse(61 breakpoint["verified"], "Expected breakpoint to not be verified"62 )63 self.assertIn("message", breakpoint, "Expected message to be present")64 self.assertEqual(65 breakpoint["message"],66 "Invalid sourceReference.",67 )68 69 # Verify that setting a breakpoint on a source reference that is not created fails70 response = self.dap_server.request_setBreakpoints(71 Source.build(source_reference=200), [1]72 )73 self.assertIsNotNone(response)74 breakpoints = response["body"]["breakpoints"]75 self.assertEqual(len(breakpoints), 1)76 break_point = breakpoints[0]77 self.assertFalse(78 break_point["verified"], "Expected breakpoint to not be verified"79 )80 self.assertIn("message", break_point, "Expected message to be present")81 self.assertEqual(82 break_point["message"],83 "Invalid sourceReference.",84 )85 86 @skipIfWindows87 def test_persistent_assembly_breakpoint(self):88 """Tests that assembly breakpoints are working persistently across sessions"""89 self.build()90 program = self.getBuildArtifact("a.out")91 self.create_debug_adapter()92 93 # Run the first session and set a persistent assembly breakpoint94 try:95 self.dap_server.request_initialize()96 self.dap_server.request_launch(program)97 98 assmebly_func_breakpoints = self.set_function_breakpoints(["assembly_func"])99 self.continue_to_breakpoints(assmebly_func_breakpoints)100 101 assembly_func_frame = self.get_stackFrames()[0]102 source_reference = assembly_func_frame["source"]["sourceReference"]103 104 # Set an assembly breakpoint in the middle of the assembly function105 persistent_breakpoint_line = 4106 persistent_breakpoint_ids = self.set_source_breakpoints_assembly(107 source_reference, [persistent_breakpoint_line]108 )109 110 self.assertEqual(111 len(persistent_breakpoint_ids),112 1,113 "Expected one assembly breakpoint to be set",114 )115 116 persistent_breakpoint_source = self.dap_server.resolved_breakpoints[117 persistent_breakpoint_ids[0]118 ]["source"]119 self.assertIn(120 "adapterData",121 persistent_breakpoint_source,122 "Expected assembly breakpoint to have persistent information",123 )124 self.assertIn(125 "persistenceData",126 persistent_breakpoint_source["adapterData"],127 "Expected assembly breakpoint to have persistent information",128 )129 130 self.continue_to_breakpoints(persistent_breakpoint_ids)131 finally:132 self.dap_server.request_disconnect(terminateDebuggee=True)133 self.dap_server.terminate()134 135 # Restart the session and verify the breakpoint is still there136 self.create_debug_adapter()137 try:138 self.dap_server.request_initialize()139 self.dap_server.request_launch(program)140 new_session_breakpoints_ids = self.set_source_breakpoints_from_source(141 Source(persistent_breakpoint_source),142 [persistent_breakpoint_line],143 )144 145 self.assertEqual(146 len(new_session_breakpoints_ids),147 1,148 "Expected one breakpoint to be set in the new session",149 )150 151 self.continue_to_breakpoints(new_session_breakpoints_ids)152 current_line = self.get_stackFrames()[0]["line"]153 self.assertEqual(154 current_line,155 persistent_breakpoint_line,156 "Expected to hit the persistent assembly breakpoint at the same line",157 )158 finally:159 self.dap_server.request_disconnect(terminateDebuggee=True)160 self.dap_server.terminate()161