Keil Logo

Building to aid debugging

3.5 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 -g 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 example:

armclang -gdwarf-3

When linking, there are several armlink options available to help improve the debug view:

  • --debug. This option is the default.
  • --no_remove to 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 -O2 and -O3. If you must use these optimization levels, disable the automatic inlining with the armclang option -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:

  • --emit_debug_overlay_section
  • --emit_debug_overlay_relocs

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:

  • The __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-functions option, the function is inlined.
  • The __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 --no_debug option.
  • The armlink --inline option. This option changes the image in such a way that the debug information might not correspond to the source code.
Non-ConfidentialPDF file icon PDF version100748_0616_01_en
Copyright © 2016–2021 Arm Limited or its affiliates. All rights reserved. 
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.