I'm trying to approaching to VS Code, I've Windows and Ubuntu on VM but i'd prefere a lot to debug on windows.
My teacher told us to use MinGW, and i'm using it for coding/compiling with no problem, i've already setted Win environment variables. I'm new to debugging world and maybe it's hard to start with VS Code, I don't know. I'm trying to follow lot of tutorial and i don't know if I'm doing it right. I must say that i'm using a Makefile instead of compiling in VS Code, i don't know if there is any difference. Here is my standard Makefile:
all: Prog.exe
Prog.exe: main.o
g++ main.o -o Prog.exe
main.o: main.cpp
g++ -c -g -Iinclude main.cpp
.PHONY: clean
clean:
rm -rf *.o *.exe
1) I only know that the parameter "-g" includes debug information, is that enough for the compiling process in order to debug?
2) I'm following VS Code tutorials to set launch.json file, and i think I'm doing it right:
launch.json:
{
// 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": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "I:/Documenti/.../Prove debug/Prog.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:/MinGW/bin/gdb.exe",
"setupCommands": [
{
"description": "Abilita la riformattazione per gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
I found that on VS Code site:
- tasks.json (build instructions)
- launch.json (debugger settings)
- c_cpp_properties.json (compiler path and IntelliSense settings)
3) So i only need launch.json? If i don't have any .json file it asks me to choose between different Configs:
Environment Config
4) it only seems to work the second one, but it skips breakpoints and it's useless... Can i usee "GDB" on windows? If i try to use GDB, after set all launch.json i get this error:
GDB error
5) I'd prefere to debug on windows with MinGW, is it possible?
EDIT: I solved, the problems were 2 big (a, b) and 1 small (c);
a. the "program"
directory;
b. the gdb/compiler directory;
c. the task.json file which is not needed if you compile with makefile (or manually with terminal).
a: i replaced "${fileDirname}\\${fileBasenameNoExtension}.exe"
with the full directory of my program;
b: I have 2 different directory of MinGW (so 2 directory of gdb):
- One which i manually installed (in C:);
- The other I installed inside Qt (inside F:);
when VS Code automatically generate "launch.json" it sets me "miDebuggerPath"
(gdb path) to the gdb installed with Qt (maybe for the order in Win10 environment paths) and I've always changed it to the other directory... Probably if I want to change directory I should set it in more files, and there was an error of 2 different gdb directory. I leaved the automatic directory (inside Qt, in F:);
c: I had an error of the task over the debug that was already working, so I realized that there were two different activities. I solved deleting the entire line "preLaunchTask": "g++.exe build active file"
and deleting "task.json"
file.