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