PlatformIO Community

VSCode, fails to debug

First of all, I am new to VSCode and PlatformIO.

I am trying to display the disassembled and assembly code of a tiny bit of Arduino code in VSCode, but everytime I run the debugger an error shows:

“Failed to launch GDB: .pioinit:13: Error in sourced command file: :3333: System tried to join a drive to a directory on a joined drive. (from interpreter-exec console “source .pioinit”)”

It tells me to open launch.json, which I do, but I cannot see anything in there causing the error:

{
    "version": "0.2.0",
    "configurations": [
        
        {
            "type": "platformio-debug",
            "request": "launch",
            "name": "PIO Debug",
            "executable": "c:/Users/username/Documents/PlatformIO/Projects/program1/.pio/build/uno/firmware.elf",
            "projectEnvName": "uno",
            "toolchainBinDir": "C:/Users/username/.platformio/packages/toolchain-atmelavr/bin",
            "internalConsoleOptions": "openOnSessionStart",
            "preLaunchTask": {
                "type": "PlatformIO",
                "task": "Pre-Debug"
            }
        },
        {
            "type": "platformio-debug",
            "request": "launch",
            "name": "PIO Debug (skip Pre-Debug)",
            "executable": "c:/Users/username/Documents/PlatformIO/Projects/program1/.pio/build/uno/firmware.elf",
            "projectEnvName": "uno",
            "toolchainBinDir": "C:/Users/username/.platformio/packages/toolchain-atmelavr/bin",
            "internalConsoleOptions": "openOnSessionStart"
        },
        {
            "type": "platformio-debug",
            "request": "launch",
            "name": "PIO Debug (without uploading)",
            "executable": "c:/Users/username/Documents/PlatformIO/Projects/program1/.pio/build/uno/firmware.elf",
            "projectEnvName": "uno",
            "toolchainBinDir": "C:/Users/username/.platformio/packages/toolchain-atmelavr/bin",
            "internalConsoleOptions": "openOnSessionStart",
            "loadMode": "manual"
        }
    ]
}

Update:

Updated the platformio.ini file:

[env:uno]
platform = atmelavr
board = uno
framework = arduino

debug_tool = avr-stub
debug_port = COM5

; GDB stub implementation
lib_deps =
    jdolinay/avr-debugger @ ~1.4

Now, while trying to debug the following error appears:

HardwareSerial0.cpp.o (symbol from plugin): In function `Serial':
(.text+0x0): multiple definition of `__vector_18'
avr8-stub.c.o (symbol from plugin):(.text+0x0): first defined here
collect2.exe: error: ld returned 1 exit status
*** [.pio\build\uno\firmware.elf] Error 1

I believe I have added everything I do need in the sketch:

#include <Arduino.h>
#include "avr8-stub.h"

uint8_t button = 8;
uint8_t redLed = 10;
uint8_t buttonWasPressed;

void setup() {
  debug_init();
  pinMode(button, INPUT);
  pinMode(redLed, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  while(1) {
    if(digitalRead(button) == LOW) {
      if(buttonWasPressed == 0) {
        digitalWrite(redLed, HIGH);
        buttonWasPressed = 1;
      }
    }
    else {
      digitalWrite(redLed, LOW);
      buttonWasPressed = 0;
    }
  }
}

Remove that line, Serial conflicts with avr8-stub which is using the serial to transport GDB messages.

2 Likes

Also the loop is already called in the Arduino main() function in a while-true loop, you don’t need that additionally there.

Thanks a lot, have been trying to get this to work for way too long!

Isn’t it always the simples things?