GDBStub Debugging With Serial

Introduction: GDBStub Debugging With Serial

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…

Using GDB Stub to debug is very useful, but losing the Serial output can make things difficult from the coding and understanding perspective.

Luckily we can implement the Software Serial Library to replace the Hardware Serial port we lose when using GDBStub, and with a few code changes, we can swap between them easily.


Visual Micro

Arduino Uno

FTDI TTL Serial Adapter

3 x Jumper Wires

Step 1: Setting Up GDB Stub

If you haven't already setup GDBStub for your code, visit our Instructable about setting up GDBStub for first use.

Once you have the library, headers and relevant init() / breakpoint() function calls to your code, you can continue with this Instructable.

Step 2: Updating Serial Code

The easiest way to achieve this is to:

  1. Include the Software Serial Library from vMicro > Add Library > Current Platform
  2. Add a #define for the Serial Object in use e.g. USE_SERIAL
  3. Change all references from Serial to USE_SERIAL
  4. Add the SoftwareSerial object with the Rx/Tx pins you wish to use

That's all that's needed, and you can switch back to Serial by changing the USE_SERIAL define now.

Step 3: Connect Additional Hardware

Now we will need to connect our USB TTL Serial adapter to the Uno, using the pins we defined in the previous step.

More information about Software Serial can be found here.

Step 4: Using Both Serial Ports in Visual Micro

As we now have our Uno on one port for debugging via Serial, and our own Software Serial interface on another COM port, we need to view both when debugging.

Open vMicro > General > Monitor Alternative, and select the USB Port for your TTL Serial Device, a new Serial Monitor Window should appear connected to this port, without changing your upload port.

Step 5: Try It Out

Ensure the correct Uno COM port is set for upload and press Start Debugging / Attach to process depending on whether the code is uploaded.

NOTE - you may need to re-open the alternative serial monitor again after debugging begins the first time. After this it will be remembered as part of your Visual Studio Window Layout.

Step 6: Learn More

Be the First to Share


    • Sculpt & Carve Challenge

      Sculpt & Carve Challenge
    • Fabric Challenge

      Fabric Challenge
    • Remote Control Contest

      Remote Control Contest