After you build your application, choose
C/C++ Local Application
label in the Configurations pane. Then,
click the New icon
positioned towards the upper left of the window.
Figure 5.5. Creating a Launch Configuration
![]() |
When you create the launch configuration, a new window appears. On the Main tab, use the button to select your project, if it is not already selected. Then, use the button to select your application.
Before you can use the Sourcery G++ IDE to debug your application, you must decide which debugging mode to use. Sourcery G++ supports several debugging modes, as described below.
Once you have decided which debugger to use, switch to the Debugger tab and select the appropriate Sourcery G++ option.
Once you have made any necessary adjustments, click the
button to start the debugger.You do not need to repeat the debugger selection process the next time you launch the debugger. Instead, you can select
→ to start the debugger using the settings you have selected.When you start the debugger, the IDE switches from the C/C++ perspective to the debug perspective. Instead of showing panes that help you to develop your application, the IDE now shows panes that help you to debug your application.
Figure 5.8. Debug Perspective
![]() |
The debugger automatically stops on the first line of
main
. The currently active source line is
highlighted. The pane at the upper left shows the application
threads and the stack associated with each thread. The pane at
the upper right shows the values of local variables. (At this
point, i
and n
have not yet
been initialized, so their values are indeterminate.)
Use
F6)
to advance by a single line. Because the program has
changed the value of i
, the IDE highlights
the value in the variable pane.
By looking at the code, you can see that the program calls
factorial
and then calls
printf
to print out the resulting value.
You can set a breakpoint right before the call to
printf
by clicking anywhere on that line, and
then using
(Ctrl-Shift-B).
Figure 5.9. Setting a Breakpoint
![]() |
After setting the breakpoint, use
F5)
to step into the body of factorial
.
The IDE no longer displays the value of i
because there is no local variable i
within
factorial
. If you wish to see the value of
i
(from main
), select the
stack frame for main
in the pane at the upper
left. The IDE displays the variables for whichever frame is
presently selected.
Now, proceed to the breakpoint by using
F8). The variable n
now has the
value 1
because the factorial of zero is one.
Step over the call to printf
to print the
value in the console.
You may sometimes need to debug at the machine level, rather than at the source code level. For example, if you are working with an assembly code device driver, you may wish to see the values stored in machine registers and step through the code instruction by instruction.
To view machine registers, click on the Registers tab, and expand the Main register group. To see the instructions being executed, use → → .
Figure 5.10. Low-Level Debugging
![]() |
When the disassembly window is active, the
and commands operate at the assembly level, rather than at the source code level. So, a command advances by a single machine instruction. When the values of registers change, the registers are highlighted in the IDE. You can set breakpoints on particular machine instructions in the same way that you can set breakpoints on source code.When your application is large, or the debugging device is relatively slow, you may encounter timeout errors when starting debugging. In that case, you should increase the timeout settings. Select the Preferences item in the Window menu, and in the dialog that appears select C/C++, Debug, GDB MI. Increase the values in the Debugger Timeout and the Launch Timeout fields until your application starts without errors.