platformio / platformio/platformio-core

Support Attaching Debugger to a Running Target

Open
#3,789 0 comments 11 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

debugging feature
Dominant language
Python
Stars
9.5k
Forks
905
Avg merge
2d 13h
Merged PRs (30d)
2

Description

This is a feature request. In this post on the community forums, I asked whether it is possible to attach a debugger to a running target without resetting the target. My usecase is tracking down a pesky bug that only occurs sporadically, typically while I am running without a debugger attached.

The commands provided by maxgerhard worked perfectly, as I explained in the forum post. However, using this does require quite a bit of back-and-forth commenting and uncommenting variables in the platformio.ini to switch between "upload a debug image" and "attach to a debug image without resetting". Also, this makes the edit-compile-upload-test loop rather slow as you have to wait for the slow debugger start after every upload,.
I attribute this to the fact that PlatformIO only knows about the usecases "Upload (without debugger)" and "Start Debugging".

I would like to request the following features:

  • For the regular upload (equivalent of platformio run and platformio upload): Make it configurable whether the release configuration or the debug configuration is used. This enables to consistently upload debug images that can later be attached. Default should be to upload a release image, thus replicating the past behavior.
  • Offer a new command to attach the debugger to a running target (perhaps equivalent to a new parameter to platformio debug). This command will skip uploading the software, regardless of what has been set in debug_load_mode. It will also use an alternate set of debug_init_cmds (perhaps called debug_attach_init_cmds?) that do not reset the target.

Quoting from the forum post, the following commands worked on a STM32 BluePill board using an ST-Link V2 clone:

debug_init_cmds =
  target extended-remote $DEBUG_PORT
  $INIT_BREAK
  monitor halt
  monitor init
  monitor resume

Thanks!
Damian

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Begin with the platformio run, platformio upload, and platformio debug entry points, then read the platformio.ini settings debug_load_mode and debug_init_cmds named here. Done means regular upload can select release or debug images, while a separate attach flow skips uploading and uses initialization commands that do not reset the target.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
embedded-iot, tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.