GDB stub debugging on the the Teensy4.1 works fine on smaller sketches. It fails on larger sketches because the teensy loader returns success before the switching of the usb device on the teensy to virtual serial mode has been completed and this change has been picked up by the PC OS and serial device ports created.
This is a known problem with the teensy loader.
I need to delay the launching of gdb on the host until the PC OS has fully created device ports. In my Ubuntu setup this would be indicated by the presence of /dev/ttyACM0 and /dev/ttyACM1 in the the file system.
I am a novice in platformIO, so any help will be gratefully received.
I would like to do this without resorting to editing the launch.json template file if possible.
So, any ideas, or tips on how to edit the template.
Thanks,
Roger
You can control the PIO Debugging solution using platformio.ini
and these options
https://docs.platformio.org/en/latest/projectconf/section_env_debug.html
#ivankravets
Thanks for the reply.
I am already using the following settings in platformio.ini.
[env:teensy41]
platform = teensy
board = teensy41
framework = arduino
lib_deps =
adafruit/Adafruit GFX Library@^1.11.3
adafruit/Adafruit SSD1306@^2.5.7
build_src_filter = +<*.cpp>
; GDB Debugging
build_type = debug
build_unflags = -DUSB_SERIAL
build_flags = -DUSB_DUAL_SERIAL -DGDB_DEBUGGING
debug_port = /dev/ttyACM1
debug_tool = custom
debug_load_mode = manual
debug_server =
debug_init_cmds =
target extended-remote $DEBUG_PORT
$INIT_BREAK
define pio_reset_run_target
interrupt
tbreak loop
continue
end
define pio_restart_target
echo Restart is undefined for now.
end
debug_init_break =
My problem is that gdb is being launched on the host pc before the OS creates the required serial port (/dev/ttyACM1).
This is what is in .vscode/launch.json
// AUTOMATICALLY GENERATED FILE. PLEASE DO NOT MODIFY IT MANUALLY
//
// PIO Unified Debugger
//
// Documentation: https://docs.platformio.org/page/plus/debugging.html
// Configuration: https://docs.platformio.org/page/projectconf/section_env_debug.html
{
"version": "0.2.0",
"configurations": [
{
"type": "platformio-debug",
"request": "launch",
"name": "PIO Debug",
"executable": "/home/roger/concerteensy/.pio/build/teensy41/firmware.elf",
"projectEnvName": "teensy41",
"toolchainBinDir": "/home/roger/.platformio/packages/toolchain-gccarmnoneeabi/bin",
"internalConsoleOptions": "openOnSessionStart",
"preLaunchTask": {
"type": "PlatformIO",
"task": "Pre-Debug"
}
},
{
"type": "platformio-debug",
"request": "launch",
"name": "PIO Debug (skip Pre-Debug)",
"executable": "/home/roger/concerteensy/.pio/build/teensy41/firmware.elf",
"projectEnvName": "teensy41",
"toolchainBinDir": "/home/roger/.platformio/packages/toolchain-gccarmnoneeabi/bin",
"internalConsoleOptions": "openOnSessionStart"
},
{
"type": "platformio-debug",
"request": "launch",
"name": "PIO Debug (without uploading)",
"executable": "/home/roger/concerteensy/.pio/build/teensy41/firmware.elf",
"projectEnvName": "teensy41",
"toolchainBinDir": "/home/roger/.platformio/packages/toolchain-gccarmnoneeabi/bin",
"internalConsoleOptions": "openOnSessionStart",
"loadMode": "manual"
}
]
}
Where might I find what is in the “Pre-Debug” task? My .vscode directory does not contain a tasks.json file. I am a complete novice in this area.
Roger
Could you try the following?
debug_init_cmds =
shell sleep 5
target extended-remote $DEBUG_PORT
See other ideas:
Thanks that looks like exactly the command I need!
I really must get a more up to date gdb manual. I have been using gdb for forty years and never come across it!
I will do a quick test with the sleep and if that works replace it with a script to check that $DEBUG_PORT actually exists and is usable.
Cheers,
Roger
1 Like
The shell command approach fixes the host end timing problems. However I now appear to be hitting the problem referenced here.
https://forum.pjrc.com/threads/61664-No-USB-serial-with-Teensy-4-x-compiled-Optimize-Debug?highlight=reset_PFD
I will do some more tests, but this looks like a show stopper. Debugging optimised code is not fun.
#ivankravets Is there any chance of you guys looking into this.
Thanks,
Roger
p.s. You are doing great work in these difficult times.
Пу́тін — хуйло́
I have enabled unoptimised code and the test sketch is getting further.
The problems I am seeing seem related to the USB serial ports. By default the serial monitor is being started on /dev/ttyACM1 rather than /dev/ttyACM0. Forcing the monitor port setting in platformio.ini results in the following error.
Error: [Errno 2] could not open port /dev/ttyACM0: [Errno 2] No such file or directory: '/dev/ttyACM0'
I suspect that /dev/ttyACM1 is appearing before /dev/ttyACM0 in the linux filesystem. I the platformio code is fooled by the this.