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