46

I recently started working on vscode. I wanted to debug my C code. But the moment I am launching the debugger getting Error : Unable to start debugging. The value of miDebuggerPath is invalid.

I have my gdb installed on wsl . It's path is /usr/bin/gdb. I have copied same path to launch.json in miDebuggerPath.

Here is my launch.json :

{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [


    {
        "name": "(gdb) Launch",
        "type": "cppdbg",
        "request": "launch",
        "program": "${workspaceFolder}/bin/main",
        "args": [],
        "stopAtEntry": false,
        "cwd": "${workspaceFolder}",
        "environment": [],
        "externalConsole": true,
        "MIMode": "gdb",
        "miDebuggerPath": "/usr/bin/gdb",
        "setupCommands": [
            {
                "description": "Enable pretty-printing for gdb",
                "text": "-enable-pretty-printing",
                "ignoreFailures": true
            }
        ]
    }
]

}

It should not throw the error and I should able to launch my debugger.

Nidhi Khanna
  • 499
  • 1
  • 5
  • 5

7 Answers7

70

So this happened to me on WSL-Ubuntu. In my case gdb was broken because of unmet dependencies. Took a while to fix but once I reinstalled gdb properly in my WSL-Ubuntu, I finally got it working.

Installing gdb can be done on shell as

sudo apt-get install gdb

There can be multiple reasons why it could end up as broken, but once you fix gdb, vscode-debugging should be running. At the very least, you won't see that error popping.

AzuxirenLeadGuy
  • 2,470
  • 1
  • 16
  • 27
  • 6
    For Arch-based Linux users: `sudo pacman -S gdb` https://archlinux.org/packages/extra/x86_64/gdb/ – Ruslan Jan 20 '21 at 13:49
  • This answer worked for me. I had a new WSL installation, so before trying the suggested command, my gdb was in /usr/share/gdb and even when I put this path in my lauch.json, it still did not work. When I installed gdb as per the suggested command, everything worked as expected (and gdb was installed in /usr/bin/gdb) – Craftonix - AA Jun 16 '22 at 23:59
7

I had the same problem, my solution was:

1. Change this section in launch.json

"miDebuggerPath": "/usr/bin/gdb",

for:

"miDebuggerPath": "C:/MinGW/bin/gdb.exe",

2. Do you need to install in your PC MinGW, this is the link:

https://osdn.net/projects/mingw/downloads/68260/mingw-get-setup.exe/

3. Next, open the MinGW then you install in the URL "C:/MinGW/bin" the gdb (select)

mingw32-gdb-bin

4. Enjoy the vs-code

uribealdo
  • 89
  • 1
  • 5
4

it should be

"miDebuggerPath": "/usr/bin/gdbus",
Dharman
  • 30,962
  • 25
  • 85
  • 135
bikpo
  • 49
  • 2
3

If you're running under WSL, you should check where gdb is in your current distro to set your "miDebuggerPath" using

whereis gdb

in my case it was in

/usr/bin/gdb

but it could be somewhere else, that depends on what Linux distribution are you using with WSL

Eugenio Miró
  • 2,398
  • 2
  • 28
  • 38
1

I had the similar problem, running on linux. Installing gdb fixed it.

Akshar
  • 78
  • 7
0

Could you try this:

sudo apt install binfmt-support

I am using VcXsrv, and this fixed all my installation problems, including chrome and GNU C++.

Pierre.Vriens
  • 2,117
  • 75
  • 29
  • 42
0

i had a similar problem ,this fixed. WINDOWS 10

QUICK ANSWER : try 1)C:\your compiler\bin\gdb.exe (paste your compiler path ) or 2)C:\TDM-GCC-32\bin\gdb32.exe for 32 bit compiler .(in my case)

(i tried to use opengl GLFW glad with 32bit tdm-gcc c++ compiler , i used a repo from OpenGL C++ template by vkphillia

but when i tried to run it in vs code using "run without debugging " option ,it showed the error "Unable to start debugging : The value of miDebuggerPath is invalid",

i copied my tdm_gcc compiler's bin path in midebugger path and it was like this , C:\TDM-GCC-32\bin\gdb.exe , but it did not remove the error then i checked for the gdb.exe application in my tdm gcc compiler bin where i noticed that there was no gdb.exe but a gdb32.exe file

DR 2020
  • 11
  • 4