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.

Figure 2. Breakpoint dialog

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.

Adding or Setting Breakpoints

The Breakpoint editing window can be opened by choosing View->Breakpoints or Debug->Breakpoints->Breakpoints …. Click on Add. A dialog will appear.

Figure 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 highlighting the function name in the editor and choosing the menu item Debug->Breakpoints->Set Breakpoint (or by clicking on the Toggle breakpoint at cursor button on the Debug Toolbar).

Editing Breakpoints

Open the Breakpoint editing window by choosing the menu item View->Breakpoints or Debug->Breakpoints->Breakpoints …. Select the breakpoint to edit and click on Edit. A dialog will appear.

Figure 4. Breakpoint edit dialog

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

Deleting Breakpoints

Open the Breakpoint editing window by choosing the menu item View->Breakpoints or Debug->Breakpoints->Breakpoints …. Select the breakpoint to delete and click on Delete. The breakpoint will be deleted.

To delete all breakpoints, click on Delete All.

Enabling or Disabling Breakpoints

Open the Breakpoint editing window by choosing the menu item View->Breakpoints or Debug->Breakpoints->Breakpoints …. Select the breakpoint to enable or disable and click on Toggle Enable. The breakpoint will be enabled or disabled, depending on the current state.

To enable all or disable all breakpoints, click on Enable All or Disable All.

NoteNote
 

When the debugger is started, all breakpoints will be set. Any old breakpoints (where the source file is more recent than the breakpoint) will be disabled.