This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Building and debugging a monolithic bin/hex/elf/out

It would be useful in debugging to be able to fire up gdb and point it at a single binary so that I can step through code in both the bootloader and the application. The mergehex tool from Nordic makes it easy to merge soft device, bootloader and application hex files into one. I can then flash a single hex file. This much I can do now.

But I don't debug with the hex file - I debug with the elf file. And there's no such tool as "merge elf" that I can find. I guess I could start building both bootloader and application as a single project. We have no elf file for the soft device, only a hex file, but that should be OK to leave out of the combined elf file.

How can I build a combined elf file for both bootloader and application, ideally leaving them as separate projects in my build system? I'm using gcc and make.

Note that merging the hex files then going back to ELF from there appears not to be a good option, because the debug symbols are lost:

$make gdb-client
printf "target remote localhost:2331\nload\nmon reset\nbreak main\nset print elements 0\neval \"monitor exec SetRTTAddr %%p\", &_SEGGER_RTT\n" > _build/.gdbinit
/Users/Eliot/dev/gcc-arm-none-eabi-4_9-2015q3/bin/arm-none-eabi-gdb -x _build/.gdbinit _build/biketracker.elf
...
Reading symbols from _build/biketracker.elf...(no debugging symbols found)...done.
0x000006d0 in ?? ()
Loading section .sec1, size 0x7c0 lma 0x0
Loading section .sec2, size 0xf000 lma 0x1000
Loading section .sec3, size 0xafe0 lma 0x10000
Loading section .sec4, size 0x5000 lma 0x1b000
Loading section .sec5, size 0x10000 lma 0x20000
Loading section .sec6, size 0x6690 lma 0x30000
Loading section .sec7, size 0x7c24 lma 0x38000
Loading section .sec8, size 0x4 lma 0x10001014
Start address 0x0, load size 252504
Transfer rate: 41097 KB/sec, 3945 bytes/write.
Resetting target
No symbol table is loaded.  Use the "file" command.
Make breakpoint pending on future shared library load? (y or [n]) [answered N; input not from terminal]
_build/.gdbinit:6: Error in sourced command file:
No symbol table is loaded.  Use the "file" command.
Related