cancel
Showing results for 
Search instead for 
Did you mean: 

Debug multiple .elf files

DZimm.9
Associate II

Hello everyone

In one of our projects we created a bootloader and the application. Both projects are located in a separate workspace in the STMCubeIDE v1.10. My goal is to setup the GDB debugger in a way, that I can start the debugger from the bootloader and end up in the application. In this case, I could debug both projects at the same time.

Like most bootloaders is our bootloader checking if the version is correct and then jumps to the main applications start address. The memory location of the bootloader is defined in the linker script as:

/* Memories definition */
MEMORY
{
  CCMRAM	(xrw)	: ORIGIN = 0x10000000,	LENGTH = 64K
  SHAREDDATA (xrw)   : ORIGIN = 0x20000000, LENGTH = 512
  RAM	(xrw)	: ORIGIN = 0x20000200,	LENGTH = 128K-512
  FLASH	(rx)	: ORIGIN = 0x8000000,	LENGTH = 16K-128  
  PRELOADERINFO (rx) : ORIGIN = 0x08003F80, LENGTH = 128
}

Whereas the application's memory is defined as:

/* Memories definition */
MEMORY
{
    PROGRAMINFO (rx) : ORIGIN = 0x08020000, LENGTH = 512 /* ProgramInfo and BootInfo */
    FLASH (rx)       : ORIGIN = 0x08020200, LENGTH = 5*128K-512  /* Move APP to sector 5-9 */
    CCMRAM	(rwx)	: ORIGIN = 0x10000000,	LENGTH = 64K
    SHAREDDATA (xrw)	: ORIGIN = 0x20000000, LENGTH = 512
    RAM	(rwx)	: ORIGIN = 0x20000200,	LENGTH = 128K-512
}

I found several ways on how to setup multiple elf files (e.g. https://dzone.com/articles/multiple-binaries-with-gdbeclipse), but none of them really work...

What I found (but I'm not sure how to set this up) is an option under Run > Debug Configurations[Tab: Startup], where one can define multiple elf files. Upon launch, all the specified files are build and downloaded onto the CPU. Furthermore, the symbols are loaded from the elf file as well. Unfortunately, I haven't found any documentation about the offsets one need to specify.

There is a download and a symbol address offset which need to be defined.

For the download:

The offset is already taken from the linker script, therefore this offset should be 0, right?

For the symbol address:

Where can I get this offset? Using the .text offset doesn't really work. Once the debugger should jump the the applications code, only disassembly view is possible. My hope is to use the inline debugger for the main application as well.

I used readelf.exe to get an overview of the addresses and offsets:

There are 26 section headers, starting at offset 0x19101c:
 
Section Headers:
  [Nr] Name              Type            Addr     Off    Size   ES Flg Lk Inf Al
  [ 0]                   NULL            00000000 000000 000000 00      0   0  0
  [ 1] .isr_vector       PROGBITS        08020200 010200 000188 00   A  0   0  1
  [ 2] .text             PROGBITS        08020388 010388 00e954 00  AX  0   0  8
  [ 3] .rodata           PROGBITS        0802ecdc 01ecdc 0001a0 00   A  0   0  4
  [ 4] .programinfo      PROGBITS        08020000 010000 000076 00  WA  0   0  4
  [ 5] .ARM.extab        PROGBITS        0802ee7c 0204ac 000000 00   W  0   0  1
  [ 6] .ARM              ARM_EXIDX       0802ee7c 01ee7c 000008 00  AL  2   0  4
  [ 7] .preinit_array    PREINIT_ARRAY   0802ee84 0204ac 000000 04  WA  0   0  1
  [ 8] .init_array       INIT_ARRAY      0802ee84 01ee84 000004 04  WA  0   0  4
  [ 9] .fini_array       FINI_ARRAY      0802ee88 01ee88 000004 04  WA  0   0  4
  [10] .data             PROGBITS        20000200 020200 0002ac 00  WA  0   0  4
  [11] .bss              NOBITS          200004ac 0204ac 001564 00  WA  0   0  4
  [12] ._user_heap_stack NOBITS          20001a10 021a10 000600 00  WA  0   0  1
  [13] .ARM.attributes   ARM_ATTRIBUTES  00000000 0204ac 000030 00      0   0  1
  [14] .debug_info       PROGBITS        00000000 0204dc 0383ea 00      0   0  1
  [15] .debug_abbrev     PROGBITS        00000000 0588c6 0055fd 00      0   0  1
  [16] .debug_aranges    PROGBITS        00000000 05dec8 0019f0 00      0   0  8
  [17] .debug_ranges     PROGBITS        00000000 05f8b8 0017a8 00      0   0  8
  [18] .debug_macro      PROGBITS        00000000 061060 026f58 00      0   0  1
  [19] .debug_line       PROGBITS        00000000 087fb8 01a315 00      0   0  1
  [20] .debug_str        PROGBITS        00000000 0a22cd 0def19 01  MS  0   0  1
  [21] .comment          PROGBITS        00000000 1811e6 00007b 01  MS  0   0  1
  [22] .debug_frame      PROGBITS        00000000 181264 006f40 00      0   0  4
  [23] .symtab           SYMTAB          00000000 1881a4 005aa0 10     24 849  4
  [24] .strtab           STRTAB          00000000 18dc44 0032c0 00      0   0  1
  [25] .shstrtab         STRTAB          00000000 190f04 000117 00      0   0  1
Key to Flags:
  W (write), A (alloc), X (execute), M (merge), S (strings), I (info),
  L (link order), O (extra OS processing required), G (group), T (TLS),
  C (compressed), x (unknown), o (OS specific), E (exclude),
  y (purecode), p (processor specific)

Does anyone have any experience in setting this IDE up for multiple elf files?

Thank you in advance and best regards

Daniel

3 REPLIES 3
Maximilian Pohl
Associate III

any progress on that?

Other platforms you should be able to list the file(s) in a debugger script.

Do you need source to understand the code? In default operation Keil can have source behind one, but can debug code without any source code, so on the loader side you'd debug to the transition point, step on thru the transition, and however deep into the app you need to see it working/succeeding.

One might be able to merge .ELF files, not sure there's a specific commercial/off-the-shelf tools to do that, but I've built such tools in the past.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Pavel A.
Evangelist III

@Maximilian Pohl​ Yes there is progress. Recent CubeIDE versions support importing an elf executable for debugging, maybe even ELFs made with non-gnu toolchain.

The CubeIDE debugger can also load multiple ELF executables, or only the debug symbols without rewriting the flash.

If the other projects are in other Eclipse workspace, you can temporarily import them into the active workspace.