本文介绍了如何“解决"问题VScode中的调试器,如果您在C ++上有Makefile项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有问题,我有用C ++编写的Make project(多个c ++文件).我正在尝试使用VScode调试器对其进行调试,但它只会冻结并全部删除,如何修复调试器VSCodes json中的哪些参数我必须更改e.t.c?
项目文件夹配置:

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(存储/将存储所有o和cpp h文件的文件夹)
在SRC文件夹中:
main.cpp
WGForeCast.h
WGForeCast.cpp等等

src (folder where all o and cpp h files are/will be stored)
IN SRC FOLDER :
main.cpp
WGForeCast.h
WGForeCast.cpp etc

我的task.json

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"]
    }
]
}

我的发射

{
// 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
            }
        ]
    }
]
}

推荐答案

好,我找到了解决方案:
第一
在Makefile中,需要向编译器添加选项-g标志才能使用," -g ":生成基于gdb的调试器使用的调试信息.添加标志示例

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-baseddebuggersAdding a flag example

CC=g++ -g -Wall 

以防万一,在继续之前用添加的标记重建项目;

Just in case rebuild your project with the added flag before continue;

第二,您需要在项目中更改 task.json
要创建launch.json文件,请在VS Code中打开项目文件夹( 文件>打开文件夹 ),然后在调试"视图顶部栏上选择配置齿轮"图标.选择 gdb (对于LInux),然后将生成 launch.json ,但您需要像这样进行更改:

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
                }
            ]
        }
    ]
}

第三,我们必须配置 task.json (基本上是一种脚本,可以使用Makefile而不是默认的编译器来启动您的程序).
要创建task.json

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

像这样更改 task.json (可能不需要那么复杂的一个,但¯(ツ)/¯)

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
          }
        }
      }
    ]
  }

通过按 Ctrl + Shift + B 重建项目(类似于现在在控制台中进行make,因为我们更改了task.json) 所有日期!您现在可以使用调试器!!!
来源-> 请参阅在vs代码中进行调试文章

这篇关于如何“解决"问题VScode中的调试器,如果您在C ++上有Makefile项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-24 12:11