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    @skipUnlessDarwin
24    @add_test_categories(['pyapi', 'basic_process'])
25    def test_with_python_api(self):
26        """Test stepping through the 'direct dispatch' optimized method calls."""
27        self.build()
28
29        (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(self,
30                                                                            "Stop here to start stepping",
31                                                                            self.main_source)
32        stop_bkpt = target.BreakpointCreateBySourceRegex("// Stop Location [0-9]+", self.main_source)
33        self.assertEqual(stop_bkpt.GetNumLocations(), 15)
34
35        # Here we step through all the overridden methods of OverridesALot
36        # The last continue will get us to the call ot OverridesInit.
37        for idx in range(2,16):
38            thread.StepInto()
39            func_name = thread.GetFrameAtIndex(0).GetFunctionName()
40            self.assertTrue("OverridesALot" in func_name, "%d'th step did not match name: %s"%(idx, func_name))
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(func_name, "-[OverridesInit init]", "Stopped in [OverridesInit init]")
48
49
50
51