CodeBlocks Debugger Functions

This section describes the debugging tasks that are integrated with the CodeBlocks IDE.


Breakpoints are set in the normal editor window by clicking on the “gutter” on the left hand side of the source file:




The red circle indicates that a breakpoint has been set at that source line. You can set breakpoints in C source files at function names and at any source lines with C executable statements.


The yellow triangle indicates the location of the currently paused program counter.


The following breakpoint commands are available under the Debug menu:


·         Debug->Toggle Breakpoint: set or clear a breakpoint at the cursor

·         Debug->Remove all breakpoints: remove all breakpoints from the project

·         Debug->Debugging windows->breakpoints: shows the breakpoint window. The breakpoint window contains all the breakpoints in the project and shows whether they are currently enabled or disabled.


Disabling a breakpoint is useful to temporarily ignore a breakpoint during a debug session without removing it.


Right-clicking at an entry in the breakpoint window brings up a context menu with further operations you can perform on the breakpoints, including disabling and enabling them:



Source Line Stepping

Once paused, you can continue execution:


·         Debug->Start/Continue runs the program until the next breakpoint.

·         Debug->next line runs the program until the next source line. If the current source line contains a function call, it will “step over” the function call.

·         Debug->Step into will “step into” a function call, and pause at the next source line.

·         Debug->Step out will continue program execution until the function call returns to its caller.

·         Debug->Next instruction and Debug->Step into instruction are assembly debugging commands, and should not be used within the CodeBlocks IDE. Instead, the corresponding commands in the ADT should be used. See Advanced Debug Toolbar (ADT) Functions.

Call Stack

Debug->Debugging windows->Call stack displays the call stack, which is the trace of the function calls that leads to the current breakpoint locations. Usually the top of the call chain is the main function, unless the program is paused at an interrupt handler or unknown PC location with no source line information.

Variable Watching

The watch window displays the content of the variables you “add” to the watch window. To show or hide the watch window, use Debug->Debugging windows->Watch. The values of the variables are updated automatically whenever the program is paused. To add a variable to the watch window, right-click on the variable name, then select Watch ‘<variable name>’ in the popup menu. You can remove a variable from the watch window by right-clicking on the entry in the watch window and selecting the action from the popup menu.


Note that values for variables that are not in-scope (e.g. a static variable defined in another file or another function, or a local variable that is not used at that program location) cannot be displayed correctly. This can be particularly jarring regarding local variables: due to compiler optimizations, the value of a local variable is only valid between its first use and last use. So, if the program is paused at a C line that is after the last use of that variable, the value may not be displayed correctly. Another "gotcha!" Is that if you assign a value to a variable but never use that variable with that assigned value, then the compiler may never assign the value to the variable at all, and thus you would not see it in the debugger either.

“Quick Watching” A Variable

When you hover the mouse over a variable, the debugger briefly shows the data type of the variable and then its content.