Videos
I have tried many times. On multiple computers and projects, both at home and at work.
Results vary. At work it would just freeze at the startup, the debugging buttons would appear but nothing would actually start. At home, my first try did sort of work, but when breaking in code, only primitive types would show their content, everything else would render as "{}" when hovered.
Now, I just get this:
ERROR: Unable to start debugging. Unexpected GDB output from command "-exec-run". During startup program exited with code 0xc0000135. The program '\build\DisplayTest.exe' has exited with code 0 (0x00000000).
Now VS Code docs are pretty adamant that debugging in VS Code is a breeze. So I am curious, am I just stupid and incompetent? Is everyone else having zero trouble? Or are VS Code docs maybe overstating the IDE capabilities a little bit?
I normally just use Visual Studio. But for my current project it would be fairly impractical.
If you are using WSL to compile the project you should not use MinGW gdb. You need to install gdb on you Linux subsystem (using native tools like apt if you are using Ubuntu WSL), reopen your project in WSL and configure the WSL path to gdb. I was able to successfully debug using this setup on WSL.
Replace your launch.json file with this file
{
"version": "0.2.0",
"configurations": [
{
"args": ["1"],
"name": "gcc.exe - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: gcc.exe build active file"
}
]
}
Make Sure you have installed MinGw Compiler and gdb debugger
Adding this entry to launch.json worked for me
"preAttachCommands": [
"set substitute-path /path/during/build /path/for/debuging",
],
From https://github.com/Marus/cortex-debug/issues/611#issuecomment-1076250854
In your case, that would be
"version": "0.2.0",
"configurations":
[
{
"type": "gdb",
"request": "attach",
"name": "gdbserver",
"gdbpath": "/usr/bin/gdb",
"program": "/app/bin/exe",
"target": "target_ip:port",
"remote": true,
"cwd": "/",
"preAttachCommands": [
"set substitute-path /path/during/build /path/for/debuging",
],
}
]
After revisiting this issue recently, I was able to achieve what I wanted using autorun in my launch settings. I use preLaunchTasks to launch my docker image with my binaries/libraries, and then autorun handles the command gdb that needs to run on start-up.
"configurations":
[
{
"type": "gdb",
"request": "attach",
"name": "gdbserver",
"gdbpath": "/usr/bin/gdb",
"miDebuggerArgs": "-ex \"set substitute-path /workspace /other/dir",
"program": "/app/bin/exe",
"target": "target_ip:port",
"remote": true,
"preLaunchTask": "Task in .task"
"cwd": "/"
"autorun": [
"set substitute-path /workspace ${workspaceFolder}"
]
}
]
}