Skip to content

Build DWARF4 for IAR Workbench Debugging

Published: at 05:42 PM

While VSCode + Arm GCC toolchain + Cortex-Debug + OpenOCD as embedded development environment is getting better everyday. And it has generally became my default choice for developing Arm based MCUs. The IAR Workbench debugging experience is still way ahead of VSCode and its extension combinations. Sometimes I have to build the .elf file with Arm GCC toolchain and load it within IAR Workbench.

DWARF 5 is the latest standard support by most modern compilers such as GCC.

Now ever since early this year, I have bumped all my Arm GCC toolchain to latest which is version 12.1. Once I launched debugging my imported .elf file, I will got this error message says:

ELF/DWARF Error: Unsupported debug_info format version: 5
IAR cannot recognize DWARF 5

Now if you double check the .elf file for the DWARF version, you will see it is version 5:

arm-none-eabi-readelf --debug-dump=info ./build/Standard/main_blinky.elf | grep -A 2 'Compilation Unit @'
Dump info for DWARF 5

The problem and solution is straightforward: since GCC 11, it by default will built DWARF 5. To force it to build DWARF 4, you need to add -gdwarf-4 to your CFLAGS and CXXFLAGS.

Now if you check the built file again:

Dump info for DWARF 4