Building to aid debugging
During application development, you must debug the image that you build. The Arm® Compiler tools have various features that provide good debug view and enable source-level debugging, such as setting breakpoints in C and C++ code. There are also some features you must avoid when building an image for debugging.
Available command-line options
To build an image for debugging, you must compile with the
option. This option allows you to specify the DWARF format to use. The
-g option is a synonym for
-gdwarf-4. You can specify DWARF 2 or DWARF 3 if necessary, for
When linking, there are several armlink options available to help improve the debug view:
--debug. This option is the default.
--no_removeto retain all input sections in the final image even if they are unused.
--bestdebug. When different input objects are compiled with different optimization levels, this option enables linking for the best debug illusion.
Effect of optimizations on the debug view
To build an application that gives the best debug view, it is better to use
options that give the fewest optimizations. Arm recommends using optimization level
-O1 for debugging. This option gives good code
density with a satisfactory debug view.
Higher optimization levels perform progressively more optimizations with correspondingly poorer debug views.
The compiler attempts to automatically inline functions at optimization levels
If you must use these optimization levels, disable the automatic inlining with the
-fno-inline-functions. The linker inlining is disabled by default.
Support for debugging overlaid programs
The linker provides various options to support overlay-aware debuggers:
These options permit an overlay-aware debugger to track which overlay is active.
Features to avoid when building an image for debugging
Avoid using the following in your source code:
__attribute__((always_inline))function attribute. Qualifying a function with this attribute forces the compiler to inline the function. If you also use the
-fno-inline-functionsoption, the function is inlined.
__declspec(noreturn)attribute and the
__attribute__((noreturn))function attribute. These attributes limit the ability of a debugger to display the call stack.
Avoid using the following features when building an image for debugging:
- Link time optimization. This feature performs aggressive optimizations and can remove large chunks of code.
- The armlink
- The armlink
--inlineoption. This option changes the image in such a way that the debug information might not correspond to the source code.