| |||
| Home > Controlling execution > Setting a conditional breakpoint | |||
Conditional breakpoints have properties assigned to test for conditions that must be satisfied to trigger the breakpoint. For example, you can:
test a variable for a given value
execute a function a set number of times
trigger a breakpoint only on a specific thread.
Conditional breakpoints can be very intrusive and lower the performance if they are hit frequently. This is because the debugger stops the target every time the breakpoint is hit. The specified condition is checked and if it evaluates to true (non-zero) then the target remains in the stopped state, otherwise execution resumes.
You must not assign a script to a breakpoint that has sub-breakpoints. If you do, the debugger attempts to execute the script for each sub-breakpoint. If this happens, an error message is displayed.
In Eclipse, you can assign conditions to an existing breakpoint in the Breakpoint Properties dialog box:
In the Breakpoints view, right-click on the breakpoint that you want modify to display the context menu.
Select Breakpoint Properties... to display the Breakpoint Properties dialog box.
If you want to set a conditional expression for
a specific breakpoint then enter a C-style expression in the Stop
Condition field. For example, if your program has a
variable x, then you can specify:
x == 10
If you want the debugger to delay hitting the breakpoint until a specific number of passes has occurred, then enter the number of passes in the Ignore Count field. For example, if you have a loop that performs 100 iterations, and you want a breakpoint in that loop to be hit after 50 passes, then enter 50.
If you want to run a script when the selected breakpoint is triggered then specify the script file in the On break, run script field:
enter the location and file name in the field provided
click on File System... to locate the file in an external directory from the workspace
click on Workspace... to locate the file in a project directory or sub-directory within the workspace.
Take care with the commands you use in a script that is attached to a breakpoint. For example, if you use the quit command in a script, the debugger disconnects from the target when the breakpoint is hit.
If you want to enable the debugger to automatically continue running the application on completion of all the breakpoint actions then select the Continue Execution checkbox.
Enabling this has the same effect as if the breakpoint has an On break, run script that ends with a continue command.
If you want to set a breakpoint in one or more threads for a multi-threaded application:
Select Break on Selected Threads to enable the thread list.
Select the checkbox for each thread that you want to assign the breakpoint to.
Click OK to save the changes.
Breakpoints that are set on a single line of source code with
multiple statements are assigned sub-numbers to a parent breakpoint
number, for example n.n.
You can enable, disable, and view the properties of each sub-breakpoint
in the same way as a single statement breakpoint.
Be aware of the following when setting multiple conditions on a breakpoint:
If you set a Stop
Condition and an Ignore Count, then the Ignore Count is not decremented
until the Stop Condition is met. For example, you might have a breakpoint
in a loop that is controlled by the variable c and
has 10 iterations .If you set the Stop Condition c==5 and
the Ignore Count to 3, then the breakpoint might
never get hit if the loop is reached fewer times than the ignore
count value.
If you choose to break on selected threads, then the Stop Condition and Ignore Count are checked only for the selected threads.