如果您在C++上有 Makefile 项目,如何在 VScode 中"fix"调试器?



我有问题,我有用c++编写的Make项目(多个c++文件(。我正在尝试使用VScode调试器来调试它,但它只是冻结和数据,如何修复调试器VScode.json中的哪些参数我必须更改e.t.c
项目文件夹配置:

Makefile

exe  

src(存储所有o和cpp h文件的文件夹(
IN src folder:
main.cpp
WGForeCast.h
WGForeCast.cppetc

我的任务.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-baseddebug使用的调试信息添加标志示例

CC=g++ -g -Wall 

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

其次,您需要更改项目中的task.json
要创建launch.json文件,请在VS Code中打开您的项目文件夹(文件>打开文件夹(,然后选择Debug视图顶栏上的Configure gear图标。选择gdb(对于LInux(,然后启动。将生成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": "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而不是默认编译器启动程序的脚本(
创建任务.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(可能不需要这么复杂,但(ツ)/

{
// 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(所有日期!!您现在可以使用调试器了
源->请参阅文章"调试与代码">

相关内容

  • 没有找到相关文章

最新更新