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