1. vscode 配置环境
- 点击运行生成task.json
- 根据需求,修改-g 待编译文件参数以及-o 输出exe文件的位置(注意c++使用g++进行编译,c语言用gcc编译)
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++.exe 生成活动文件",
"command": "E:\\Program Files (x86)\\mingw64\\bin\\g++.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"*.cpp",
"-o",
"${fileDirname}\\code.exe"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "调试器生成的任务。"
}
],
"version": "2.0.0"
}
2. vscode 调试程序
- 点击运行和调式,生成launch.json 文件
- 修改debuggerpath,为本机的gdb.exe路径,
- 如果在task.json中修改了编译之后的文件名,需要修改program。
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Windows 上的 Bash 启动",
"type": "cppdbg",
"request": "launch",
"program": " ${workspaceFolder}/code.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"pipeTransport": {
"debuggerPath": "E:\\Program Files (x86)\\mingw64\\bin\\gdb.exe",
"pipeProgram": "${env:windir}\\system32\\bash.exe",
"pipeArgs": ["-c"],
"pipeCwd": ""
},
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "将反汇编风格设置为 Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
]
}
]
}