50 lines · python
1"""Test stepping through ObjC method dispatch in various forms."""2 3import lldb4from lldbsuite.test.decorators import *5from lldbsuite.test.lldbtest import *6from lldbsuite.test import lldbutil7 8 9class TestObjCDirectDispatchStepping(TestBase):10 NO_DEBUG_INFO_TESTCASE = True11 12 def setUp(self):13 # Call super's setUp().14 TestBase.setUp(self)15 # Find the line numbers that we will step to in main:16 self.main_source = lldb.SBFileSpec("stepping-tests.m")17 18 @add_test_categories(["pyapi", "basic_process"])19 def test_with_python_api(self):20 """Test stepping through the 'direct dispatch' optimized method calls."""21 self.build()22 23 (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(24 self, "Stop here to start stepping", self.main_source25 )26 stop_bkpt = target.BreakpointCreateBySourceRegex(27 "// Stop Location [0-9]+", self.main_source28 )29 self.assertEqual(stop_bkpt.GetNumLocations(), 15)30 31 # Here we step through all the overridden methods of OverridesALot32 # The last continue will get us to the call ot OverridesInit.33 for idx in range(2, 16):34 thread.StepInto()35 func_name = thread.GetFrameAtIndex(0).GetFunctionName()36 self.assertIn(37 "OverridesALot",38 func_name,39 "%d'th step did not match name: %s" % (idx, func_name),40 )41 stop_threads = lldbutil.continue_to_breakpoint(process, stop_bkpt)42 self.assertEqual(len(stop_threads), 1)43 self.assertEqual(stop_threads[0], thread)44 45 thread.StepInto()46 func_name = thread.GetFrameAtIndex(0).GetFunctionName()47 self.assertEqual(48 func_name, "-[OverridesInit init]", "Stopped in [OverridesInit init]"49 )50