Menu

#3580 Dwarf address truncated for STM8 large model (with fix)

open
nobody
None
other
5
2023-05-14
2023-05-07
No

1/ Sample code (main.c):
/ test case for Dwarf generation in large model /
const char padding[0x8FFF];
void main(void)
{
}

2/ Command:
sdcc -mstm8 --model-large --out-fmt-elf --debug main.c

3/ version:
SDCC : mcs51/z80/z180/r2k/r2ka/r3ka/sm83/tlcs90/ez80_z80/z80n/ds390/pic16/pic14/TININative/ds400/hc08/s08/stm8/pdk13/pdk14/pdk15/mos6502 TD- 4.2.14 #14028 (Linux)

4/ result of readelf -wF main.elf:
00000000 00000010 ffffffff CIE "" cf=1 df=-1 ra=9
LOC CFA ra
00000000 r8+2 c-1

00000014 00000014 00000000 FDE cie=00000000 pc=00001030..00001031
LOC CFA ra
00001030 r8+2 c-1
00001030 r8+2 c-1

Address should be 00011030 instead of 00001030

I propose a fix in the attached patch file.

1 Attachments

Discussion

  • Philipp Klaus Krause

    I'm not really familiar with with DWARF/ELF. So I just did some basic testing trying the usual OpenOCD/GDB combination (and a small LED blinking test program) for on-target debugging, which uses DWARF/ELF.

    1) Without the patch: Works for medium model, fails for large model.
    2) With patch: Works for medium model, fails for large model.

    So at least there is no apparent regression for this test case.
    AFAIK, ELF/DWARF was first used for the hc08 target? @epetrich, can you test if this patch breaks anything for that port?

    Some questions:

    • What are you using DWARF/ELF for?
    • Why did you introduce new assembler directive .3byte and .triple instead of emitting 3 .byte directives like SDCC otherwise does for 24-bit values (e.g. const stm8 function pointers for --model-large or _BitInt(24))? You made changes to sdas/asxxsrc/asmain.c. Is this something you came up with vs. something ported from newer upstream asxxxx?
     

    Last edit: Philipp Klaus Krause 2023-05-10
  • Christian Schoffit

    Hi Philipp,

    I am currently porting STM8 target for GDB 13. Is is a personal project based on this work: https://stm8-binutils-gdb.sourceforge.io, but without the binutil part. My goal is to have STM8 programs generated by SDCC fully debugable with GDB, with actively maintained tools. If it is successful, I will make it publicly available.

    I'm done with medium model, and for large model, we need to have the 24bit address of symbols correctly exposed in DWARF information. This is the goal of the proposed patch. Without this, it will not be possible to implement large model support in GDB.

    I didn't find a way to store in the DWARF sections the 24bit runtime address (which is not known at the compile time) with the byte directive, so this is the reason why I implemented the .3byte (or .triple) directive. I noticed that they were not commented in the file sdas/asstm8/stm8pst.c, contrary to the .4byte/quad. It seems that it was in the intention of someone to implement and use them. I just finished the work. By the way, these directives are implemented in recent upstream asxxxx, but in a much more complicated way.

    I didn't know about _Bitint(24). I simply replaced the faulty .dw 0, <symbol> by a more correct .db 0 followed by .3byte <symbol> in the generated asm file.

    And I'm also currently working on a second patch for fixing the wrong position of the return address in the .debug_frame section for the large memory model. If you agree, I'll submit it if we can find a way to achieve what I am trying do with the current patch.

     

    Last edit: Christian Schoffit 2023-05-10
    • Philipp Klaus Krause

      I see. I'm a bit reluctant, as we are kind of getting close to the 4.3.0 release, so I don't want to break anything (as of now, IMO, only [bugs:#3569] is critical enough to not do an RC1). But if I get a good test result from a user on the hc08/s08 side, I'd still go ahead and apply this patch.
      How far are you from having support in GDB for the large memory model (assuming that this patch gets applied)?

       

      Related

      Bugs: #3569

  • Christian Schoffit

    Of course there is no urgence to integrate this patch in the next release. We can take our time to carefully check all the impacts. I see it as an improvement which can be applied at the best time. From my experience with the medium memory model, I would say that it will be esay to get GDB working with STM8 in large model with an accurate DWARF information, provided by this patch and another one which will follow, as I mentioned before. I will look at the GDB side in the next few days to test large model programs.

     

    Last edit: Christian Schoffit 2023-05-10
  • Christian Schoffit

    I attached here the second patch required to debug STM8 large model programs with GDB.

     
    • Philipp Klaus Krause

      Thanks. I wonder about the interrupts, though:

      • on stm8, on interrupt a total of 9B are stored to the stack, 3B for the return address, the rest to save registers
      • on hc08, on interrupt a total of 5B are stored to the stack, 2B for the return address, the rest to save registers
      • on z80, , on interrupt a total of 2B are stored to the stack, for the return address.

      While z80 does not yet use DWARF, both stm8 and hc08 do (AFAIR, hc08 was actually the first port to support DWAREF/ELF), so it would be good it whatever solution is used works for both.

       
  • Christian Schoffit

    With all of this, we can use SDCC + GDB to create and debug SMT8 programs in both medium and large models.

     

Log in to post a comment.

MongoDB Logo MongoDB