1"""Test calling functions in class methods.""" 2 3 4import lldb 5from lldbsuite.test.decorators import * 6from lldbsuite.test.lldbtest import * 7from lldbsuite.test import lldbutil 8 9 10class TestObjCClassMethod(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 = "test.m" 16 self.break_line = line_number(self.main_source, "// Set breakpoint here.") 17 18 @add_test_categories(["pyapi"]) 19 def test_with_python_api(self): 20 """Test calling functions in class methods.""" 21 self.build() 22 exe = self.getBuildArtifact("a.out") 23 24 target = self.dbg.CreateTarget(exe) 25 self.assertTrue(target, VALID_TARGET) 26 27 bpt = target.BreakpointCreateByLocation(self.main_source, self.break_line) 28 self.assertTrue(bpt, VALID_BREAKPOINT) 29 30 # Now launch the process, and do not stop at entry point. 31 process = target.LaunchSimple(None, None, self.get_process_working_directory()) 32 33 self.assertTrue(process, PROCESS_IS_VALID) 34 35 # The stop reason of the thread should be breakpoint. 36 thread_list = lldbutil.get_threads_stopped_at_breakpoint(process, bpt) 37 38 # Make sure we stopped at the first breakpoint. 39 self.assertNotEqual(len(thread_list), 0, "No thread stopped at our breakpoint.") 40 self.assertEqual( 41 len(thread_list), 1, "More than one thread stopped at our breakpoint." 42 ) 43 44 frame = thread_list[0].GetFrameAtIndex(0) 45 self.assertTrue(frame, "Got a valid frame 0 frame.") 46 47 # Now make sure we can call a method that returns a struct without 48 # crashing. 49 cmd_value = frame.EvaluateExpression("[provider getRange]") 50 self.assertTrue(cmd_value.IsValid()) 51