'GDB can't debug running process using VS Code but can through command line
I am trying to debug a C++ application on Windows that has been started by a python script. I am able to attach to the process using GDB from command line and everything works fine.
However, when trying to use VS Code to attach GDB, it manages attach, but all the breakpoints are stuck on Attempting to bind to the breakpoint... and trying to execute a command in the debug console returns Unable to perform this action because the process is running..
This is my launch.json configuration:
{
"name": "(gdb) Attach",
"type": "cppdbg",
"request": "attach",
"program": "${workspaceFolder}\\build\\program.exe",
"processId": "${command:pickProcess}",
"MIMode": "gdb",
"miDebuggerPath": "C:\\Program Files (x86)\\mingw-w64\\i686-8.1.0-posix-dwarf-rt_v6-rev0\\mingw32\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
I assume that VS code is doing something extra/weird when starting GDB, is there a way to fix this?
Solution 1:[1]
I know this is an old question but I was facing the same issue which landed me here.
For me the culprit was in the "miDebuggerPath" in launch.json
Even though the path looked right when I checked it countless times, it was not the same one invoked from the command line (I am working on a Linux machine in an environment with lots of gdb versions installed)
Try to find the gdb path invoked from the command line and add that to the above mentioned parameter in debug configuration file.
Solution 2:[2]
GDB on MinGW has some limitations:
GDB on Cygwin and MinGW cannot break a running process. To set a breakpoint when the application is running (not stopped under the debugger), or to pause the application being debugged, press Ctrl-C in the application's terminal.
Make sure to stop the application with Ctrl-C before setting breakpoints in VS Code. See also a relevant issue: https://github.com/Microsoft/vscode-cpptools/issues/595.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Dharman |
| Solution 2 | ks1322 |
