Menu

Debug Symbols on elf files when linking multiple .rel files

cocus
2021-03-05
2021-03-10
  • cocus

    cocus - 2021-03-05

    Hi All!
    I started using the stm8 some years ago, tried some code on IAR and now I went ahead and tried to do the same but with sdcc just because I don't like IAR :)
    My code uses multiple .c source files, and I'm using the stm8 binutils (all of these are provided on PlatformIO, but that's just because I'm trying to use their vscode extension instead of creating my own Makefiles).
    If I try to build it and upload it with my stlink, it works. If I try to debug it with stm8-gdb; it "works", but I can't move thru the high level sources. The debugger clearly states that the elf file doesn't have debug symbols.
    So I went ahead and tried to reproduce the issue outside of the environment, which I could do easily. Consider two source files, a.c and b.c. On the first one I have the main() function, which calls another function declared on b.c. This function changes a register value, so it doesn't get optimized. I ran the following commands:

    sdcc -mstm8 --opt-code-size --debug --verbose -I./ -D STM8S003 -o a.rel -c a.c
    sdcc -mstm8 --opt-code-size --debug --verbose -I./ -D STM8S003 -o b.rel -c b.c
    sdcc -o file.elf -mstm8 --nostdlib --code-size 8192 --iram-size 1024 --debug --out-fmt-elf a.rel b.rel
    

    However, the resulting file.elf doesn't contain ANY debug symbols. The manual is not clear enough about the usage of --debug outside of sdcdb; and the format of the .cdb files. However, it's kind of a nice-to-see feature if you can generate elf files with debug symbols when running the sdcc with a single source and it runs thru linkage without using .rel files; but it doesn't work when using multiple .rel files.
    Is this documented somewhere? If so, is it even possible?
    Thanks.

     
    • Philipp Klaus Krause

      I think you are creating debug info in CDB format on compilation, then link as ELF.
      gdb expects debug info in DWARF format. AFAIK, SDCC generates CDB on --debug without --out-fmt-elf, DWARF on --debug --out-fmt-elf, so you'll need to add --out-fmt-elf to the compilation command line.

       
  • cocus

    cocus - 2021-03-05

    Oh, I couldn't figure out that you have to specify --out-fmt-elf to generate DWARF debug symbols when generating object code!
    I've tried it and it works perfectly! If it's possible, can this be explained in the manual? Maybe with some examples of invocation.
    Thanks!

     
    • Philipp Klaus Krause

      Since the SDCC 4.1.0 release is very close, it is too late for that. But I've just documented it in the manual in the sdcc-next branch, which will be merged after the release.

       
  • Maarten Brock

    Maarten Brock - 2021-03-06

    Is the generated file.elf even a real ELF file or is it actually an intel HEX file?

     
  • cocus

    cocus - 2021-03-10

    It's a real ELF file:

    $ file firmware.elf
    firmware.elf: ELF 32-bit MSB executable, STMicroeletronics STM8 8-bit, version 1 (IRIX), statically linked, with debug_info, not stripped
    
     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.