1"""Test calling functions in static methods with a stripped binary."""
2
3
4
5import lldb
6from lldbsuite.test.decorators import *
7from lldbsuite.test.lldbtest import *
8from lldbsuite.test import lldbutil
9
10
11class TestObjCStaticMethodStripped(TestBase):
12
13    def setUp(self):
14        # Call super's setUp().
15        TestBase.setUp(self)
16        # Find the line numbers to break inside main().
17        self.main_source = "static.m"
18        self.break_line = line_number(
19            self.main_source, '// Set breakpoint here.')
20
21    @add_test_categories(['pyapi'])
22    @skipIf(
23        debug_info=no_match("dsym"),
24        bugnumber="This test requires a stripped binary and a dSYM")
25    #<rdar://problem/12042992>
26    def test_with_python_api(self):
27        """Test calling functions in static methods with a stripped binary."""
28        if self.getArchitecture() == 'i386':
29            self.skipTest("requires modern objc runtime")
30        self.build()
31        exe = self.getBuildArtifact("a.out")
32
33        target = self.dbg.CreateTarget(exe)
34        self.assertTrue(target, VALID_TARGET)
35
36        bpt = target.BreakpointCreateByLocation(
37            self.main_source, self.break_line)
38        self.assertTrue(bpt, VALID_BREAKPOINT)
39
40        # Now launch the process, and do not stop at entry point.
41        process = target.LaunchSimple(
42            None, None, self.get_process_working_directory())
43
44        self.assertTrue(process, PROCESS_IS_VALID)
45
46        # The stop reason of the thread should be breakpoint.
47        thread_list = lldbutil.get_threads_stopped_at_breakpoint(process, bpt)
48
49        # Make sure we stopped at the first breakpoint.
50        self.assertNotEqual(
51            len(thread_list), 0,
52            "No thread stopped at our breakpoint.")
53        self.assertEquals(len(thread_list), 1,
54                        "More than one thread stopped at our breakpoint.")
55
56        # Now make sure we can call a function in the static method we've
57        # stopped in.
58        frame = thread_list[0].GetFrameAtIndex(0)
59        self.assertTrue(frame, "Got a valid frame 0 frame.")
60
61        cmd_value = frame.EvaluateExpression("(char *) sel_getName (_cmd)")
62        self.assertTrue(cmd_value.IsValid())
63        sel_name = cmd_value.GetSummary()
64        self.assertEqual(
65            sel_name, "\"doSomethingWithString:\"",
66            "Got the right value for the selector as string.")
67
68        cmd_value = frame.EvaluateExpression(
69            "[Foo doSomethingElseWithString:string]")
70        self.assertTrue(cmd_value.IsValid())
71        string_length = cmd_value.GetValueAsUnsigned()
72        self.assertEqual(
73            string_length, 27,
74            "Got the right value from another class method on the same class.")
75