28188afc14279198b7e92411b013dd584732a32c
[openbsd] /
1 """Test passing structs to Objective-C methods."""
2
3
4
5 import lldb
6 from lldbsuite.test.decorators import *
7 from lldbsuite.test.lldbtest import *
8 from lldbsuite.test import lldbutil
9
10
11 class TestObjCStructArgument(TestBase):
12
13     mydir = TestBase.compute_mydir(__file__)
14
15     def setUp(self):
16         # Call super's setUp().
17         TestBase.setUp(self)
18         # Find the line numbers to break inside main().
19         self.main_source = "test.m"
20         self.break_line = line_number(
21             self.main_source, '// Set breakpoint here.')
22
23     @skipUnlessDarwin
24     @add_test_categories(['pyapi'])
25     @skipIf(debug_info=no_match(["gmodules"]), oslist=['ios', 'watchos', 'tvos', 'bridgeos'], archs=['armv7', 'arm64'])  # this test program only builds for ios with -gmodules
26     def test_with_python_api(self):
27         """Test passing structs to Objective-C methods."""
28         self.build()
29         exe = self.getBuildArtifact("a.out")
30
31         target = self.dbg.CreateTarget(exe)
32         self.assertTrue(target, VALID_TARGET)
33
34         bpt = target.BreakpointCreateByLocation(
35             self.main_source, self.break_line)
36         self.assertTrue(bpt, VALID_BREAKPOINT)
37
38         # Now launch the process, and do not stop at entry point.
39         process = target.LaunchSimple(
40             None, None, self.get_process_working_directory())
41
42         self.assertTrue(process, PROCESS_IS_VALID)
43
44         # The stop reason of the thread should be breakpoint.
45         thread_list = lldbutil.get_threads_stopped_at_breakpoint(process, bpt)
46
47         # Make sure we stopped at the first breakpoint.
48         self.assertTrue(
49             len(thread_list) != 0,
50             "No thread stopped at our breakpoint.")
51         self.assertTrue(len(thread_list) == 1,
52                         "More than one thread stopped at our breakpoint.")
53
54         frame = thread_list[0].GetFrameAtIndex(0)
55         self.assertTrue(frame, "Got a valid frame 0 frame.")
56
57         self.expect("p [summer sumThings:tts]", substrs=['9'])
58
59         self.expect(
60             "po [NSValue valueWithRect:rect]",
61             substrs=['NSRect: {{0, 0}, {10, 20}}'])
62
63         # Now make sure we can call a method that returns a struct without
64         # crashing.
65         cmd_value = frame.EvaluateExpression("[provider getRange]")
66         self.assertTrue(cmd_value.IsValid())