68 lines · python
1"""2Make sure that deleting breakpoints in another breakpoint3callback doesn't cause problems.4"""5 6 7import lldb8import lldbsuite.test.lldbutil as lldbutil9from lldbsuite.test.lldbtest import *10 11 12class TestBreakpointDeletionInCallback(TestBase):13 NO_DEBUG_INFO_TESTCASE = True14 15 def test_breakpoint_deletion_in_callback(self):16 self.build()17 self.main_source_file = lldb.SBFileSpec("main.c")18 self.delete_others_test()19 20 def delete_others_test(self):21 """You might use the test implementation in several ways, say so here."""22 23 # This function starts a process, "a.out" by default, sets a source24 # breakpoint, runs to it, and returns the thread, process & target.25 # It optionally takes an SBLaunchOption argument if you want to pass26 # arguments or environment variables.27 (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(28 self, "Set a breakpoint here", self.main_source_file29 )30 31 # Now set a breakpoint on "I did something" several times32 #33 bkpt_numbers = []34 for idx in range(0, 5):35 bkpt_numbers.append(36 lldbutil.run_break_set_by_source_regexp(self, "// Deletable location")37 )38 39 # And add commands to the third one to delete two others:40 deleter = target.FindBreakpointByID(bkpt_numbers[2])41 self.assertTrue(deleter.IsValid(), "Deleter is a good breakpoint")42 commands = lldb.SBStringList()43 deleted_ids = [bkpt_numbers[0], bkpt_numbers[3]]44 for idx in deleted_ids:45 commands.AppendString(f"break delete {idx}")46 47 deleter.SetCommandLineCommands(commands)48 49 thread_list = lldbutil.continue_to_breakpoint(process, deleter)50 self.assertEqual(len(thread_list), 1)51 stop_data = thread.stop_reason_data52 # There are 5 breakpoints so 10 break_id, break_loc_id.53 self.assertEqual(len(stop_data), 10)54 # We should have been able to get break ID's and locations for all the55 # breakpoints that we originally hit, but some won't be around anymore:56 for idx in range(0, 5):57 bkpt_id = stop_data[idx * 2]58 print(f"{idx}: {bkpt_id}")59 self.assertIn(bkpt_id, bkpt_numbers, "Found breakpoints are right")60 loc_id = stop_data[idx * 2 + 1]61 self.assertEqual(loc_id, 1, "All breakpoints have one location")62 bkpt = target.FindBreakpointByID(bkpt_id)63 if bkpt_id in deleted_ids:64 # Looking these up should be an error:65 self.assertFalse(bkpt.IsValid(), "Deleted breakpoints are deleted")66 else:67 self.assertTrue(bkpt.IsValid(), "The rest are still valid")68