• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1"""Test calling functions in static methods with a stripped binary."""
2
3import os, time
4import unittest2
5import lldb
6import lldbutil
7from lldbtest import *
8
9class TestObjCStaticMethodStripped(TestBase):
10
11    mydir = os.path.join("lang", "objc", "objc-static-method-stripped")
12
13    @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
14    @python_api_test
15    #<rdar://problem/12042992>
16    @dsym_test
17    def test_with_dsym_and_python_api(self):
18        """Test calling functions in static methods with a stripped binary."""
19        if self.getArchitecture() == 'i386':
20            self.skipTest("requires modern objc runtime")
21        self.buildDsym()
22        self.objc_static_method_stripped()
23
24    def setUp(self):
25        # Call super's setUp().
26        TestBase.setUp(self)
27        # Find the line numbers to break inside main().
28        self.main_source = "static.m"
29        self.break_line = line_number(self.main_source, '// Set breakpoint here.')
30
31    #<rdar://problem/12042992>
32    def objc_static_method_stripped(self):
33        """Test calling functions in static methods with a stripped binary."""
34        exe = os.path.join(os.getcwd(), "a.out.stripped")
35
36        target = self.dbg.CreateTarget(exe)
37        self.assertTrue(target, VALID_TARGET)
38
39        bpt = target.BreakpointCreateByLocation(self.main_source, self.break_line)
40        self.assertTrue(bpt, VALID_BREAKPOINT)
41
42        # Now launch the process, and do not stop at entry point.
43        process = target.LaunchSimple (None, None, os.getcwd())
44
45        self.assertTrue(process, PROCESS_IS_VALID)
46
47        # The stop reason of the thread should be breakpoint.
48        thread_list = lldbutil.get_threads_stopped_at_breakpoint (process, bpt)
49
50        # Make sure we stopped at the first breakpoint.
51        self.assertTrue (len(thread_list) != 0, "No thread stopped at our breakpoint.")
52        self.assertTrue (len(thread_list) == 1, "More than one thread stopped at our breakpoint.")
53
54        # Now make sure we can call a function in the static method we've stopped in.
55        frame = thread_list[0].GetFrameAtIndex(0)
56        self.assertTrue (frame, "Got a valid frame 0 frame.")
57
58        cmd_value = frame.EvaluateExpression ("(char *) sel_getName (_cmd)")
59        self.assertTrue (cmd_value.IsValid())
60        sel_name = cmd_value.GetSummary()
61        self.assertTrue (sel_name == "\"doSomethingWithString:\"", "Got the right value for the selector as string.")
62
63        cmd_value = frame.EvaluateExpression ("[Foo doSomethingElseWithString:string]")
64        self.assertTrue (cmd_value.IsValid())
65        string_length = cmd_value.GetValueAsUnsigned()
66        self.assertTrue (string_length == 27, "Got the right value from another class method on the same class.")
67
68if __name__ == '__main__':
69    import atexit
70    lldb.SBDebugger.Initialize()
71    atexit.register(lambda: lldb.SBDebugger.Terminate())
72    unittest2.main()
73