vscode环境配置(二)——C Program Debug

2023-02-14,,,,

一、任务准备

  launch.json

{
"version": "0.2.0",
"configurations": [
{
"name": "C/C++",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}.exe", //创建可执行文件
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "C:/Program Files (x86)/mingw-w64/i686-8.1.0-posix-dwarf-rt_v6-rev0/mingw32/bin/gdb.exe", //本机gdb安装位置
"preLaunchTask": "g++",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
},
]
}

  tasks.json

{
"version": "2.0.0",
"command": "g++",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}.exe"
],
"problemMatcher": {
"owner": "cpp",
"fileLocation": [
"relative",
"${workspaceRoot}"
],
"pattern": {
"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
"file": ,
"line": ,
"column": ,
"severity": ,
"message":
}
},
"group": {
"kind": "build",
"isDefault": true
}
}

二、配置步骤

  方法一:在程序主目录下新建.vscode文件夹,在此文件夹下新建任务准备中的launch.json和tasks.json文件,修改launch.json中gdb位置即可。

  方法二:点击vscode最左边任务栏中的Debug瓢虫按钮或按Ctrl+Shift+D,在跳出的选项框中,进行如下操作      

  

  

  查看生成的launch.json文件看gdb.exe文件是否需要修改。然后进行下一步创建task.json操作,操作如下

  如果没有C/C++:gcc.exe build active file选项,就选择Create task.json file from template选项,出现如下页面

  生成task.json文件后回到C文件页面再次点击Debug按钮,操作如下

  查看是否生成task.json文件。  

  设置断点后再次点击Debug按钮或英文状态时按Ctrl+Shift+B运行。

vscode环境配置(二)——C Program Debug的相关教程结束。

《vscode环境配置(二)——C Program Debug.doc》

下载本文的Word格式文档,以方便收藏与打印。