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