]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - packages/Python/lldbsuite/test/lang/objc/objc-stepping/TestObjCStepping.py
Vendor import of lldb release_39 branch r276489:
[FreeBSD/FreeBSD.git] / packages / Python / lldbsuite / test / lang / objc / objc-stepping / TestObjCStepping.py
1 """Test stepping through ObjC method dispatch in various forms."""
2
3 from __future__ import print_function
4
5
6
7 import os, time
8 import lldb
9 from lldbsuite.test.decorators import *
10 from lldbsuite.test.lldbtest import *
11 from lldbsuite.test import lldbutil
12
13 class TestObjCStepping(TestBase):
14
15     def getCategories (self):
16         return ['basic_process']
17
18     mydir = TestBase.compute_mydir(__file__)
19
20     def setUp(self):
21         # Call super's setUp().
22         TestBase.setUp(self)
23         # Find the line numbers that we will step to in main:
24         self.main_source = "stepping-tests.m"
25         self.source_randomMethod_line = line_number (self.main_source, '// Source randomMethod start line.')
26         self.sourceBase_randomMethod_line = line_number (self.main_source, '// SourceBase randomMethod start line.')
27         self.source_returnsStruct_start_line = line_number (self.main_source, '// Source returnsStruct start line.')
28         self.sourceBase_returnsStruct_start_line = line_number (self.main_source, '// SourceBase returnsStruct start line.')
29         self.stepped_past_nil_line = line_number (self.main_source, '// Step over nil should stop here.')
30
31     @skipUnlessDarwin
32     @add_test_categories(['pyapi'])
33     def test_with_python_api(self):
34         """Test stepping through ObjC method dispatch in various forms."""
35         self.build()
36         exe = os.path.join(os.getcwd(), "a.out")
37
38         target = self.dbg.CreateTarget(exe)
39         self.assertTrue(target, VALID_TARGET)
40
41         self.main_source_spec = lldb.SBFileSpec (self.main_source)
42
43         breakpoints_to_disable = []
44
45         break1 = target.BreakpointCreateBySourceRegex ("// Set first breakpoint here.", self.main_source_spec)
46         self.assertTrue(break1, VALID_BREAKPOINT)
47         breakpoints_to_disable.append (break1)
48
49         break2 = target.BreakpointCreateBySourceRegex ("// Set second breakpoint here.", self.main_source_spec)
50         self.assertTrue(break2, VALID_BREAKPOINT)
51         breakpoints_to_disable.append (break2)
52
53         break3 = target.BreakpointCreateBySourceRegex ('// Set third breakpoint here.', self.main_source_spec)
54         self.assertTrue(break3, VALID_BREAKPOINT)
55         breakpoints_to_disable.append (break3)
56
57         break4 = target.BreakpointCreateBySourceRegex ('// Set fourth breakpoint here.', self.main_source_spec)
58         self.assertTrue(break4, VALID_BREAKPOINT)
59         breakpoints_to_disable.append (break4)
60
61         break5 = target.BreakpointCreateBySourceRegex ('// Set fifth breakpoint here.', self.main_source_spec)
62         self.assertTrue(break5, VALID_BREAKPOINT)
63         breakpoints_to_disable.append (break5)
64
65         break_returnStruct_call_super = target.BreakpointCreateBySourceRegex ('// Source returnsStruct call line.', self.main_source_spec)
66         self.assertTrue(break_returnStruct_call_super, VALID_BREAKPOINT)
67         breakpoints_to_disable.append (break_returnStruct_call_super)
68
69         break_step_nil = target.BreakpointCreateBySourceRegex ('// Set nil step breakpoint here.', self.main_source_spec)
70         self.assertTrue(break_step_nil, VALID_BREAKPOINT)
71
72         # Now launch the process, and do not stop at entry point.
73         process = target.LaunchSimple (None, None, self.get_process_working_directory())
74
75         self.assertTrue(process, PROCESS_IS_VALID)
76
77         # The stop reason of the thread should be breakpoint.
78         threads = lldbutil.get_threads_stopped_at_breakpoint (process, break1)
79         if len(threads) != 1:
80             self.fail ("Failed to stop at breakpoint 1.")
81
82         thread = threads[0]
83
84         mySource = thread.GetFrameAtIndex(0).FindVariable("mySource")
85         self.assertTrue(mySource, "Found mySource local variable.")
86         mySource_isa = mySource.GetChildMemberWithName ("isa")
87         self.assertTrue(mySource_isa, "Found mySource->isa local variable.")
88         className = mySource_isa.GetSummary ()
89
90         if self.TraceOn():
91              print(mySource_isa)
92
93         # Lets delete mySource so we can check that after stepping a child variable
94         # with no parent persists and is useful.
95         del (mySource)
96
97         # Now step in, that should leave us in the Source randomMethod:
98         thread.StepInto()
99         line_number = thread.GetFrameAtIndex(0).GetLineEntry().GetLine()
100         self.assertTrue (line_number == self.source_randomMethod_line, "Stepped into Source randomMethod.")
101
102         # Now step in again, through the super call, and that should leave us in the SourceBase randomMethod:
103         thread.StepInto()
104         line_number = thread.GetFrameAtIndex(0).GetLineEntry().GetLine()
105         self.assertTrue (line_number == self.sourceBase_randomMethod_line, "Stepped through super into SourceBase randomMethod.")
106
107         threads = lldbutil.continue_to_breakpoint (process, break2)
108         self.assertTrue (len(threads) == 1, "Continued to second breakpoint in main.")
109
110         # Again, step in twice gets us to a stret method and a stret super call:
111         thread = threads[0]
112         thread.StepInto()
113         line_number = thread.GetFrameAtIndex(0).GetLineEntry().GetLine()
114         self.assertTrue (line_number == self.source_returnsStruct_start_line, "Stepped into Source returnsStruct.")
115
116         threads = lldbutil.continue_to_breakpoint (process, break_returnStruct_call_super)
117         self.assertTrue (len(threads) == 1, "Stepped to the call super line in Source returnsStruct.")
118         thread = threads[0]
119
120         thread.StepInto()
121         line_number = thread.GetFrameAtIndex(0).GetLineEntry().GetLine()
122         self.assertTrue (line_number == self.sourceBase_returnsStruct_start_line, "Stepped through super into SourceBase returnsStruct.")
123
124         # Cool now continue to get past the call that initializes the Observer, and then do our steps in again to see that 
125         # we can find our way when we're stepping through a KVO swizzled object.
126
127         threads = lldbutil.continue_to_breakpoint (process, break3)
128         self.assertTrue (len(threads) == 1, "Continued to third breakpoint in main, our object should now be swizzled.")
129
130         newClassName = mySource_isa.GetSummary ()
131
132         if self.TraceOn():
133              print(mySource_isa)
134
135         self.assertTrue (newClassName != className, "The isa did indeed change, swizzled!")
136
137         # Now step in, that should leave us in the Source randomMethod:
138         thread = threads[0]
139         thread.StepInto()
140         line_number = thread.GetFrameAtIndex(0).GetLineEntry().GetLine()
141         self.assertTrue (line_number == self.source_randomMethod_line, "Stepped into Source randomMethod in swizzled object.")
142
143         # Now step in again, through the super call, and that should leave us in the SourceBase randomMethod:
144         thread.StepInto()
145         line_number = thread.GetFrameAtIndex(0).GetLineEntry().GetLine()
146         self.assertTrue (line_number == self.sourceBase_randomMethod_line, "Stepped through super into SourceBase randomMethod in swizzled object.")
147
148         threads = lldbutil.continue_to_breakpoint (process, break4)
149         self.assertTrue (len(threads) == 1, "Continued to fourth breakpoint in main.")
150         thread = threads[0]
151
152         # Again, step in twice gets us to a stret method and a stret super call:
153         thread.StepInto()
154         line_number = thread.GetFrameAtIndex(0).GetLineEntry().GetLine()
155         self.assertTrue (line_number == self.source_returnsStruct_start_line, "Stepped into Source returnsStruct in swizzled object.")
156
157         threads = lldbutil.continue_to_breakpoint(process, break_returnStruct_call_super)
158         self.assertTrue (len(threads) == 1, "Stepped to the call super line in Source returnsStruct - second time.")
159         thread = threads[0]
160
161         thread.StepInto()
162         line_number = thread.GetFrameAtIndex(0).GetLineEntry().GetLine()
163         self.assertTrue (line_number == self.sourceBase_returnsStruct_start_line, "Stepped through super into SourceBase returnsStruct in swizzled object.")
164
165         for bkpt in breakpoints_to_disable:
166             bkpt.SetEnabled(False)
167
168         threads = lldbutil.continue_to_breakpoint (process, break_step_nil)
169         self.assertTrue (len(threads) == 1, "Continued to step nil breakpoint.")
170
171         thread.StepInto()
172         line_number = thread.GetFrameAtIndex(0).GetLineEntry().GetLine()
173         self.assertTrue (line_number == self.stepped_past_nil_line, "Step in over dispatch to nil stepped over.")