Failed to launch GDB: .pioinit13: Error in sourced command file: :3333: he system has attempted to mount a drive to a directory that is already mounted

I’m encountering an issue with debugging my Arduino Uno R3 using PlatformIO in VS Code. I’m using the basic “Blink” sketch, which works perfectly fine in Arduino IDE. However, when I try to run the same code in VS Code with PlatformIO, it uploads successfully, and the PIO Device Monitor also works as expected.

The problem arises a few seconds later, when I get an error message stating:

“Failed to launch GDB: .pioinit:13: Error in sourced command file: :3333: The system has attempted to mount a drive to a directory that is already mounted.”

Steps I’ve tried so far:

  1. Reinstalling PlatformIO completely.
  2. Modifying the platformio.ini file in various ways.
  3. Modifying the launch.json file to adjust debugger settings.
  4. Checking for duplicate debugger instances via the command window, but there were none.
  5. Verifying if another process is using the same port, but nothing seems to be conflicting.
  6. Suspecting it was a permissions issue, I ran VS Code (actually Cursor) as an administrator to see if that helped.
  7. Disabled my antivirus in case it was interfering with the debugging process.

Since Arduino IDE does not have a debugger, I suspect that the issue is specific to PlatformIO’s debugging setup. The program works fine until the debugger is launched, which suggests that the debugger is trying to attach to a resource that is already in use.

I’m not sure what else to try at this point. Could this be a bug, or is there a specific configuration I need to change? Any guidance would be greatly appreciated.

This is the whole message

Processing uno (platform: atmelavr; board: uno; framework: arduino)
--------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/atmelavr/uno.html
PLATFORM: Atmel AVR (5.1.0) > Arduino Uno
HARDWARE: ATMEGA328P 16MHz, 2KB RAM, 31.50KB Flash
DEBUG: Current (avr-stub) External (avr-stub, simavr)
PACKAGES:
 - framework-arduino-avr @ 5.2.0
 - tool-avrdude @ 1.60300.200527 (6.3.0)
 - toolchain-atmelavr @ 1.70300.191015 (7.3.0)

LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 7 compatible libraries
Scanning dependencies...
Dependency Graph
|-- Servo @ 1.2.2
|-- SmartRobotCarKitV4 @ 1.0.0
Building in debug mode
Checking size .pio\build\uno\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [          ]   0.4% (used 9 bytes from 2048 bytes)
Flash: [=         ]   5.9% (used 1896 bytes from 32256 bytes)
Configuring upload protocol...
AVAILABLE: arduino
CURRENT: upload_protocol = arduino
Looking for upload port...
Auto-detected: COM19
Uploading .pio\build\uno\firmware.hex

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s

avrdude: Device signature = 0x1e950f (probably m328p)
avrdude: reading input file ".pio\build\uno\firmware.hex"
avrdude: writing flash (1896 bytes):

Writing | ################################################## | 100% 0.30s

avrdude: 1896 bytes of flash written
avrdude: verifying flash memory against .pio\build\uno\firmware.hex:
avrdude: load data flash data from input file .pio\build\uno\firmware.hex:
avrdude: input file .pio\build\uno\firmware.hex contains 1896 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 0.24s

avrdude: verifying ...
avrdude: 1896 bytes of flash verified

avrdude done.  Thank you.

========================= [SUCCESS] Took 5.83 seconds =========================
Reading symbols from C:\Users\34697\Documents\PlatformIO\Projects\Smaert\.pio\build\uno\firmware.elf...
done.
PlatformIO Unified Debugger -> https://bit.ly/pio-debug
PlatformIO: debug_tool = avr-stub
PlatformIO: Initializing remote target...
.pioinit:13: Error in sourced command file:
:3333: El sistema ha intentado unir una unidad a un directorio de una unidad ya unida.

Do you only want to upload the program to the board and start the serial monitor or actually start a debugger?

Note that, if you actualyl want to debug the sketch inside the debugger, with the debug_tool = avr-stub, then you specifically have to add a library, initialization code and remove any usages of Serial (since the debugger now takes over your Serial). This is documented.

Otherwise, make sure that you don’t click on the “Play” button but just use the project task for “Upload” or “Upload and Monitor”, as documented.

1 Like

I found the cause of the problem: I didn’t have the required library installed. After installing it, debugging works correctly using the simavr simulator. Thanks, everyone, for your help! :+1: