[Arduino IDE 2 Extension] AVR debugging with avr-gdb, PlatformIO-like workflow without leaving Arduino IDE

Happy Arduino Day everyone.

I built an extension for Arduino IDE 2.x that brings real avr-gdb debugging into the IDE using avr_debug.

Demo video

https://www.youtube.com/watch?v=0JLI-_ybyCw&feature=youtu.be

:backhand_index_pointing_right: Repo:
https://github.com/IamTheVector/arduino-avr-stub-debug

:backhand_index_pointing_right: avr_debug (jdolinay):
https://github.com/jdolinay/avr_debug

:backhand_index_pointing_right: AVR 8-bit Toolchain (Microchip):
https://www.microchip.com/en-us/tools-resources/develop/microchip-studio/gcc-compilers

What it does

It enables on-target debugging over serial on AVR boards, directly inside Arduino IDE:

  • breakpoints

  • step into / step over

  • variable inspection

  • call stack

  • GDB console

Why this exists

Arduino IDE is great for accessibility, but debugging is basically limited to Serial.print.

On the other side, PlatformIO gives you proper debugging, but introduces more tooling, configuration, and friction.

This extension is meant to sit in between:

  • keep Arduino workflow

  • add real debugging capabilities

Real use case

I mainly built this for teaching.

Explaining Arduino execution flow with prints is inefficient.
With a debugger you can:

  • follow execution step by step

  • see variables change in real time

  • understand conditions and timing properly

It makes a big difference in how fast people actually understand what the MCU is doing.

Setup

  • install the .vsix from the repo

  • install avr_debug as a library

  • use avr-gdb from Microchip toolchain

Full steps are in the README.

Feedback

If you try it, feedback is welcome, especially on:

  • COM port handling

  • stability

  • setup clarity

If you’ve ever thought “Arduino needs real debugging”, this is basically that.

Happy Arduino Day, and happy debugging.

Thanks @Blu-Vector. I submitted it for inclusion in the community-managed catalog of Arduino IDE 2.x extensions:

https://github.com/IamTheVector/arduino-avr-stub-debug#important-settings

  • avrStubDebug.gdbPath (e.g. C:\\avr8-gnu-toolchain\\bin\\avr-gdb.exe)
  • avrStubDebug.elfPath (real ELF path for your sketch)
  • avrStubDebug.serialPort (leave empty for auto-detect; examples: COM12 on Windows, /dev/ttyACM0 on Linux, /dev/cu.usbmodem* on macOS)

Did you investigate using obtaining this data from the information exposed by the "Arduino IDE API for VS Code extensions" extension that is bundled with the Arduino IDE installation?

Super tool, thanks for sharing!

Yes, but for some reason the Extension was failing most of the time in the task unfortunately! :frowning: ! Dunno why.

@Blu-Vector have you been aware of the alternative Arduino core MiniCore by MCUdude? This core covers all the small ATmegas (e.g., the ATmega328P) and provides an integrated debugging solution via PyAvrOCD. After installing it and selecting one of the MCUs in Arduino's Tools menu, the debug button will no longer be greyed out, and you can attach a Microchip debug probe, such as SNAP (for 10€), or you can even turn an Arduino Uno into a debug probe. However, a pure software-only solution, such as your solution, also has, of course, clear advantages.

Yes I had a look at it and also at a similar sistem that enabled debugging trough flashing a bootloader. I will use my debugger mainly for teaching so I need the system to work out of the shelf. Thanks for the suggestion :blush:

If you look for a plug-and-play solution, then the Microchip ATmega328P Xplained Mini board (roughly 20 €) with an integrated on-board debugger and XMiniCore is the right choice. It is a bit more expensive than a UNO clone, though. But you can get an educational rebate from Microchip.