I am trying to set up VSCODE to debug a C program on Windows using Cygwin64.
I used the config suggested by @stephw (
I changed my launch.json
just a little bit. Notice the "preLaunchTask" key does not have the exact same value that the "label" key in the tasks.json
has:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "gcc.exe build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [
{
"name": "PATH",
"value": "%PATH%;C:\\cygwin64\\bin"
}
],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:\\cygwin64\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"logging": { "engineLogging": true }, //optional
"preLaunchTask": "gcc.exe build active file"
}
]
}
My tasks.json
is this (notice my name in the end, in the "detail" key):
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "C/C : gcc.exe build active file",
"command": "C:\\cygwin64\\bin\\gcc.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": "build",
"detail": "Task generated by Leonardo."
}
]
}
I notice something a little bit strange: When I press F5, it does not work, because the task created is not found.
When I edited my launch.json
file (preLaunchTask key) to the exact same value in the tasks.json
file, the "not found" error disappears, but the debugging process does not start.
"preLaunchTask": "C/C : gcc.exe build active file"
If I press the Run and debug play button, the debug process does not work either.
When I use the Command Palette (pressing CTRL SHIFT P), and click C/C : Build and Debug Active File
,
and then choose the task I created (the second one appears to be automatic),
the program is compiled and the debug process is started.
This is my very simple test script:
#include <stdio.h>
#include <stdlib.h>
int main() {
/* declare and initialize string */
char myString[] = "This is an example of string declaration!";
/* print string */
printf("%s", myString);
int numberA = 5;
int numberB = 10;
int sum = numberA numberB;
/* Printing a number */
printf("A soma de numberA numberB é: %d", sum);
return 0;
}
I hope this question and answer can help someone in the future. Peace.