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