Discuss here different C compiler set ups, and compiling executables for the ESP8266

User avatar
By projectgus
#18346
cal wrote:In call0_analyze_prologue the following is used
Code: Select allprologue_sal = find_pc_line (start, 0);
 if (prologue_sal.line != 0)  /* Found debug info.  */
   body_pc = prologue_sal.end;


That means the analysis stops at .LVL8 and so misses the necessary part at .LVL9.

I thought skip_prologue_using_sal could be used to fix the problem but
as far as I see it does stop at the FIRST non prologue line, but what we need is the LAST code
OF the prologue line.


Nice catch!

I think having body_pc set to "the first non-prologue instruction" is actually what you want, isn't it? Because the loop that scans instructions has "ia < bodypc" as the terminating condition, so it won't scan the instruction at bodypc, just all the instructions preceding it.

For my 2c, I think this is possibly a compiler bug if the DWARF information doesn't correctly identify the end of the prologue, but I don't know enough about gcc and optimisations to say for sure. Fixing it in gdb seems like a good idea, regardless.

Does anybody know of a way to fake/add ROM symbols to an executable using tools from the GNU tool chain?
I think I could hack it using elfsh but would prefer some gcc/gas/gld/objcopy hackery.


I have also wanted this. jcmvbkbc's esp-elf-rom is useful but gdb tries to load it as a new image. I don't have a solution yet either, there must be a straightforward way though.


Angus
User avatar
By jcmvbkbc
#18351
projectgus wrote:
cal wrote:Does anybody know of a way to fake/add ROM symbols to an executable using tools from the GNU tool chain?
I think I could hack it using elfsh but would prefer some gcc/gas/gld/objcopy hackery.


I have also wanted this. jcmvbkbc's esp-elf-rom is useful but gdb tries to load it as a new image. I don't have a solution yet either, there must be a straightforward way though.

You can load your main image as usual and then use add-symbol-file bootrom.elf 0x40000000 to add symbols for ROM.
User avatar
By jcmvbkbc
#18366
projectgus wrote:I think having body_pc set to "the first non-prologue instruction" is actually what you want, isn't it? Because the loop that scans instructions has "ia < bodypc" as the terminating condition, so it won't scan the instruction at bodypc, just all the instructions preceding it.

For my 2c, I think this is possibly a compiler bug if the DWARF information doesn't correctly identify the end of the prologue, but I don't know enough about gcc and optimisations to say for sure. Fixing it in gdb seems like a good idea, regardless.

"The first non-prologue instruction" does not always mean the prologue code is over. I didn't put any unnecessary blockage after the prologue and before epilogue to allow for better instruction scheduling, and from my observations optimization passes often mix prologue instructions with the function code.
User avatar
By cal
#18373
jcmvbkbc wrote:
projectgus wrote:
cal wrote:Does anybody know of a way to fake/add ROM symbols to an executable using tools from the GNU tool chain?
I think I could hack it using elfsh but would prefer some gcc/gas/gld/objcopy hackery.


I have also wanted this. jcmvbkbc's esp-elf-rom is useful but gdb tries to load it as a new image. I don't have a solution yet either, there must be a straightforward way though.

You can load your main image as usual and then use add-symbol-file bootrom.elf 0x40000000 to add symbols for ROM.


YES!
Thats exactly what I needed. Thanks!
Shame on me: I used the ELF trick for disasm (via empty C file and objcopy) but overlooked it for symbol definitions.
Instead I tried to force the symbols into the firmware image, grr.

Here the successful usage:
Code: Select all(gdb) bt
#0  gdb_breakpoint () at arch_esp8266.c:19
#1  0x401046ae in uart0_rx_intr_handler (para=0x3fffde28) at uart.c:216
#2  0x4000050c in ?? ()
#3  0x4000050c in ?? ()
Backtrace stopped: previous frame identical to this frame (corrupt stack?)
(gdb) add-symbol-file ../esp-elf-rom/esp-elf-rom/bootrom.elf 0x40000000
add symbol table from file "../esp-elf-rom/esp-elf-rom/bootrom.elf" at
   .text_addr = 0x40000000
(y or n) y
Reading symbols from .../esp-elf-rom/esp-elf-rom/bootrom.elf...warning: section .text not found in .../esp-elf-rom/esp-elf-rom/bootrom.elf
(no debugging symbols found)...done.
(gdb) bt
#0  gdb_breakpoint () at arch_esp8266.c:19
#1  0x401046ae in uart0_rx_intr_handler (para=0x3fffde28) at uart.c:216
#2  0x4000050c in _xtos_l1int_handler ()
#3  0x4000050c in _xtos_l1int_handler ()
Backtrace stopped: previous frame identical to this frame (corrupt stack?)


Great!

It should be possible to just extract the debug sections then and just load them.
If put and versioned in the repository it could be easily used without the firmware blob.

Thanks,
Cal