[AMDGPU] Add True16 register classes.
[llvm-project.git] / lldb / test / API / lang / c / stepping / TestStepAndBreakpoints.py
blob15b65ad35bcdb52966d7c358ee90c7963870927c
1 """Test stepping over vrs. hitting breakpoints & subsequent stepping in various forms."""
4 import lldb
5 from lldbsuite.test.decorators import *
6 from lldbsuite.test.lldbtest import *
7 from lldbsuite.test import lldbutil
10 class TestCStepping(TestBase):
11 def setUp(self):
12 # Call super's setUp().
13 TestBase.setUp(self)
14 # Find the line numbers that we will step to in main:
15 self.main_source = "main.c"
17 @add_test_categories(["pyapi", "basic_process"])
18 @expectedFailureAll(oslist=["freebsd"], bugnumber="llvm.org/pr17932")
19 @expectedFailureAll(oslist=["linux"], archs=no_match(["i386", "x86_64"]))
20 @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24777")
21 @expectedFailureNetBSD
22 def test_and_python_api(self):
23 """Test stepping over vrs. hitting breakpoints & subsequent stepping in various forms."""
24 self.build()
25 exe = self.getBuildArtifact("a.out")
27 target = self.dbg.CreateTarget(exe)
28 self.assertTrue(target, VALID_TARGET)
30 self.main_source_spec = lldb.SBFileSpec(self.main_source)
32 breakpoints_to_disable = []
34 break_1_in_main = target.BreakpointCreateBySourceRegex(
35 "// frame select 2, thread step-out while stopped at .c.1..",
36 self.main_source_spec,
38 self.assertTrue(break_1_in_main, VALID_BREAKPOINT)
39 breakpoints_to_disable.append(break_1_in_main)
41 break_in_a = target.BreakpointCreateBySourceRegex(
42 "// break here to stop in a before calling b", self.main_source_spec
44 self.assertTrue(break_in_a, VALID_BREAKPOINT)
45 breakpoints_to_disable.append(break_in_a)
47 break_in_b = target.BreakpointCreateBySourceRegex(
48 "// thread step-out while stopped at .c.2..", self.main_source_spec
50 self.assertTrue(break_in_b, VALID_BREAKPOINT)
51 breakpoints_to_disable.append(break_in_b)
53 break_in_c = target.BreakpointCreateBySourceRegex(
54 "// Find the line number of function .c. here.", self.main_source_spec
56 self.assertTrue(break_in_c, VALID_BREAKPOINT)
57 breakpoints_to_disable.append(break_in_c)
59 # Now launch the process, and do not stop at entry point.
60 process = target.LaunchSimple(None, None, self.get_process_working_directory())
62 self.assertTrue(process, PROCESS_IS_VALID)
64 # The stop reason of the thread should be breakpoint.
65 threads = lldbutil.get_threads_stopped_at_breakpoint(process, break_1_in_main)
67 if len(threads) != 1:
68 self.fail("Failed to stop at first breakpoint in main.")
70 thread = threads[0]
72 # Get the stop id and for fun make sure it increases:
73 old_stop_id = process.GetStopID()
75 # Now step over, which should cause us to hit the breakpoint in "a"
76 thread.StepOver()
78 # The stop reason of the thread should be breakpoint.
79 threads = lldbutil.get_threads_stopped_at_breakpoint(process, break_in_a)
80 if len(threads) != 1:
81 self.fail("Failed to stop at breakpoint in a.")
83 # Check that the stop ID increases:
84 new_stop_id = process.GetStopID()
85 self.assertTrue(new_stop_id > old_stop_id, "Stop ID increases monotonically.")
87 thread = threads[0]
89 # Step over, and we should hit the breakpoint in b:
90 thread.StepOver()
92 threads = lldbutil.get_threads_stopped_at_breakpoint(process, break_in_b)
93 if len(threads) != 1:
94 self.fail("Failed to stop at breakpoint in b.")
95 thread = threads[0]
97 # Now try running some function, and make sure that we still end up in the same place
98 # and with the same stop reason.
99 frame = thread.GetFrameAtIndex(0)
100 current_line = frame.GetLineEntry().GetLine()
101 current_file = frame.GetLineEntry().GetFileSpec()
102 current_bp = []
103 current_bp.append(thread.GetStopReasonDataAtIndex(0))
104 current_bp.append(thread.GetStopReasonDataAtIndex(1))
106 stop_id_before_expression = process.GetStopID()
107 stop_id_before_including_expressions = process.GetStopID(True)
109 frame.EvaluateExpression("(int) printf (print_string)")
111 frame = thread.GetFrameAtIndex(0)
112 self.assertEqual(
113 current_line,
114 frame.GetLineEntry().GetLine(),
115 "The line stayed the same after expression.",
117 self.assertEqual(
118 current_file,
119 frame.GetLineEntry().GetFileSpec(),
120 "The file stayed the same after expression.",
122 self.assertEqual(
123 thread.GetStopReason(),
124 lldb.eStopReasonBreakpoint,
125 "We still say we stopped for a breakpoint.",
127 self.assertTrue(
128 thread.GetStopReasonDataAtIndex(0) == current_bp[0]
129 and thread.GetStopReasonDataAtIndex(1) == current_bp[1],
130 "And it is the same breakpoint.",
133 # Also make sure running the expression didn't change the public stop id
134 # but did change if we are asking for expression stops as well.
135 stop_id_after_expression = process.GetStopID()
136 stop_id_after_including_expressions = process.GetStopID(True)
138 self.assertEqual(
139 stop_id_before_expression,
140 stop_id_after_expression,
141 "Expression calling doesn't change stop ID",
144 self.assertTrue(
145 stop_id_after_including_expressions > stop_id_before_including_expressions,
146 "Stop ID including expressions increments over expression call.",
149 # Do the same thing with an expression that's going to crash, and make
150 # sure we are still unchanged.
152 frame.EvaluateExpression("((char *) 0)[0] = 'a'")
154 frame = thread.GetFrameAtIndex(0)
155 self.assertEqual(
156 current_line,
157 frame.GetLineEntry().GetLine(),
158 "The line stayed the same after expression.",
160 self.assertEqual(
161 current_file,
162 frame.GetLineEntry().GetFileSpec(),
163 "The file stayed the same after expression.",
165 self.assertEqual(
166 thread.GetStopReason(),
167 lldb.eStopReasonBreakpoint,
168 "We still say we stopped for a breakpoint.",
170 self.assertTrue(
171 thread.GetStopReasonDataAtIndex(0) == current_bp[0]
172 and thread.GetStopReasonDataAtIndex(1) == current_bp[1],
173 "And it is the same breakpoint.",
176 # Now continue and make sure we just complete the step:
177 # Disable all our breakpoints first - sometimes the compiler puts two line table entries in for the
178 # breakpoint a "b" and we don't want to hit that.
179 for bkpt in breakpoints_to_disable:
180 bkpt.SetEnabled(False)
182 process.Continue()
184 self.assertEqual(thread.GetFrameAtIndex(0).GetFunctionName(), "a")
185 self.assertStopReason(thread.GetStopReason(), lldb.eStopReasonPlanComplete)
187 # And one more time should get us back to main:
188 process.Continue()
190 self.assertEqual(thread.GetFrameAtIndex(0).GetFunctionName(), "main")
191 self.assertStopReason(thread.GetStopReason(), lldb.eStopReasonPlanComplete)
193 # Now make sure we can call a function, break in the called function,
194 # then have "continue" get us back out again:
195 frame = thread.GetFrameAtIndex(0)
196 frame = thread.GetFrameAtIndex(0)
197 current_line = frame.GetLineEntry().GetLine()
198 current_file = frame.GetLineEntry().GetFileSpec()
200 break_in_b.SetEnabled(True)
201 options = lldb.SBExpressionOptions()
202 options.SetIgnoreBreakpoints(False)
203 options.SetFetchDynamicValue(False)
204 options.SetUnwindOnError(False)
205 frame.EvaluateExpression("b (4)", options)
207 threads = lldbutil.get_threads_stopped_at_breakpoint(process, break_in_b)
209 if len(threads) != 1:
210 self.fail("Failed to stop at breakpoint in b when calling b.")
211 thread = threads[0]
213 # So do a step over here to make sure we can still do that:
215 thread.StepOver()
217 # See that we are still in b:
218 func_name = thread.GetFrameAtIndex(0).GetFunctionName()
219 self.assertEqual(func_name, "b", "Should be in 'b', were in %s" % (func_name))
221 # Okay, now if we continue, we will finish off our function call and we
222 # should end up back in "a" as if nothing had happened:
223 process.Continue()
225 self.assertEqual(
226 thread.GetFrameAtIndex(0).GetLineEntry().GetLine(), current_line
228 self.assertEqual(
229 thread.GetFrameAtIndex(0).GetLineEntry().GetFileSpec(), current_file
232 # Now we are going to test step in targeting a function:
234 break_in_b.SetEnabled(False)
236 break_before_complex_1 = target.BreakpointCreateBySourceRegex(
237 "// Stop here to try step in targeting b.", self.main_source_spec
239 self.assertTrue(break_before_complex_1, VALID_BREAKPOINT)
241 break_before_complex_2 = target.BreakpointCreateBySourceRegex(
242 "// Stop here to try step in targeting complex.", self.main_source_spec
244 self.assertTrue(break_before_complex_2, VALID_BREAKPOINT)
246 break_before_complex_3 = target.BreakpointCreateBySourceRegex(
247 "// Stop here to step targeting b and hitting breakpoint.",
248 self.main_source_spec,
250 self.assertTrue(break_before_complex_3, VALID_BREAKPOINT)
252 break_before_complex_4 = target.BreakpointCreateBySourceRegex(
253 "// Stop here to make sure bogus target steps over.", self.main_source_spec
255 self.assertTrue(break_before_complex_4, VALID_BREAKPOINT)
257 threads = lldbutil.continue_to_breakpoint(process, break_before_complex_1)
258 self.assertEqual(len(threads), 1)
259 thread = threads[0]
260 break_before_complex_1.SetEnabled(False)
262 thread.StepInto("b")
263 self.assertEqual(thread.GetFrameAtIndex(0).GetFunctionName(), "b")
265 # Now continue out and stop at the next call to complex. This time
266 # step all the way into complex:
267 threads = lldbutil.continue_to_breakpoint(process, break_before_complex_2)
268 self.assertEqual(len(threads), 1)
269 thread = threads[0]
270 break_before_complex_2.SetEnabled(False)
272 thread.StepInto("complex")
273 self.assertEqual(thread.GetFrameAtIndex(0).GetFunctionName(), "complex")
275 # Now continue out and stop at the next call to complex. This time
276 # enable breakpoints in a and c and then step targeting b:
277 threads = lldbutil.continue_to_breakpoint(process, break_before_complex_3)
278 self.assertEqual(len(threads), 1)
279 thread = threads[0]
280 break_before_complex_3.SetEnabled(False)
282 break_at_start_of_a = target.BreakpointCreateByName("a")
283 break_at_start_of_c = target.BreakpointCreateByName("c")
285 thread.StepInto("b")
286 threads = lldbutil.get_stopped_threads(process, lldb.eStopReasonBreakpoint)
288 self.assertEqual(len(threads), 1)
289 thread = threads[0]
290 stop_break_id = thread.GetStopReasonDataAtIndex(0)
291 self.assertTrue(
292 stop_break_id == break_at_start_of_a.GetID()
293 or stop_break_id == break_at_start_of_c.GetID()
296 break_at_start_of_a.SetEnabled(False)
297 break_at_start_of_c.SetEnabled(False)
299 process.Continue()
300 self.assertEqual(thread.GetFrameAtIndex(0).GetFunctionName(), "b")
302 # Now continue out and stop at the next call to complex. This time
303 # enable breakpoints in a and c and then step targeting b:
304 threads = lldbutil.continue_to_breakpoint(process, break_before_complex_4)
305 self.assertEqual(len(threads), 1)
306 thread = threads[0]
307 break_before_complex_4.SetEnabled(False)
309 thread.StepInto("NoSuchFunction")
310 self.assertEqual(thread.GetFrameAtIndex(0).GetFunctionName(), "main")