1"""Test calling functions in static methods.""" 2 3 4 5import lldb 6from lldbsuite.test.decorators import * 7from lldbsuite.test.lldbtest import * 8from lldbsuite.test import lldbutil 9 10 11class TestObjCStaticMethod(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 #<rdar://problem/9745789> "expression" can't call functions in class methods 23 def test_with_python_api(self): 24 """Test calling functions in static methods.""" 25 self.build() 26 exe = self.getBuildArtifact("a.out") 27 28 target = self.dbg.CreateTarget(exe) 29 self.assertTrue(target, VALID_TARGET) 30 31 bpt = target.BreakpointCreateByLocation( 32 self.main_source, self.break_line) 33 self.assertTrue(bpt, VALID_BREAKPOINT) 34 35 # Now launch the process, and do not stop at entry point. 36 process = target.LaunchSimple( 37 None, None, self.get_process_working_directory()) 38 39 self.assertTrue(process, PROCESS_IS_VALID) 40 41 # The stop reason of the thread should be breakpoint. 42 thread_list = lldbutil.get_threads_stopped_at_breakpoint(process, bpt) 43 44 # Make sure we stopped at the first breakpoint. 45 self.assertNotEqual( 46 len(thread_list), 0, 47 "No thread stopped at our breakpoint.") 48 self.assertEquals(len(thread_list), 1, 49 "More than one thread stopped at our breakpoint.") 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, "\"doSomethingWithString:\"", 61 "Got the right value for the selector as string.") 62 63 cmd_value = frame.EvaluateExpression( 64 "[self doSomethingElseWithString:string]") 65 self.assertTrue(cmd_value.IsValid()) 66 string_length = cmd_value.GetValueAsUnsigned() 67 self.assertEqual( 68 string_length, 27, 69 "Got the right value from another class method on the same class.") 70