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 # this test program only builds for ios with -gmodules 22 @add_test_categories(['gmodules', 'pyapi']) 23 @skipIf(oslist=['ios', 'watchos', 'tvos', 'bridgeos'], archs=['armv7', 'arm64']) 24 def test_with_python_api(self): 25 """Test passing structs to Objective-C methods.""" 26 self.build() 27 exe = self.getBuildArtifact("a.out") 28 29 target = self.dbg.CreateTarget(exe) 30 self.assertTrue(target, VALID_TARGET) 31 32 bpt = target.BreakpointCreateByLocation( 33 self.main_source, self.break_line) 34 self.assertTrue(bpt, VALID_BREAKPOINT) 35 36 # Now launch the process, and do not stop at entry point. 37 process = target.LaunchSimple( 38 None, None, self.get_process_working_directory()) 39 40 self.assertTrue(process, PROCESS_IS_VALID) 41 42 # The stop reason of the thread should be breakpoint. 43 thread_list = lldbutil.get_threads_stopped_at_breakpoint(process, bpt) 44 45 # Make sure we stopped at the first breakpoint. 46 self.assertTrue( 47 len(thread_list) != 0, 48 "No thread stopped at our breakpoint.") 49 self.assertEquals(len(thread_list), 1, 50 "More than one thread stopped at our breakpoint.") 51 52 frame = thread_list[0].GetFrameAtIndex(0) 53 self.assertTrue(frame, "Got a valid frame 0 frame.") 54 55 self.expect("expression [summer sumThings:tts]", substrs=['9']) 56 57 self.expect( 58 "po [NSValue valueWithRect:rect]", 59 substrs=['NSRect: {{0, 0}, {10, 20}}']) 60 61 # Now make sure we can call a method that returns a struct without 62 # crashing. 63 cmd_value = frame.EvaluateExpression("[provider getRange]") 64 self.assertTrue(cmd_value.IsValid()) 65