diff options
Diffstat (limited to 'packages/Python/lldbsuite/test/lang/c/stepping')
-rw-r--r-- | packages/Python/lldbsuite/test/lang/c/stepping/TestStepAndBreakpoints.py | 205 | ||||
-rw-r--r-- | packages/Python/lldbsuite/test/lang/c/stepping/TestThreadStepping.py | 44 |
2 files changed, 154 insertions, 95 deletions
diff --git a/packages/Python/lldbsuite/test/lang/c/stepping/TestStepAndBreakpoints.py b/packages/Python/lldbsuite/test/lang/c/stepping/TestStepAndBreakpoints.py index cfaff91daa45f..d693e1dada51d 100644 --- a/packages/Python/lldbsuite/test/lang/c/stepping/TestStepAndBreakpoints.py +++ b/packages/Python/lldbsuite/test/lang/c/stepping/TestStepAndBreakpoints.py @@ -3,13 +3,14 @@ from __future__ import print_function - -import os, time +import os +import time import lldb from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * from lldbsuite.test import lldbutil + class TestCStepping(TestBase): mydir = TestBase.compute_mydir(__file__) @@ -35,36 +36,43 @@ class TestCStepping(TestBase): target = self.dbg.CreateTarget(exe) self.assertTrue(target, VALID_TARGET) - self.main_source_spec = lldb.SBFileSpec (self.main_source) + self.main_source_spec = lldb.SBFileSpec(self.main_source) breakpoints_to_disable = [] - break_1_in_main = target.BreakpointCreateBySourceRegex ('// frame select 2, thread step-out while stopped at .c.1..', self.main_source_spec) + break_1_in_main = target.BreakpointCreateBySourceRegex( + '// frame select 2, thread step-out while stopped at .c.1..', + self.main_source_spec) self.assertTrue(break_1_in_main, VALID_BREAKPOINT) - breakpoints_to_disable.append (break_1_in_main) + breakpoints_to_disable.append(break_1_in_main) - break_in_a = target.BreakpointCreateBySourceRegex ('// break here to stop in a before calling b', self.main_source_spec) + break_in_a = target.BreakpointCreateBySourceRegex( + '// break here to stop in a before calling b', self.main_source_spec) self.assertTrue(break_in_a, VALID_BREAKPOINT) - breakpoints_to_disable.append (break_in_a) + breakpoints_to_disable.append(break_in_a) - break_in_b = target.BreakpointCreateBySourceRegex ('// thread step-out while stopped at .c.2..', self.main_source_spec) + break_in_b = target.BreakpointCreateBySourceRegex( + '// thread step-out while stopped at .c.2..', self.main_source_spec) self.assertTrue(break_in_b, VALID_BREAKPOINT) - breakpoints_to_disable.append (break_in_b) + breakpoints_to_disable.append(break_in_b) - break_in_c = target.BreakpointCreateBySourceRegex ('// Find the line number of function .c. here.', self.main_source_spec) + break_in_c = target.BreakpointCreateBySourceRegex( + '// Find the line number of function .c. here.', self.main_source_spec) self.assertTrue(break_in_c, VALID_BREAKPOINT) - breakpoints_to_disable.append (break_in_c) + breakpoints_to_disable.append(break_in_c) # Now launch the process, and do not stop at entry point. - process = target.LaunchSimple (None, None, self.get_process_working_directory()) + process = target.LaunchSimple( + None, None, self.get_process_working_directory()) self.assertTrue(process, PROCESS_IS_VALID) # The stop reason of the thread should be breakpoint. - threads = lldbutil.get_threads_stopped_at_breakpoint (process, break_1_in_main) + threads = lldbutil.get_threads_stopped_at_breakpoint( + process, break_1_in_main) if len(threads) != 1: - self.fail ("Failed to stop at first breakpoint in main.") + self.fail("Failed to stop at first breakpoint in main.") thread = threads[0] @@ -75,22 +83,26 @@ class TestCStepping(TestBase): thread.StepOver() # The stop reason of the thread should be breakpoint. - threads = lldbutil.get_threads_stopped_at_breakpoint (process, break_in_a) + threads = lldbutil.get_threads_stopped_at_breakpoint( + process, break_in_a) if len(threads) != 1: - self.fail ("Failed to stop at breakpoint in a.") + self.fail("Failed to stop at breakpoint in a.") # Check that the stop ID increases: new_stop_id = process.GetStopID() - self.assertTrue(new_stop_id > old_stop_id, "Stop ID increases monotonically.") + self.assertTrue( + new_stop_id > old_stop_id, + "Stop ID increases monotonically.") thread = threads[0] # Step over, and we should hit the breakpoint in b: thread.StepOver() - threads = lldbutil.get_threads_stopped_at_breakpoint (process, break_in_b) + threads = lldbutil.get_threads_stopped_at_breakpoint( + process, break_in_b) if len(threads) != 1: - self.fail ("Failed to stop at breakpoint in b.") + self.fail("Failed to stop at breakpoint in b.") thread = threads[0] # Now try running some function, and make sure that we still end up in the same place @@ -105,32 +117,51 @@ class TestCStepping(TestBase): stop_id_before_expression = process.GetStopID() stop_id_before_including_expressions = process.GetStopID(True) - frame.EvaluateExpression ("(int) printf (print_string)") + frame.EvaluateExpression("(int) printf (print_string)") frame = thread.GetFrameAtIndex(0) - self.assertTrue (current_line == frame.GetLineEntry().GetLine(), "The line stayed the same after expression.") - self.assertTrue (current_file == frame.GetLineEntry().GetFileSpec(), "The file stayed the same after expression.") - self.assertTrue (thread.GetStopReason() == lldb.eStopReasonBreakpoint, "We still say we stopped for a breakpoint.") - self.assertTrue (thread.GetStopReasonDataAtIndex(0) == current_bp[0] and thread.GetStopReasonDataAtIndex(1) == current_bp[1], "And it is the same breakpoint.") - + self.assertTrue( + current_line == frame.GetLineEntry().GetLine(), + "The line stayed the same after expression.") + self.assertTrue( + current_file == frame.GetLineEntry().GetFileSpec(), + "The file stayed the same after expression.") + self.assertTrue( + thread.GetStopReason() == lldb.eStopReasonBreakpoint, + "We still say we stopped for a breakpoint.") + self.assertTrue(thread.GetStopReasonDataAtIndex(0) == current_bp[ + 0] and thread.GetStopReasonDataAtIndex(1) == current_bp[1], "And it is the same breakpoint.") + # Also make sure running the expression didn't change the public stop id # but did change if we are asking for expression stops as well. stop_id_after_expression = process.GetStopID() stop_id_after_including_expressions = process.GetStopID(True) - self.assertTrue (stop_id_before_expression == stop_id_after_expression, "Expression calling doesn't change stop ID") + self.assertTrue( + stop_id_before_expression == stop_id_after_expression, + "Expression calling doesn't change stop ID") - self.assertTrue (stop_id_after_including_expressions > stop_id_before_including_expressions, "Stop ID including expressions increments over expression call.") + self.assertTrue( + stop_id_after_including_expressions > stop_id_before_including_expressions, + "Stop ID including expressions increments over expression call.") - # Do the same thing with an expression that's going to crash, and make sure we are still unchanged. + # Do the same thing with an expression that's going to crash, and make + # sure we are still unchanged. - frame.EvaluateExpression ("((char *) 0)[0] = 'a'") + frame.EvaluateExpression("((char *) 0)[0] = 'a'") frame = thread.GetFrameAtIndex(0) - self.assertTrue (current_line == frame.GetLineEntry().GetLine(), "The line stayed the same after expression.") - self.assertTrue (current_file == frame.GetLineEntry().GetFileSpec(), "The file stayed the same after expression.") - self.assertTrue (thread.GetStopReason() == lldb.eStopReasonBreakpoint, "We still say we stopped for a breakpoint.") - self.assertTrue (thread.GetStopReasonDataAtIndex(0) == current_bp[0] and thread.GetStopReasonDataAtIndex(1) == current_bp[1], "And it is the same breakpoint.") + self.assertTrue( + current_line == frame.GetLineEntry().GetLine(), + "The line stayed the same after expression.") + self.assertTrue( + current_file == frame.GetLineEntry().GetFileSpec(), + "The file stayed the same after expression.") + self.assertTrue( + thread.GetStopReason() == lldb.eStopReasonBreakpoint, + "We still say we stopped for a breakpoint.") + self.assertTrue(thread.GetStopReasonDataAtIndex(0) == current_bp[ + 0] and thread.GetStopReasonDataAtIndex(1) == current_bp[1], "And it is the same breakpoint.") # Now continue and make sure we just complete the step: # Disable all our breakpoints first - sometimes the compiler puts two line table entries in for the @@ -140,16 +171,17 @@ class TestCStepping(TestBase): process.Continue() - self.assertTrue (thread.GetFrameAtIndex(0).GetFunctionName() == "a") - self.assertTrue (thread.GetStopReason() == lldb.eStopReasonPlanComplete) + self.assertTrue(thread.GetFrameAtIndex(0).GetFunctionName() == "a") + self.assertTrue(thread.GetStopReason() == lldb.eStopReasonPlanComplete) # And one more time should get us back to main: process.Continue() - self.assertTrue (thread.GetFrameAtIndex(0).GetFunctionName() == "main") - self.assertTrue (thread.GetStopReason() == lldb.eStopReasonPlanComplete) + self.assertTrue(thread.GetFrameAtIndex(0).GetFunctionName() == "main") + self.assertTrue(thread.GetStopReason() == lldb.eStopReasonPlanComplete) - # Now make sure we can call a function, break in the called function, then have "continue" get us back out again: + # Now make sure we can call a function, break in the called function, + # then have "continue" get us back out again: frame = thread.GetFrameAtIndex(0) frame = thread.GetFrameAtIndex(0) current_line = frame.GetLineEntry().GetLine() @@ -160,12 +192,13 @@ class TestCStepping(TestBase): options.SetIgnoreBreakpoints(False) options.SetFetchDynamicValue(False) options.SetUnwindOnError(False) - frame.EvaluateExpression ("b (4)", options) + frame.EvaluateExpression("b (4)", options) - threads = lldbutil.get_threads_stopped_at_breakpoint (process, break_in_b) + threads = lldbutil.get_threads_stopped_at_breakpoint( + process, break_in_b) if len(threads) != 1: - self.fail ("Failed to stop at breakpoint in b when calling b.") + self.fail("Failed to stop at breakpoint in b when calling b.") thread = threads[0] # So do a step over here to make sure we can still do that: @@ -174,75 +207,95 @@ class TestCStepping(TestBase): # See that we are still in b: func_name = thread.GetFrameAtIndex(0).GetFunctionName() - self.assertTrue (func_name == "b", "Should be in 'b', were in %s"%(func_name)) + self.assertTrue( + func_name == "b", + "Should be in 'b', were in %s" % + (func_name)) - # Okay, now if we continue, we will finish off our function call and we should end up back in "a" as if nothing had happened: - process.Continue () + # Okay, now if we continue, we will finish off our function call and we + # should end up back in "a" as if nothing had happened: + process.Continue() - self.assertTrue (thread.GetFrameAtIndex(0).GetLineEntry().GetLine() == current_line) - self.assertTrue (thread.GetFrameAtIndex(0).GetLineEntry().GetFileSpec() == current_file) + self.assertTrue(thread.GetFrameAtIndex( + 0).GetLineEntry().GetLine() == current_line) + self.assertTrue(thread.GetFrameAtIndex( + 0).GetLineEntry().GetFileSpec() == current_file) # Now we are going to test step in targeting a function: - break_in_b.SetEnabled (False) + break_in_b.SetEnabled(False) - break_before_complex_1 = target.BreakpointCreateBySourceRegex ('// Stop here to try step in targeting b.', self.main_source_spec) + break_before_complex_1 = target.BreakpointCreateBySourceRegex( + '// Stop here to try step in targeting b.', self.main_source_spec) self.assertTrue(break_before_complex_1, VALID_BREAKPOINT) - break_before_complex_2 = target.BreakpointCreateBySourceRegex ('// Stop here to try step in targeting complex.', self.main_source_spec) + break_before_complex_2 = target.BreakpointCreateBySourceRegex( + '// Stop here to try step in targeting complex.', self.main_source_spec) self.assertTrue(break_before_complex_2, VALID_BREAKPOINT) - break_before_complex_3 = target.BreakpointCreateBySourceRegex ('// Stop here to step targeting b and hitting breakpoint.', self.main_source_spec) + break_before_complex_3 = target.BreakpointCreateBySourceRegex( + '// Stop here to step targeting b and hitting breakpoint.', self.main_source_spec) self.assertTrue(break_before_complex_3, VALID_BREAKPOINT) - break_before_complex_4 = target.BreakpointCreateBySourceRegex ('// Stop here to make sure bogus target steps over.', self.main_source_spec) + break_before_complex_4 = target.BreakpointCreateBySourceRegex( + '// Stop here to make sure bogus target steps over.', self.main_source_spec) self.assertTrue(break_before_complex_4, VALID_BREAKPOINT) - threads = lldbutil.continue_to_breakpoint(process, break_before_complex_1) - self.assertTrue (len(threads) == 1) + threads = lldbutil.continue_to_breakpoint( + process, break_before_complex_1) + self.assertTrue(len(threads) == 1) thread = threads[0] break_before_complex_1.SetEnabled(False) - thread.StepInto ("b") - self.assertTrue (thread.GetFrameAtIndex(0).GetFunctionName() == "b") + thread.StepInto("b") + self.assertTrue(thread.GetFrameAtIndex(0).GetFunctionName() == "b") - # Now continue out and stop at the next call to complex. This time step all the way into complex: - threads = lldbutil.continue_to_breakpoint (process, break_before_complex_2) - self.assertTrue (len(threads) == 1) + # Now continue out and stop at the next call to complex. This time + # step all the way into complex: + threads = lldbutil.continue_to_breakpoint( + process, break_before_complex_2) + self.assertTrue(len(threads) == 1) thread = threads[0] break_before_complex_2.SetEnabled(False) - thread.StepInto ("complex") - self.assertTrue (thread.GetFrameAtIndex(0).GetFunctionName() == "complex") - - # Now continue out and stop at the next call to complex. This time enable breakpoints in a and c and then step targeting b: - threads = lldbutil.continue_to_breakpoint (process, break_before_complex_3) - self.assertTrue (len(threads) == 1) + thread.StepInto("complex") + self.assertTrue(thread.GetFrameAtIndex( + 0).GetFunctionName() == "complex") + + # Now continue out and stop at the next call to complex. This time + # enable breakpoints in a and c and then step targeting b: + threads = lldbutil.continue_to_breakpoint( + process, break_before_complex_3) + self.assertTrue(len(threads) == 1) thread = threads[0] break_before_complex_3.SetEnabled(False) - break_at_start_of_a = target.BreakpointCreateByName ('a') - break_at_start_of_c = target.BreakpointCreateByName ('c') + break_at_start_of_a = target.BreakpointCreateByName('a') + break_at_start_of_c = target.BreakpointCreateByName('c') - thread.StepInto ("b") - threads = lldbutil.get_stopped_threads(process, lldb.eStopReasonBreakpoint); + thread.StepInto("b") + threads = lldbutil.get_stopped_threads( + process, lldb.eStopReasonBreakpoint) - self.assertTrue (len(threads) == 1) + self.assertTrue(len(threads) == 1) thread = threads[0] stop_break_id = thread.GetStopReasonDataAtIndex(0) - self.assertTrue(stop_break_id == break_at_start_of_a.GetID() or stop_break_id == break_at_start_of_c.GetID()) + self.assertTrue(stop_break_id == break_at_start_of_a.GetID() + or stop_break_id == break_at_start_of_c.GetID()) break_at_start_of_a.SetEnabled(False) break_at_start_of_c.SetEnabled(False) process.Continue() - self.assertTrue (thread.GetFrameAtIndex(0).GetFunctionName() == "b") - - # Now continue out and stop at the next call to complex. This time enable breakpoints in a and c and then step targeting b: - threads = lldbutil.continue_to_breakpoint (process, break_before_complex_4) - self.assertTrue (len(threads) == 1) + self.assertTrue(thread.GetFrameAtIndex(0).GetFunctionName() == "b") + + # Now continue out and stop at the next call to complex. This time + # enable breakpoints in a and c and then step targeting b: + threads = lldbutil.continue_to_breakpoint( + process, break_before_complex_4) + self.assertTrue(len(threads) == 1) thread = threads[0] break_before_complex_4.SetEnabled(False) thread.StepInto("NoSuchFunction") - self.assertTrue (thread.GetFrameAtIndex(0).GetFunctionName() == "main") + self.assertTrue(thread.GetFrameAtIndex(0).GetFunctionName() == "main") diff --git a/packages/Python/lldbsuite/test/lang/c/stepping/TestThreadStepping.py b/packages/Python/lldbsuite/test/lang/c/stepping/TestThreadStepping.py index c3ed3f933ab03..c436000d882fb 100644 --- a/packages/Python/lldbsuite/test/lang/c/stepping/TestThreadStepping.py +++ b/packages/Python/lldbsuite/test/lang/c/stepping/TestThreadStepping.py @@ -5,14 +5,15 @@ Test thread stepping features in combination with frame select. from __future__ import print_function - -import os, time +import os +import time import re import lldb import lldbsuite.test.lldbutil as lldbutil from lldbsuite.test.lldbtest import * import lldbsuite.test.lldbutil as lldbutil + class ThreadSteppingTestCase(TestBase): mydir = TestBase.compute_mydir(__file__) @@ -21,10 +22,14 @@ class ThreadSteppingTestCase(TestBase): # Call super's setUp(). TestBase.setUp(self) # Find the line number to of function 'c'. - self.line1 = line_number('main.c', '// Find the line number of function "c" here.') - self.line2 = line_number('main.c', '// frame select 2, thread step-out while stopped at "c(1)"') - self.line3 = line_number('main.c', '// thread step-out while stopped at "c(2)"') - self.line4 = line_number('main.c', '// frame select 1, thread step-out while stopped at "c(3)"') + self.line1 = line_number( + 'main.c', '// Find the line number of function "c" here.') + self.line2 = line_number( + 'main.c', '// frame select 2, thread step-out while stopped at "c(1)"') + self.line3 = line_number( + 'main.c', '// thread step-out while stopped at "c(2)"') + self.line4 = line_number( + 'main.c', '// frame select 1, thread step-out while stopped at "c(3)"') def test_step_out_with_run_command(self): """Exercise thread step-out and frame select followed by thread step-out.""" @@ -33,49 +38,50 @@ class ThreadSteppingTestCase(TestBase): self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) # Create a breakpoint inside function 'c'. - lldbutil.run_break_set_by_file_and_line (self, "main.c", self.line1, num_expected_locations=1, loc_exact=True) + lldbutil.run_break_set_by_file_and_line( + self, "main.c", self.line1, num_expected_locations=1, loc_exact=True) # Now run the program. self.runCmd("run", RUN_SUCCEEDED) # The process should be stopped at this point. self.expect("process status", PROCESS_STOPPED, - patterns = ['Process .* stopped']) + patterns=['Process .* stopped']) # The frame #0 should correspond to main.c:32, the executable statement # in function name 'c'. And frame #3 should point to main.c:37. self.expect("thread backtrace", STOPPED_DUE_TO_BREAKPOINT, - substrs = ["stop reason = breakpoint"], - patterns = ["frame #0.*main.c:%d" % self.line1, - "frame #3.*main.c:%d" % self.line2]) + substrs=["stop reason = breakpoint"], + patterns=["frame #0.*main.c:%d" % self.line1, + "frame #3.*main.c:%d" % self.line2]) # We want to move the pc to frame #3. This can be accomplished by # 'frame select 2', followed by 'thread step-out'. self.runCmd("frame select 2") self.runCmd("thread step-out") self.expect("thread backtrace", STEP_OUT_SUCCEEDED, - substrs = ["stop reason = step out"], - patterns = ["frame #0.*main.c:%d" % self.line2]) + substrs=["stop reason = step out"], + patterns=["frame #0.*main.c:%d" % self.line2]) # Let's move on to a single step-out case. self.runCmd("process continue") # The process should be stopped at this point. self.expect("process status", PROCESS_STOPPED, - patterns = ['Process .* stopped']) + patterns=['Process .* stopped']) self.runCmd("thread step-out") self.expect("thread backtrace", STEP_OUT_SUCCEEDED, - substrs = ["stop reason = step out"], - patterns = ["frame #0.*main.c:%d" % self.line3]) + substrs=["stop reason = step out"], + patterns=["frame #0.*main.c:%d" % self.line3]) # Do another frame selct, followed by thread step-out. self.runCmd("process continue") # The process should be stopped at this point. self.expect("process status", PROCESS_STOPPED, - patterns = ['Process .* stopped']) + patterns=['Process .* stopped']) self.runCmd("frame select 1") self.runCmd("thread step-out") self.expect("thread backtrace", STEP_OUT_SUCCEEDED, - substrs = ["stop reason = step out"], - patterns = ["frame #0.*main.c:%d" % self.line4]) + substrs=["stop reason = step out"], + patterns=["frame #0.*main.c:%d" % self.line4]) |