1"""Test passing structs to Objective-C methods.""" 2 3 4 5import lldb 6from lldbsuite.test.decorators import * 7from lldbsuite.test.lldbtest import * 8from lldbsuite.test import lldbutil 9 10 11class TestObjCStructArgument(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 = "test.m" 18 self.break_line = line_number( 19 self.main_source, '// Set breakpoint here.') 20 21 @add_test_categories(['pyapi']) 22 @skipIf(debug_info=no_match(["gmodules"]), oslist=['ios', 'watchos', 'tvos', 'bridgeos'], archs=['armv7', 'arm64']) # this test program only builds for ios with -gmodules 23 def test_with_python_api(self): 24 """Test passing structs to Objective-C 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.assertTrue( 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 frame = thread_list[0].GetFrameAtIndex(0) 52 self.assertTrue(frame, "Got a valid frame 0 frame.") 53 54 self.expect("p [summer sumThings:tts]", substrs=['9']) 55 56 self.expect( 57 "po [NSValue valueWithRect:rect]", 58 substrs=['NSRect: {{0, 0}, {10, 20}}']) 59 60 # Now make sure we can call a method that returns a struct without 61 # crashing. 62 cmd_value = frame.EvaluateExpression("[provider getRange]") 63 self.assertTrue(cmd_value.IsValid()) 64