|
| 1 | +""" |
| 2 | +Test that breakpoints (reason = breakpoint) have more priority than |
| 3 | +plan completion (reason = step in/out/over) when reporting stop reason after step, |
| 4 | +in particular 'step out' and 'step over', and in addition 'step in'. |
| 5 | +Check for correct StopReason when stepping to the line with breakpoint, |
| 6 | +which should be eStopReasonBreakpoint in general, |
| 7 | +and eStopReasonPlanComplete when breakpoint's condition fails or it is disabled. |
| 8 | +""" |
| 9 | + |
| 10 | + |
| 11 | +import unittest2 |
| 12 | +import lldb |
| 13 | +from lldbsuite.test.decorators import * |
| 14 | +from lldbsuite.test.lldbtest import * |
| 15 | +from lldbsuite.test import lldbutil |
| 16 | + |
| 17 | +class ThreadPlanUserBreakpointsTestCase(TestBase): |
| 18 | + |
| 19 | + def setUp(self): |
| 20 | + TestBase.setUp(self) |
| 21 | + |
| 22 | + # Build and run to starting breakpoint |
| 23 | + self.build() |
| 24 | + src = lldb.SBFileSpec('main.cpp') |
| 25 | + (self.target, self.process, self.thread, _) = \ |
| 26 | + lldbutil.run_to_source_breakpoint(self, '// Start from here', src) |
| 27 | + |
| 28 | + # Setup two more breakpoints |
| 29 | + self.breakpoints = [self.target.BreakpointCreateBySourceRegex('breakpoint_%i' % i, src) |
| 30 | + for i in range(2)] |
| 31 | + self.assertTrue( |
| 32 | + all(bp and bp.GetNumLocations() == 1 for bp in self.breakpoints), |
| 33 | + VALID_BREAKPOINT) |
| 34 | + |
| 35 | + def check_correct_stop_reason(self, breakpoint_idx, condition): |
| 36 | + self.assertState(self.process.GetState(), lldb.eStateStopped) |
| 37 | + if condition: |
| 38 | + # All breakpoints active, stop reason is breakpoint |
| 39 | + thread1 = lldbutil.get_one_thread_stopped_at_breakpoint(self.process, self.breakpoints[breakpoint_idx]) |
| 40 | + self.assertEquals(self.thread, thread1, "Didn't stop at breakpoint %i." % breakpoint_idx) |
| 41 | + else: |
| 42 | + # Breakpoints are inactive, stop reason is plan complete |
| 43 | + self.assertEquals(self.thread.GetStopReason(), lldb.eStopReasonPlanComplete, |
| 44 | + 'Expected stop reason to be step into/over/out for inactive breakpoint %i line.' % breakpoint_idx) |
| 45 | + |
| 46 | + def change_breakpoints(self, action): |
| 47 | + for bp in self.breakpoints: |
| 48 | + action(bp) |
| 49 | + |
| 50 | + def check_thread_plan_user_breakpoint(self, condition, set_up_breakpoint_func): |
| 51 | + # Make breakpoints active/inactive in different ways |
| 52 | + self.change_breakpoints(lambda bp: set_up_breakpoint_func(condition, bp)) |
| 53 | + |
| 54 | + self.thread.StepInto() |
| 55 | + # We should be stopped at the breakpoint_0 line with the correct stop reason |
| 56 | + self.check_correct_stop_reason(0, condition) |
| 57 | + |
| 58 | + # This step-over creates a step-out from `func_1` plan |
| 59 | + self.thread.StepOver() |
| 60 | + # We should be stopped at the breakpoint_1 line with the correct stop reason |
| 61 | + self.check_correct_stop_reason(1, condition) |
| 62 | + |
| 63 | + # Check explicit step-out |
| 64 | + # Make sure we install the breakpoint at the right address: |
| 65 | + # step-out might stop on different lines, if the compiler |
| 66 | + # did or did not emit more instructions after the return |
| 67 | + return_addr = self.thread.GetFrameAtIndex(1).GetPC() |
| 68 | + step_out_breakpoint = self.target.BreakpointCreateByAddress(return_addr) |
| 69 | + self.assertTrue(step_out_breakpoint, VALID_BREAKPOINT) |
| 70 | + set_up_breakpoint_func(condition, step_out_breakpoint) |
| 71 | + self.breakpoints.append(step_out_breakpoint) |
| 72 | + self.thread.StepOut() |
| 73 | + # We should be stopped somewhere in the main frame with the correct stop reason |
| 74 | + self.check_correct_stop_reason(2, condition) |
| 75 | + |
| 76 | + # Run the process until termination |
| 77 | + self.process.Continue() |
| 78 | + self.assertState(self.process.GetState(), lldb.eStateExited) |
| 79 | + |
| 80 | + def set_up_breakpoints_condition(self, condition, bp): |
| 81 | + # Set breakpoint condition to true/false |
| 82 | + conditionStr = 'true' if condition else 'false' |
| 83 | + bp.SetCondition(conditionStr) |
| 84 | + |
| 85 | + def set_up_breakpoints_enable(self, condition, bp): |
| 86 | + # Enable/disable breakpoint |
| 87 | + bp.SetEnabled(condition) |
| 88 | + |
| 89 | + def set_up_breakpoints_callback(self, condition, bp): |
| 90 | + # Set breakpoint callback to return True/False |
| 91 | + bp.SetScriptCallbackBody('return %s' % condition) |
| 92 | + |
| 93 | + def test_thread_plan_user_breakpoint_conditional_active(self): |
| 94 | + # Test with breakpoints having true condition |
| 95 | + self.check_thread_plan_user_breakpoint(condition=True, |
| 96 | + set_up_breakpoint_func=self.set_up_breakpoints_condition) |
| 97 | + |
| 98 | + def test_thread_plan_user_breakpoint_conditional_inactive(self): |
| 99 | + # Test with breakpoints having false condition |
| 100 | + self.check_thread_plan_user_breakpoint(condition=False, |
| 101 | + set_up_breakpoint_func=self.set_up_breakpoints_condition) |
| 102 | + |
| 103 | + def test_thread_plan_user_breakpoint_unconditional_active(self): |
| 104 | + # Test with breakpoints enabled unconditionally |
| 105 | + self.check_thread_plan_user_breakpoint(condition=True, |
| 106 | + set_up_breakpoint_func=self.set_up_breakpoints_enable) |
| 107 | + |
| 108 | + def test_thread_plan_user_breakpoint_unconditional_inactive(self): |
| 109 | + # Test with breakpoints disabled unconditionally |
| 110 | + self.check_thread_plan_user_breakpoint(condition=False, |
| 111 | + set_up_breakpoint_func=self.set_up_breakpoints_enable) |
| 112 | + |
| 113 | + def test_thread_plan_user_breakpoint_callback_active(self): |
| 114 | + # Test with breakpoints with callback that returns 'True' |
| 115 | + self.check_thread_plan_user_breakpoint(condition=True, |
| 116 | + set_up_breakpoint_func=self.set_up_breakpoints_callback) |
| 117 | + |
| 118 | + def test_thread_plan_user_breakpoint_callback_inactive(self): |
| 119 | + # Test with breakpoints with callback that returns 'False' |
| 120 | + self.check_thread_plan_user_breakpoint(condition=False, |
| 121 | + set_up_breakpoint_func=self.set_up_breakpoints_callback) |
0 commit comments