60 lines · python
1"""2Test that a Python breakpoint callback defined in another Python3breakpoint callback works properly. 4"""5 6 7import lldb8import os9import lldbsuite.test.lldbutil as lldbutil10from lldbsuite.test.lldbtest import *11 12 13class TestNestedBreakpointCommands(TestBase):14 NO_DEBUG_INFO_TESTCASE = True15 16 def test_nested_commands(self):17 self.build()18 self.main_source_file = lldb.SBFileSpec("main.c")19 self.callback_module = "make_bkpt_cmds"20 self.do_test()21 22 def do_test(self):23 (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(24 self, "Set a breakpoint here", self.main_source_file25 )26 27 outer_bkpt = target.BreakpointCreateBySourceRegex(28 "Set outer breakpoint here", self.main_source_file29 )30 cmd_file_path = os.path.join(self.getSourceDir(), f"{self.callback_module}.py")31 self.runCmd(f"command script import {cmd_file_path}")32 outer_bkpt.SetScriptCallbackFunction(f"{self.callback_module}.outer_callback")33 34 process.Continue()35 36 self.assertEqual(37 thread.stop_reason, lldb.eStopReasonBreakpoint, "Right stop reason"38 )39 40 bkpt_no = thread.stop_reason_data[0]41 42 # We made the callbacks record the new breakpoint ID and the number of43 # times a callback ran in some globals in the target. Find them now:44 exec_module = target.FindModule(target.executable)45 self.assertTrue(exec_module.IsValid(), "Found executable module")46 var = exec_module.FindFirstGlobalVariable(target, "g_global")47 self.assertSuccess(var.GetError(), "Found globals")48 num_hits = var.GetChildAtIndex(1).GetValueAsUnsigned()49 inner_id = var.GetChildAtIndex(2).GetValueAsUnsigned()50 51 # Make sure they have the right values:52 self.assertEqual(bkpt_no, inner_id, "Hit the right breakpoint")53 self.assertEqual(num_hits, 2, "Right counter end value")54 self.assertEqual(thread.frames[0].name, "main", "Got to main")55 56 self.assertEqual(outer_bkpt.GetHitCount(), 1, "Hit outer breakpoint once")57 58 inner_bkpt = target.FindBreakpointByID(inner_id)59 self.assertEqual(inner_bkpt.GetHitCount(), 1, "Hit inner breakpoint once")60