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