kwartzlab makerspace

Dec
12

Remote debugging an Arduino

By

I don’t have a fancy JTAG or ICE system for Arduino debugging. AVR simulators can only take you so far. So I’ve been working on creating a remote debugging stub, so you can use GDB (the GNU Debugger) and Insight (a graphical interface to GDB) on your PC to remotely debug code running on the Arduino board (or any AVR-based board.)

I’ve had some success. I got compiled-in breakpoints working a while ago, and reading memory and registers. Just a moment ago, I actually got single-stepping to work. From there, settable breakpoints are only a small step.

I still have to support writing memory and registers, and complete the support for breakpoints. I also need to optimize the rather sloppy, inefficient code. Right now it takes up a fairly sizable chunk of the program memory. I also have ideas how I might shrink the Arduino stub down really, really small, by putting another PC-based layer between GDB and the Arduino stub.

Running with breakpoints enabled will, unfortunately, slow the system down considerably. This is because there is no (easy) way to stuff a breakpoint instruction into the AVR’s flash program memory. So, breakpoints are actually implemented by continuously single-stepping until you hit one.

And single-stepping itself is not free. The AVR has no internal mechanism for single-stepping. It’s implemented by forcing a hardware interrupt on one of the IO ports. Fortunately, it will let you choose which IO port to use, to hopefully avoid a conflict with your system’s requirements. Currently Analog Comparator (Port D:6,7), External Interrupt 0 (Port D:2) and External Interrupt 1 (Port D:3) can be used for single-stepping.