-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Debugging not working with Arduino examples #48
Comments
Oh, that's a good tip! I've commented out the
Which is due to this bug: https://sourceforge.net/p/sdcc/bugs/2970/ (SDCC outputs a file with line-endings on Windows that it itself cannot read back later) Which is also really strange because why would the linker fail now and not before? So I added a workaround script to fixup all
import shutil
Import("env")
# convert \r\n (dos) to \n (unix)
def dos2unix(file_to_strip, output_file):
content = ''
outsize = 0
with open(file_to_strip, 'rb') as infile:
content = infile.read()
with open(output_file, 'wb') as output:
for line in content.splitlines():
outsize += len(line) + 1
output.write(line + b'\n')
def fix_rel_file(source, target, env):
for src in source:
print("dos2unix fix: " + str(src))
dos2unix(str(src), str(src)+".fixed")
shutil.move(str(src)+".fixed", str(src))
# for all source .rel files when building the lib and elf file
env.AddPreAction("$BUILD_DIR/libFrameworkArduino.lib", fix_rel_file)
env.AddPreAction("$BUILD_DIR/libFrameworkArduinoVariant.lib", fix_rel_file)
env.AddPreAction("$BUILD_DIR/${PROGNAME}.elf", fix_rel_file) And this got linking working. But for debugging, I'm hitting now the same issue as in #44 that the ELF DWARF symbols are broken. Debugging starts, and I can halt the chip, but it has no idea where it is in the C code. But that's at least one step further in finding out the cause. The firmware built in this debug mode works btw, removing EDIT: Now that I think about the Dos2Unix workaround, it may only appear when the archiver |
I believe there is a hacky way to build the firmware, but I'm not sure whether it'll work. If env.BuildSources(
os.path.join("$BUILD_DIR", "FrameworkArduinoVariant"),
os.path.join(FRAMEWORK_DIR, "variants", env.BoardConfig().get("build.variant"))
)
env.BuildSources(
os.path.join("$BUILD_DIR", "FrameworkArduino"),
os.path.join(FRAMEWORK_DIR, "cores", env.BoardConfig().get("build.core"))
) Then we need to remove extra_scripts =
pre:winterrupts_fix.py Import("env")
def replace_node(node):
if "WInterrupts" not in node.name:
return node
return env.Object(
node,
CFLAGS=[f for f in env["CFLAGS"] if f != "--out-fmt-elf"]
)
env.AddBuildMiddleware(replace_node) |
I've tested the above python code (with the code fix to remove
However, the resulting ELF file still has the bug
as per #44, so no debugging possible :( Also, with using archives and with the dos2unix fix above, the resulting binary is much smaller
So we should rather stay archives. And maybe with the dos2unix fix for Windows in these cases where A different question: What are the plans for release? New boads were added, SDCC was updated, tools like stm8gal etc were updated, the Arduino core was update, debugging was added, it however just works on baremetal examples where SDCC bugs don't occur, like they do in SPL or Arduino builds. This is almost perfect. However sadly, the SDCC people seem slow (the line-ending bug for Windows has been known for a year, all it got was a comment saying 'maybe fixed in 4.1.0, which it didn't), so I'm not expecting an answer on the more critical DWARF generation bug anytime soon. Still the improvements from the last release are substantial. Release now with partly non-functional debugging features or wait for release later? |
I published it yesterday https://github.com/platformio/platform-ststm8/releases/tag/v2.0.0 |
There have been new developments in this -- SDCC devs say that |
Not sure if this helps, but in my setup debugging STM8 with arduino framework seems working.
And in packages/tool-stm8binutils I had to replace stm8-gdb with a fresh build, because of libpython2.7.so issue similar to platformio/platformio-vscode-ide#1792 platformio.ini is this :
the additional debug flag is needed because otherwise sduino disables SWIM during init in wiring_init.c :
If the target was still running a non-debug arduino build, SWIM is already disabled and openocd cannot connect. Therefore I press the reset button on the board to keep the target in reset while platformio starts openocd. After that openocd holds target in reset and gdb overwrites the flash with code that has 'ENABLE_SWIM'. So for subsequent debug uploads, no need to press the reset button. |
That's very interesting, for reference, what does PlatformIO show about the used SDCC version at the beginning of compilation ("PACKAGES:")? You've not overwritten the toolchain-sdcc folder with your own version right? |
@maxgerhardt @valeros why does platform.py force the use of an older sdcc version for arduino framework? |
If we don't use the same SDCC version the original SDuino core does (https://github.com/tenbaht/sduino/blob/development/package_sduino_stm8_index.json#L380-L388) there might be situations where the compiled result is different (and behaves different) than in the Arduino IDE, so for compatibility reasons they are kept the same. For SPL there is no "reference compiler", so we use the latest one. The SDCC update should go through in the core first. tenbaht/sduino#121 has been long open on this, but no change yet. |
Issue is just for tracking what was said in #38.
Hopefully there will be an update on that soon, so that debugging can be fully working in any framework :)
The text was updated successfully, but these errors were encountered: