5.3. 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.

5.3.1. Listing Breakpoints

The Breakpoint list window can be opened by choosing View->Breakpoints

Figure 5-2. Breakpoint view

Location, refers to the location of the code in the source file. Location can be specified in any of the following formats:

  1. File_name:Line_number

  2. Function_name

  3. File:Function_name

The first one is obvious — The location refers to the line number Line_number in the source file File. The second 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.

Two parameters can be associated with each breakpoint:

  1. Break condition

  2. Pass count

The Break condition is a valid C 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 casted to a Boolean.

Every time the breakpoint is encountered during the 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 of Break condition is always TRUE. The debugger will break the execution at the breakpoint location.

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 of the Pass count is zero. The breakpoint will be considered when it is first encountered.

Note

All breakpoints are kept across anjuta session even if they correspond to a non existing place. The interface try to set them each time the program is started or a new dynamic library is loaded.

5.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 5-3. Breakpoint add dialog

Enter the location at which to set the breakpoint. Optionally, enter the Break condition and the Pass count in the appropriate entry boxes. Click OK to set the breakpoint.

A breakpoint may also be by selecting a line in the editor and choosing the menu item Debug->Toggle Breakpoint, the editor popup menu item Toggle Breakpoint or the Toggle Breakpoint icon in the Debug toolbar.

Tip

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

5.3.3. Editing Breakpoints

It is possible to change the condition of a breakpoint of the pass count by selecting the breakpoint to edit in the breakpoint list and click in the popup menu item Edit Breakpoint.

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

5.3.4. Deleting Breakpoints

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

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

5.3.5. Enabling or Disabling Breakpoints

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

To disable all breakpoints, click on Debug->Disable All Breakpoints or on Disable All Breakpoints in the breakpoint list popup menu.