17

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
            }
        ]
    }
]
}
Inex
  • 502
  • 1
  • 4
  • 11

1 Answers1

19

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

Inex
  • 502
  • 1
  • 4
  • 11