I'm currently on a quest to use SDCC with STM8-GDB to get debugging working in VSCode. So far this works well with very simple programs and I can fully debug the code with SDCC and the --debug --out-fmt-elf option, then feed that ELF with debug symbols into stm8-gdb in parallel with openOCD.
I am using the latest SDCC 4.1.0.
SDCC : mcs51/z80/z180/r2k/r2ka/r3ka/gbz80/tlcs90/ez80_z80/z80n/ds390/pic16/pic14/TININative/ds400/hc08/s08/stm8/pdk13/pdk14/pdk15 4.1.0 #12072 (MINGW64)
published under GNU General Public License (GPL)
My problem is when letting SDCC compile the S8Duino Arduino core for STM8 devices, it fails without any legible error message on the compilation of the WInterrupts.c file. It can be found at https://github.com/tenbaht/sduino/blob/development/sduino/stm8/cores/sduino/WInterrupts.c
But it only fails when I give it the flag --debug. Here is the invocation that fails, with --verbose -V:
PS C:\Users\Max\Documents\PlatformIO\Projects\stm8_testing> C:\Users\Max\.platformio\packages\toolchain-sdcc\bin\sdcc -o .pio\build\stm8sblue_debug2\FrameworkArduino\WInterrupts.c.rel -c -mstm8 --debug --out-fmt-elf -DF_CPU=16000000L -DPLATFORMIO=50101 -DSTM8S_BLUE -DSTM8S103 -DARDUINO_ARCH_STM8 -DARDUINO=10802 -Ddouble=float -DUSE_STDINT -D__PROG_TYPES_COMPAT__ -D__PLATFORMIO_BUILD_DEBUG__ -IC:\Users\Max\.platformio\packages\framework-arduinoststm8\cores\sduino -IC:\Users\Max\.platformio\packages\framework-arduinoststm8\STM8S_StdPeriph_Driver\inc -IC:\Users\Max\.platformio\packages\framework-arduinoststm8\variants\standard --verbose -V C:\Users\Max\.platformio\packages\framework-arduinoststm8\cores\sduino\WInterrupts.c
sdcc: Calling preprocessor...
sdcc: sdcpp.exe -nostdinc -Wall -std=c11 -D"F_CPU=16000000L" -D"PLATFORMIO=50101" -D"STM8S_BLUE" -D"STM8S103" -D"ARDUINO_ARCH_STM8" -D"ARDUINO=10802" -D"double=float" -D"USE_STDINT" -D"__PROG_TYPES_COMPAT__" -D"__PLATFORMIO_BUILD_DEBUG__" -I"C:\Users\Max\.platformio\packages\framework-arduinoststm8\cores\sduino" -I"C:\Users\Max\.platformio\packages\framework-arduinoststm8\STM8S_StdPeriph_Driver\inc" -I"C:\Users\Max\.platformio\packages\framework-arduinoststm8\variants\standard" -obj-ext=.rel -D__SDCC_STACK_AUTO -D__SDCC_CHAR_UNSIGNED -D__SDCC_MODEL_MEDIUM -D__SDCC_INT_LONG_REENT -D__SDCC_FLOAT_REENT -D__SDCC=4_1_0 -D__SDCC_VERSION_MAJOR=4 -D__SDCC_VERSION_MINOR=1 -D__SDCC_VERSION_PATCH=0 -D__SDCC_REVISION=12072 -D__SDCC_stm8 -D__STDC_NO_COMPLEX__=1 -D__STDC_NO_THREADS__=1 -D__STDC_NO_ATOMICS__=1 -D__STDC_NO_VLA__=1 -D__STDC_ISO_10646__=201409L -D__STDC_UTF_16__=1 -D__STDC_UTF_32__=1 -isystem "C:\Users\Max\.platformio\packages\toolchain-sdcc\bin\..\include\stm8" -isystem "C:\Users\Max\.platformio\packages\toolchain-sdcc\bin\..\include" "C:\Users\Max\.platformio\packages\framework-arduinoststm8\cores\sduino\WInterrupts.c"
+ C:\Users\Max\PLATFO~1\packages\TODCB3~1\bin\sdcpp.exe -nostdinc -Wall -std=c11 -D"F_CPU=16000000L" -D"PLATFORMIO=50101" -D"STM8S_BLUE" -D"STM8S103" -D"ARDUINO_ARCH_STM8" -D"ARDUINO=10802" -D"double=float" -D"USE_STDINT"
-D"__PROG_TYPES_COMPAT__" -D"__PLATFORMIO_BUILD_DEBUG__" -I"C:\Users\Max\.platformio\packages\framework-arduinoststm8\cores\sduino" -I"C:\Users\Max\.platformio\packages\framework-arduinoststm8\STM8S_StdPeriph_Driver\inc" -I"C:\Users\Max\.platformio\packages\framework-arduinoststm8\variants\standard" -obj-ext=.rel -D__SDCC_STACK_AUTO -D__SDCC_CHAR_UNSIGNED -D__SDCC_MODEL_MEDIUM -D__SDCC_INT_LONG_REENT -D__SDCC_FLOAT_REENT -D__SDCC=4_1_0 -D__SDCC_VERSION_MAJOR=4 -D__SDCC_VERSION_MINOR=1 -D__SDCC_VERSION_PATCH=0 -D__SDCC_REVISION=12072 -D__SDCC_stm8 -D__STDC_NO_COMPLEX__=1 -D__STDC_NO_THREADS__=1 -D__STDC_NO_ATOMICS__=1 -D__STDC_NO_VLA__=1 -D__STDC_ISO_10646__=201409L -D__STDC_UTF_16__=1 -D__STDC_UTF_32__=1 -isystem "C:\Users\Max\.platformio\packages\toolchain-sdcc\bin\..\include\stm8" -isystem "C:\Users\Max\.platformio\packages\toolchain-sdcc\bin\..\include" "C:\Users\Max\.platformio\packages\framework-arduinoststm8\cores\sduino\WInterrupts.c"
sdcc: Generating code...
sdcc: Calling assembler...
sdcc: sdasstm8.exe -plosgffwy "".pio\build\stm8sblue_debug2\FrameworkArduino\WInterrupts.c".asm"
+ C:\Users\Max\PLATFO~1\packages\TODCB3~1\bin\sdasstm8.exe -plosgffwy "".pio\build\stm8sblue_debug2\FrameworkArduino\WInterrupts.c".asm"
+ C:\Users\Max\PLATFO~1\packages\TODCB3~1\bin\sdasstm8.exe -plosgffwy "".pio\build\stm8sblue_debug2\FrameworkArduino\WInterrupts.c".asm" returned errorcode -1073741819
And the $LASTEXITCODE is 1, indicating failure. It does however create 4 new files (.asm, .lst, .rel, .sym), they are attached here. The .sym file is empty for some reason.
Just removing the --debug gives
PS C:\Users\Max\Documents\PlatformIO\Projects\stm8_testing> C:\Users\Max\.platformio\packages\toolchain-sdcc\bin\sdcc -o .pio\build\stm8sblue_debug2\FrameworkArduino\WInterrupts.c.rel -c -mstm8 --out-fmt-elf -DF_CPU=16000000L -DPLATFORMIO=50101 -DSTM8S_BLUE -DSTM8S103 -DARDUINO_ARCH_STM8 -DARDUINO=10802 -Ddouble=float -DUSE_STDINT -D__PROG_TYPES_COMPAT__ -D__PLATFORMIO_BUILD_DEBUG__ -IC:\Users\Max\.platformio\packages\framework-arduinoststm8\cores\sduino -IC:\Users\Max\.platformio\packages\framework-arduinoststm8\STM8S_StdPeriph_Driver\inc -IC:\Users\Max\.platformio\packages\framework-arduinoststm8\variants\standard --verbose -V C:\Users\Max\.platformio\packages\framework-arduinoststm8\cores\sduino\WInterrupts.c
sdcc: Calling preprocessor...
sdcc: sdcpp.exe -nostdinc -Wall -std=c11 -D"F_CPU=16000000L" -D"PLATFORMIO=50101" -D"STM8S_BLUE" -D"STM8S103" -D"ARDUINO_ARCH_STM8" -D"ARDUINO=10802" -D"double=float" -D"USE_STDINT" -D"__PROG_TYPES_COMPAT__" -D"__PLATFORMIO_BUILD_DEBUG__" -I"C:\Users\Max\.platformio\packages\framework-arduinoststm8\cores\sduino" -I"C:\Users\Max\.platformio\packages\framework-arduinoststm8\STM8S_StdPeriph_Driver\inc" -I"C:\Users\Max\.platformio\packages\framework-arduinoststm8\variants\standard" -obj-ext=.rel -D__SDCC_STACK_AUTO -D__SDCC_CHAR_UNSIGNED -D__SDCC_MODEL_MEDIUM -D__SDCC_INT_LONG_REENT -D__SDCC_FLOAT_REENT -D__SDCC=4_1_0 -D__SDCC_VERSION_MAJOR=4 -D__SDCC_VERSION_MINOR=1 -D__SDCC_VERSION_PATCH=0 -D__SDCC_REVISION=12072 -D__SDCC_stm8 -D__STDC_NO_COMPLEX__=1 -D__STDC_NO_THREADS__=1 -D__STDC_NO_ATOMICS__=1 -D__STDC_NO_VLA__=1 -D__STDC_ISO_10646__=201409L -D__STDC_UTF_16__=1 -D__STDC_UTF_32__=1 -isystem "C:\Users\Max\.platformio\packages\toolchain-sdcc\bin\..\include\stm8" -isystem "C:\Users\Max\.platformio\packages\toolchain-sdcc\bin\..\include" "C:\Users\Max\.platformio\packages\framework-arduinoststm8\cores\sduino\WInterrupts.c"
+ C:\Users\Max\PLATFO~1\packages\TODCB3~1\bin\sdcpp.exe -nostdinc -Wall -std=c11 -D"F_CPU=16000000L" -D"PLATFORMIO=50101" -D"STM8S_BLUE" -D"STM8S103" -D"ARDUINO_ARCH_STM8" -D"ARDUINO=10802" -D"double=float" -D"USE_STDINT"
-D"__PROG_TYPES_COMPAT__" -D"__PLATFORMIO_BUILD_DEBUG__" -I"C:\Users\Max\.platformio\packages\framework-arduinoststm8\cores\sduino" -I"C:\Users\Max\.platformio\packages\framework-arduinoststm8\STM8S_StdPeriph_Driver\inc" -I"C:\Users\Max\.platformio\packages\framework-arduinoststm8\variants\standard" -obj-ext=.rel -D__SDCC_STACK_AUTO -D__SDCC_CHAR_UNSIGNED -D__SDCC_MODEL_MEDIUM -D__SDCC_INT_LONG_REENT -D__SDCC_FLOAT_REENT -D__SDCC=4_1_0 -D__SDCC_VERSION_MAJOR=4 -D__SDCC_VERSION_MINOR=1 -D__SDCC_VERSION_PATCH=0 -D__SDCC_REVISION=12072 -D__SDCC_stm8 -D__STDC_NO_COMPLEX__=1 -D__STDC_NO_THREADS__=1 -D__STDC_NO_ATOMICS__=1 -D__STDC_NO_VLA__=1 -D__STDC_ISO_10646__=201409L -D__STDC_UTF_16__=1 -D__STDC_UTF_32__=1 -isystem "C:\Users\Max\.platformio\packages\toolchain-sdcc\bin\..\include\stm8" -isystem "C:\Users\Max\.platformio\packages\toolchain-sdcc\bin\..\include" "C:\Users\Max\.platformio\packages\framework-arduinoststm8\cores\sduino\WInterrupts.c"
sdcc: Generating code...
sdcc: Calling assembler...
sdcc: sdasstm8.exe -plosgffw "".pio\build\stm8sblue_debug2\FrameworkArduino\WInterrupts.c".asm"
+ C:\Users\Max\PLATFO~1\packages\TODCB3~1\bin\sdasstm8.exe -plosgffw "".pio\build\stm8sblue_debug2\FrameworkArduino\WInterrupts.c".asm"
A successfull compilation with exit-code 0. Output files are again attached.
Why?
For an reproduction of my issue, you can do as follows:
pio run once in the cloned directory (will download toolchains and other stuff)~/.platformio/packages/toolchain-sdcc with the SDCC files of the latest release (it uses 3.8.4 by default)pio run -v and observe normal (verbose) compilation with the new SDCCbuild_type = debug to the end of the platformio.ini, rerun po run -v --> see compilation failurebuild_flags = --verbose -V to the platformio.ini to give those flags to SDCC during compilationIf there's more that you need to know, let me know.
Adding compile_output_debug.zip here because it didn't upload in the first post for some reason.
I was just given a good tip in https://github.com/platformio/platform-ststm8/issues/48#issuecomment-806820829
Refering to https://www.mail-archive.com/sdcc-user@lists.sourceforge.net/msg05982.html, this issue seems to be known.. but not tracked?
I've tested it by commenting out
__nakedin the affected file and compilation of that file works, linking still failed on my Windows machine because [bugs:#2970] is still unfixed in SDCC 4.1.0, but that's another story.So this issue is now narrowed down to the
__nakedusage which fails in debug mode.Related
Bugs: #2970
Last edit: Maarten Brock 2021-05-25
This is now probably fixed in [r12500]. The compiler tried to output information about the stack frame, but that information was missing for naked functions when compiling for stm8, resulting in some malformed expressions in the debug information in the assembly.