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}"
]
}
]
}
I'm starting to learn C and C++ and have installed the Visual Studio Code extension for C/C++. When I create a new project and run (without debugging) a C or C++ file for the first time, I see this message in the Visual Studio Code debug console:
=thread-group-added,id="i1" GNU gdb (GDB) 11.2 Copyright (C) 2022 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "x86\_64-w64-mingw32". Type "show configuration" for configuration details. For bug reporting instructions, please see: <https://www.gnu.org/software/gdb/bugs/>. Find the GDB manual and other documentation resources online at: <http://www.gnu.org/software/gdb/documentation/>.
The code runs fine and doesn't stop at breakpoints. My only question is why this message appears if I'm not debugging my code.
If you're going to suggest using another IDE or advise against spending time on this, please don't waste time doing so.