I have problem ,I have Make project(multiple c++ files ) written on C++ . I am trying using VScode debugger to debug it but it just freezes and dats all, How to fix debugger what parameters in VSCodes json I must change e.t.c?
Projects folder config:
Makefile
exe
src (folder where all o and cpp h files are/will be stored)
IN SRC FOLDER :
main.cpp
WGForeCast.h
WGForeCast.cpp
etc
my task.json
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "echo",
"type": "shell",
"command": "make",
"args":["${workspaceFolder}/Makefile"]
}
]
}
my launch
{
// 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": "${workspaceFolder}/Pusk",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
In Visual Studio, as with most IDEs, there are two phases to making code work: building the code to catch and resolve project and compiler errors, and running the code to find run-time and dynamic errors.
It seems you built release version of your program. Try to build debug version of your program. rm -r build cd build cmake -DCMAKE_BUILD_TYPE=Debug .. cmake --build . It is better to separate debug and release builds.
Visual Studio provides a powerful integrated set of project build and debugging tools. In this article, find out how Visual Studio can help you find problems in your code using build output, code analysis, debugging tools, and unit tests. You've figured out the editor and created some code. Now, you want to make sure the code works properly.
The easiest way to build your project is to press F7, but you can also start the build by selecting Build > Build Solution from the main menu. You can observe the build process in the Output window at the bottom of the Visual Studio UI. Errors, warnings, and build operations are displayed here.
Well I found the solution :
First
In Makefile you need add option -g flag to compiler to use, “ -g ”: Generates debugging information that is used by gdb-baseddebuggers
Adding a flag example
CC=g++ -g -Wall
Just in case rebuild your project with the added flag before continue;
Second you need to change task.json in your project
To create a launch.json file, open your project folder in VS Code (File > Open Folder) and then select the Configure gear icon on the Debug view top bar. Chose gdb(for LInux) then launch.json will be generated but you need to change it like so:
{
// 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": "Pusk", //I named it Pusk because i can
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/Pusk", //path to your programs exe and exe name
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
Third we must configure task.json(basically its kinda script to launch your programm using Makefile instead the default compiler).
To create task.json
1)Open a folder with vscode
2)Hit F1
3)Select "Tasks: Configure Task Runner"
4)Hit Enter and vscode will create a sample task.json for you
Change task.json like so(probably do not need so complicated one but ¯(ツ)/¯ )
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "Build",
"type": "shell",
"command": "make", //its like writing in console make //btw you can others commands like clean make build etc
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": {
"owner": "cpp",
"fileLocation": ["relative", "${workspaceFolder}"],
"pattern": {
"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
}
}
]
}
Rebuild your project by pressing Ctrl+Shift+B(its like make in console now, because we changed task.json)
DATS ALL!! YOU CAN NOW USE DEBUGER!!!
Source->see "debug in vs code" article
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With