4.10 Setting Breakpoints

When debugging, it can be useful to suspend execution at a specific location in code so that variable values can be examined. To do this, use breakpoints.

For more information on breakpoints, see also NetBeans Help:

Debugging C/C++ Projects Tutorial>Creating Breakpoints

Set Breakpoint

If your code is running, end execution by clicking the Finish Debugger Session icon

.

In the Projects window, under Source Files, double click on the file main.c to open it in an Editor window. Set a breakpoint on the line in the figure by clicking in the left margin of the line.

For the device used in this tutorial, there is only one hardware breakpoint but software breakpoints are available. A notebox will pop up asking about your choice of breakpoint type. Since stepping through code in the next section requires another breakpoint, click Yes to use software breakpoints.

For more on breakpoint type selection, see 5.17.1 Choose Hardware or Software Breakpoints.

Figure 4-11. Breakpoint Set in Code

Halt at Breakpoint

Click the Debug Project icon

to execute the program in debug mode. As the program contains a loop waiting for a button press, you will need to press and release the button on the evaluation board once to enter the loop and halt at the breakpoint (see figure below). Hover over the variable in the figure to see its current value.

Figure 4-12. Program Execution Halted at Breakpoint