由于手上有一台强大的Linux工作站,尽管在Windows下使用Visul Studio写C++十分舒服,但是考虑到以后很多工作都是在Linux下完成,所以需要配置C++的远程调试环境。 使用Remote SSH插件连接远程工作站,在项目目录下的.vscode 里配置task.json 和launch.json 如下:
task.json
看起来很长,实际上在Linux下面只写label 为g++ build active file 的配置就可以,其他是为了方便兼容Windows的cl编译任务
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: cl.exe 生成活动文件",
"command": "cl.exe",
"args": [
"/Zi",
"/EHsc",
"/nologo",
"/Fe:",
"${fileDirname}\\Bin\\${fileBasenameNoExtension}.exe",
"${file}"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$msCompile"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "调试器生成的任务。"
},
{
"label": "clean win32",
"type": "shell",
"command": "./.vscode/remove.bat",
"options": {
"cwd": "${fileDirname}"
},
"dependsOn": ["C/C++: cl.exe 生成活动文件"]
},
{
"type": "shell",
"label": "g++ build active file",
"command": "g++",
"args": [
"-g",
"-O0",
"${file}",
"-D_GLIBCXX_DEBUG",
"-o",
"${fileDirname}/Bin/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": ["$gcc"],
"group": {
"kind": "build",
"isDefault": true
}
}
],
"version": "2.0.0"
}
launch.json
同样的配置了两个调试启动器,可以在调试界面选择使用哪个启动器,Linux下用G++,Windows用cl.exe
{
"version": "0.2.0",
"configurations": [
{
"name": "cl.exe - 生成和调试活动文件",
"type": "cppvsdbg",
"request": "launch",
"program": "${fileDirname}\\Bin\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"console": "externalTerminal",
"preLaunchTask": "clean win32"
},
{
"name": "g++ Launch",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/Bin/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "g++ build active file",
"miDebuggerPath": "/usr/bin/gdb"
"miDebuggerArgs": "-q -ex quit; wait() { fg >/dev/null; }; /usr/bin/gdb -q --interpreter=mi"
}
]
}
配置完成后按F5 即可断点调试
|