Arduino Uno GDB Debugging

Introduction: Arduino Uno GDB Debugging

About: News November 2019. Welcome to the place where we have started to build useful examples. Arduino for Visual Studio provides an Arduino compatible development environment in Microsoft Visual Studio. The tools p…

Sometimes you want to use the advantages of GDB Hardware debugging, but your hardware simply doesn't support it, which is the case with the Arduino Uno, and others like the ESP8266.

There are GDBStub libraries which can give you most of the capability of the hardware debugger, via the Serial interface.

For the Uno we can use the "avr-debugger by Jan Dolinay" for example.

Visual Micro can use these out of the box, as well as its own Advanced Serial Debugger and Hardware debugging features.

Supplies:

Visual Micro

Arduino Uno & USB Lead

Step 1: Setup Visual Micro

First ensure you have the project loaded you want to debug

Set the correct Board and COM port

Change the Debugger > Debug option to "Hardware"

Change the Debugger > Hardware debugger option to "GDB Stub"

Finally change the Optimisation setting to the recommended "No Project + Libraries Optimization"

Step 2: Installing the GDB Stub Library

To Install the GDBStub Code

  • vMicro > Add Library > Download and Install Arduino Library > Manage Libraries Tab
  • Enter "gdb" as the Search term
  • For the Uno we can use the "avr-debugger by Jan Dolinay"
  • Left click to install the library (see more about libraries here)
  • Click the Rescan button at the top when the install has completed
  • Now close the Visual Micro Explorer

Step 3: Adding the Code

To include the GDB stub we will need to add a few lines of code:

Include the avr8-stub.h

Add debug_init() to your setup() routine

Add breakpoint() to the top of loop()

Step 4: Add a Breakpoint

Add a break point to your sketch by clicking in the left hand margin.

You can add more than one, and up to 4

Step 5: Debugging

To start the debugging process, you can either:

  • "Debug > Attach to Process" button if your code has already been uploaded to the board
  • "Debug > Start Debugging" if your code has not been uploaded

Now you can debug in Visual Micro as normal on your Arduino Uno, without an external hardware debugger.


This can work with other GDB stub implementations for other boards, and advanced customisation of the IDE may be needed.

A GDBStub implementation for the ESP8266 has also been linked in Visual Micro, which can be seen here.

If you want to use your own Serial Code as well as GDBStub, see the follow up Instructable here

Step 6: Find Out More

Be the First to Share

    Recommendations

    • Clocks Speed Challenge

      Clocks Speed Challenge
    • Toys & Games Contest

      Toys & Games Contest
    • Big vs Small Challenge

      Big vs Small Challenge

    Comments