Breakpoints

When debugging a program, it is useful to be able to stop the execution of the program at a particular point, so that the state of the program can be examined at that location. Breakpoints enable this to happen. Breakpoints can be set at different locations in a source file and then the program is allowed to run. When a breakpoint is encountered, the execution of the program is suspended, enabling expressions to be evaluated, variables to be inspected, the stack trace to be studied, and so on.

6.3.1. Listing Breakpoints

The Breakpoint list window can be opened by choosing View ▸ Breakpoints

Figure 6-2Breakpoint view

The view has the following columns:

Location

This is the position of the breakpoint in the source file. When the breakpoint is set by the debugger, you can get additional information such as the function containing the breakpoint.

Address

This field is filled with the address of the breakpoint when it is set by the debugger.

Type

This always displays "breakpoint". It will be used in a future release supporting different kinds of breakpoints.

Condition

This is the breakpoint condition. It is empty if no condition is defined.

Pass count

When the debugger is not running, this column displays the pass count of the breakpoint, or zero if it is not defined.

When the debugger is running, if the pass count is zero, this column displays the number of times this breakpoint has been triggered. If the pass count is not zero, both numbers are displayed. The pass count is the second number.

State

This is the state of the breakpoint. It may be

  • Pending: the breakpoint is not set in your program.
  • Permanent: the breakpoint is set (its id number in given inside parentheses).
  • Temporary: the breakpoint is set but will be deleted if reached.

All breakpoints are kept across Anjuta sessions even if they correspond to a non-existing location. In this case their states are set as pending. The interface tries to set them each time the program is started or a new dynamic library is loaded.

6.3.2. Adding or Setting Breakpoints

Choose the menu item Debug ▸ Add Breakpoint… or Add Breakpoint… in the breakpoint list popup menu to open the add breakpoint dialog.

Figure 6-3Breakpoint add dialog

Enter the location and, optionally, the break condition and the pass count; then click OK to set the breakpoint.

Location

Enter the location at which to set the breakpoint. It can be specified in any of the following formats:

  1. File_name:Line_number
  2. Function_name
  3. File:Function_name

The first format is obvious — the location refers to the line number Line_number in the source file File. The second format refers to the first line of the function Function_name. The third is similar to the second, except that this notation is used where there is more than one function with the name Function_name in the program. It is possible to differentiate between them by providing the File, so the notation refers to the function Function_name in the file File.

Condition

The Condition parameter displays a associated expression which should evaluate to a Boolean value — that is, the evaluation of the expression should result in either TRUE(1) or FALSE(0). If the final evaluation value is not a Boolean value, then it will be appropriately type cast to a Boolean.

Every time the breakpoint is encountered during your program's execution, the break condition will be evaluated. The debugger will break the execution only if the evaluation results in a TRUE value, otherwise it will continue the execution as though there had been no breakpoint.

The default value, if you leave this field blank, of Condition is TRUE. The debugger will always break the execution at the breakpoint location.

Pass Count

The Pass count is an integer (unsigned) value which tells the debugger to skip the breakpoint that number of times before it is considered. Pass count has a higher priority than the Break condition. Only when the Pass count reaches zero will the debugger evaluate the Break condition (if any condition is present). If there is no condition, the debugger will break the execution once the Pass count counts down to zero.

The default value, if you leave this field blank, of the Pass count is zero. The breakpoint will be considered when it is first encountered.

A breakpoint may also be set by selecting a line in the editor and choosing the menu item Debug ▸ Toggle Breakpoint in the editor context menu or the Toggle Breakpoint icon in the Debug toolbar.

Breakpoints can be added even if the debugger is not started, or in a dynamic library which is not loaded yet. But they cannot be added while a program is running under control of the debugger.

6.3.3. Editing Breakpoints

You can change the condition and the pass count by selecting the breakpoint in the breakpoint list and clicking Edit Breakpoint in the popup menu.

Edit the entries as required and click on OK to commit the changes.

6.3.4. Deleting Breakpoints

Select the breakpoint in the breakpoint list view and click on Remove Breakpoint to delete it.

A existing breakpoint may also be deleted by selecting its line in the editor and choosing the menu item Debug ▸ Toggle Breakpoint, the editor context menu item Toggle Breakpoint or the Toggle Breakpoint icon in the Debug toolbar.

You can remove all breakpoints by clicking on Debug ▸ Remove All Breakpoints or on Remove All Breakpoints in the breakpoint list context menu.

6.3.5. Enabling or Disabling Breakpoints

Click on the Enable column of the Breakpoint list window or in the context menu item Enable Breakpoint to enable or disable the selected breakpoint. The breakpoint will be enabled or disabled, depending on its current state.

To disable all breakpoints, click on Debug ▸ Disable All Breakpoints or on Disable All Breakpoints in the breakpoint list context menu.