'Trouble debugging - VSCode - configuring JSON - Program path is missing or invalid
I am having trouble getting the F5 debugger to work properly.
I have been trying to follow the Microsoft tutorial to get things going, but after building successfully the debugging process never really works out the way it should.
When I use the Ctrl + Shift + B command to build, it successfully creates a main.exe file, but I cannot change the launch.json file in a way that works hand-in-hand.
While tasks.json has this
"-o","${fileDirname}\\${fileBasenameNoExtension}.exe" as the object path/name, 'main.cpp' is compiled into main.exe.
So, initially, I had tried to set launch.json to have program": ${fileDirname}\\${fileBasenameNoExtension}.exe. Which would be neat and effective, matching the build file that would be produced.
Next, I tried to change launch.json to run as a.exe hardcoded. In the PS terminal within VSCode, I ran g++ .\main.cpp and produced an a.exe file. Which successfully allows F5 debugging giving me an exit code '0' in the debug console when I changed launch.json to have "program": "${workspaceFolder}\\a.exe".
I have also tried to use ${workspaceFolder}\\${fileBasenameNoExtension}.exe with no luck.
It makes no logical sense to me that the same parameters for cwd with the same object name in tasks won't run successfully for debugging in launch.
The entire tasks.json:
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: cpp.exe build active file",
"command": "C:\\msys64\\mingw64\\bin\\cpp.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "compiler: C:\\msys64\\mingw64\\bin\\cpp.exe"
}
]
}
The entire launch.json:
{
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}\\a.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:\\msys64\\mingw64\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "Set Disassembly Flavor to Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
]
}
]
}
Could someone please take a look for me? This is infuriating.. Thanks in advance!
Solution 1:[1]
I figured out the problem. Hopefully will help someone else, too.
First I updated the architecture portion of the options for launch.json - not relevant to the file-path issue, but figured I would mention. Add "targetArchitecture": "x64"(or the 32bit option if necessary) to the tasks.json file.
==================================================================
Solution: After fiddling around a bit I have found that tasks.json was the issue, not launch.json. After a good amount of confusion I took a break and came back to the problem and noticed that tasks was running cpp.exe to build the file. Out of curiosity I replaced it with g++.exe and voilĂ - it works.
So, if you have issues with using F5 in VSCode with MinGW for compiling/debugging - ensure that g++.exe is compiling. At least from my limited knowledge, that should fix the issue if you are running VSCode and using MinGW for building/debugging.
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 | Whiskey Face |

