Skip to content

Flash with program_esp on the first debug session too - #1778

Open
naelolaiz wants to merge 1 commit into
platformio:developfrom
naelolaiz:fix-debug-first-session
Open

naelolaiz wants to merge 1 commit into
platformio:developfrom
naelolaiz:fix-debug-first-session

Conversation

@naelolaiz

Copy link
Copy Markdown

configure_debug_session switches the debugger's load step to program_esp only when every flash image already exists. pio debug configures the session before it builds the firmware, so the first session after a clean build, or on a new environment, finds no bootloader or partition table yet and falls back to GDB load. Depending on the chip, load then either fails (Load failed, flash addresses not writable) or writes the new ELF sections into flash through the mapping of the application already there, leaving an image whose checksum no longer matches, so the chip resets in a loop without reaching app_main. Sessions started on a project that was already built were not affected.

The images are build outputs that exist by the time GDB runs the load commands, so the check is dropped.

Tested:

  • ESP32-S3 (ESP32-S3-WROOM-1, esp32-s3-devkitc-1, debug_tool = esp-builtin, the pinned OpenOCD v0.11.0-esp32-20220706), examples/espidf-hello-world, first pio debug after rm -rf .pio:
    • Current develop: GDB falls back to load, which cannot write the flash sections (Warn : address 0x3c010020 not writable) and ends in Load failed; the session never starts.
    • With this change: program_esp writes and verifies the bootloader, partition table and application (** Verify OK ** three times), and the session stops at app_main.
  • ESP32-S31 (with the S31 support branch, see Add support for ESP32-S31 (ESP32-S31-Function-CoreBoard-1) #1777): before the change, the first pio debug after a clean build ran GDB load and the board reset in a loop; with it, the first session flashes with program_esp.
  • esp32dev and esp32-c6-devkitm-1 with no images built yet: the load commands change from load to monitor program_esp for bootloader, partition table and application, in the format OpenOCD v0.11 expects.

configure_debug_session switched the GDB load to program_esp only when
every flash image already existed. `pio debug` configures the session
before it builds the firmware, so on the first session of a clean
build the bootloader and partition table were missing and GDB fell
back to `load`. For ESP-IDF images that writes the new ELF sections
into flash through the mapping of the application already there and
leaves an image that no longer matches its checksum: on an ESP32-S31
the chip then reset in a loop and never reached app_main.

The images are build outputs that exist by the time GDB runs the load
commands, so stop requiring them up front. Sessions started on an
already built project were not affected.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TyrpBtw45nhJDbpwhXbBbd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants