AR# 22602


11.1 EDK - How to debug successfully using GDB


Keywords: gnu, debugger, optimization, -g, -O0

I am experiencing instability with GDB while attempting to debug my program. The debugger appears to hang intermittently. When I stop the debugger, a sigtrap error is issued and I must restart the debugger. Is there anything I can do to improve my GDB debugging experience?


First, make sure you include the -g symbols for debugging for both the user application and the EDK libraries. In the Compiler Options, under the Debug and Optimization tab, select Create Symbols for Debugging (-g option). Ensure that the -g flag is also included in the Software Platform Settings dialog under extra_compiler_flags.

Second, Xilinx strongly suggests that you debug your program with no optimization. Although debugging with optimization should technically work in GDB, debugging compiler-optimized code is difficult to follow and is not very intuitive. As the compiler optimizes your code, the flow of the code is often reordered, resulting in jumps back and forth that can be very difficult to follow as you step through this code. Debugging compiler-optimized code should be necessary only when investigating a potential compiler optimization problem. Debugging your program with no optimization provides a much more intuitive flow as you step through the program. Also, debugging nonoptimized code has been observed to be more stable with respect to GDB.

Both the user application and all EDK libraries should be compiled with no optimization. Please note that turning off optimization in the Compiler Settings dialog affects only the user application. To turn off optimization for the EDK libraries, you must manually add a switch to the Software Platform Settings. To do this, follow these steps:

1. Open the Software Platform Settings.
2. In the Software Platform tab, in the extra_compiler_flags box, add the -O0 switch.
3. To compile the user application with no optimization, in the Compiler Settings dialog go to the Debug and Optimization tab and select No Optimization.

Third, it is important to understand all of the debugging symbols (buttons) in GDB and to use them correctly.

The "step" button, also known as "step into" button, simply steps to the next instruction. If the instruction is a function call, pressing the "step" button allows you to step into the function.

The "next" button, also known as "step over" button, allows you to step over the current line of code. If this happens to be a function call, the "next" button allows you to step over the function call as opposed to stepping into it with the "step" button.

The "finish" button, also known as "step return" button, allows you to return from a function you have stepped into. The "step" button allows you to step into a function, and the "finish" button allows you to step out of the function.

The "continue" button, also known as "resume" button, allows you to continue executing your program until the next breakpoint is hit.

AR# 22602
Date 04/25/2009
Status Active
Type General Article
People Also Viewed