I'm trying to run from a launch.json file, so i can use gdb to debug my program in vscode.
The launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "g build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "SourceFolder/test",
"args": [],
"stopAtEntry": false,
"cwd": "SourceFolder",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "g compile active file",
"miDebuggerPath": "/usr/bin/gdb"
}
]
}
The path is correct, i can see the compiled file right there in the folder. I can run the program via console (bash) no problem and it doesn't throw any errors, but when i run it via this method i get the following pop up:
Unable to start debugging. Program path 'SourceFolder/test' is missing or invalid.
GDB failed with message: SourceFolder/test: File or directory not found.
...
And the debug-terminal returns:
The program 'SourceFolder/test' has exited with code 42 (0x0000002a).
Could "preLaunchTask": "g compile active file" be causing this error?
CodePudding user response:
The preLaunchTask name must match the label
tag of the tasks.json
file built by default in .vscode. Check they match.
If this isn't enough, go on your source code file, press Ctrl Shift B
and see if the precompiler does everything fine. You should see something like this:
> Executing task: g build active file <
Starting build... /usr/bin/g -fdiagnostics-color=always -g "sourcefilename.extension" -o "sourcefilenameNoExtension" Build finished successfully.
Terminal will be reused by tasks, press any key to close it.
If this happens to be fine then you should have the file 'SourceFolder/test' ready to run. If this went wrong you may check your tasks.json
settings or simply change the filename to be test.extension
and put it in the SourceFolder
folder if you didn't yet.
If you meant the SourceFolder to be the default value for the actual opened folder then you should have write ${workspaceFolder}.
By the way you can find this and more in this guide by VSCode
https://code.visualstudio.com/docs/languages/cpp#_tutorials
Here you'll find links to use G on your operating system.