使用VScode运行调试C/C++( 二 )




4然后我们需要改写这两个json文件的内容 。
此中launch.json文件内容(此中的miDubuggerPath后的路径要改当作你的mingw编译器的安装路径):
{
"version": "0.2.0",
"configurations": [
{
"name": "Run C/C++",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/${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",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": false
}
],
"preLaunchTask": "build & run file"
},
{
"name": "Debug C/C++",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/${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",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": false
}
],
"preLaunchTask": "build & debug file"
}
]
}

使用VScode运行调试C/C++



5此中tasks.json文件内容(直接复制即可):
{
"version": "2.0.0",
"tasks": [
{
"label": "build & debug file",
"type": "shell",
"command": "g++",
"args": [
"-g",
"-o",
"${fileBasenameNoExtension}",
"${file}"
],
"group": {
"kind": "build",
"isDefault": true
}
},
{
"label": "build & run file",
"type": "shell",
"command": "g++",
"args": [
"-o",
"${fileBasenameNoExtension}",
"${file}"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}

使用VScode运行调试C/C++



6这是我们已经完当作了根基的设置装备摆设工作,保留以上两个json文件后,再次点击左侧的调试按钮(Debug),可以发现呈现了两个新的设置装备摆设,一个是直接运行程序的Run,一个是用来调试程序的Debug 。

使用VScode运行调试C/C++



7下面我们写一个简单的c++程序来进行调试申明,程序源代码如下图,我们在return 0这行添加了一个断点 。

猜你喜欢