1"""Test calling functions in class methods.""" 2 3import lldb 4from lldbsuite.test.decorators import * 5from lldbsuite.test.lldbtest import * 6from lldbsuite.test import lldbutil 7 8 9class TestObjCClassMethod(TestBase): 10 def setUp(self): 11 # Call super's setUp(). 12 TestBase.setUp(self) 13 # Find the line numbers to break inside main(). 14 self.main_source = "class.m" 15 self.break_line = line_number(self.main_source, "// Set breakpoint here.") 16 17 @add_test_categories(["pyapi"]) 18 def test_with_python_api(self): 19 """Test calling functions in class methods.""" 20 self.build() 21 exe = self.getBuildArtifact("a.out") 22 23 target = self.dbg.CreateTarget(exe) 24 self.assertTrue(target, VALID_TARGET) 25 26 bpt = target.BreakpointCreateByLocation(self.main_source, self.break_line) 27 self.assertTrue(bpt, VALID_BREAKPOINT) 28 29 # Now launch the process, and do not stop at entry point. 30 process = target.LaunchSimple(None, None, self.get_process_working_directory()) 31 32 self.assertTrue(process, PROCESS_IS_VALID) 33 34 # The stop reason of the thread should be breakpoint. 35 thread_list = lldbutil.get_threads_stopped_at_breakpoint(process, bpt) 36 37 # Make sure we stopped at the first breakpoint. 38 self.assertNotEqual(len(thread_list), 0, "No thread stopped at our breakpoint.") 39 self.assertEqual( 40 len(thread_list), 1, "More than one thread stopped at our breakpoint." 41 ) 42 43 # Now make sure we can call a function in the class method we've 44 # stopped in. 45 frame = thread_list[0].GetFrameAtIndex(0) 46 self.assertTrue(frame, "Got a valid frame 0 frame.") 47 48 cmd_value = frame.EvaluateExpression( 49 '(int)[Foo doSomethingWithString:@"Hello"]' 50 ) 51 if self.TraceOn(): 52 if cmd_value.IsValid(): 53 print("cmd_value is valid") 54 print("cmd_value has the value %d" % cmd_value.GetValueAsUnsigned()) 55 self.assertTrue(cmd_value.IsValid()) 56 self.assertEqual(cmd_value.GetValueAsUnsigned(), 5) 57