经过远程连接之后,写下main.cpp进行调试
//main.cpp
#include<iostream>
using namespace std;
int main()
{
cout<<"hello world"<<endl;
return 0;
}
//launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "C/C++ Runner: Debug Session",
"type": "cppdbg",
"request": "launch",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}", // gdb程序的工作目录
"environment": [],
"program": "${workspaceFolder}/main",,
"internalConsoleOptions": "openOnSessionStart",
"MIMode": "gdb",
"miDebuggerPath": "/usr/bin/gdb",
"externalConsole": false,
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
//tasks.json
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "gnss-sdr-lizw0.0.01",
"command": "g++",
"args": [
"-g",
"main.cpp",
"-o",
"main"
]
//"group": "build"
}
]
}
如果按F5 出现 ”launch: program ’ ’ does not exist “这个问题 ,首先看launch.json 里面的 “cwd” , “program” 和 tasks.json里的”args“能否对上,这在其他博主的blog里已经讲了,,那么如果还没解决就需要在launch.json 里加入
“preLaunchTask”: “gnss-sdr-lizw0.0.01” // 该项的值对应任务文件中的label的值,表示在执行debug前先执行编译任务
"gnss-sdr-lizw0.0.01"和tasks.json里的"label"名字相同。
之后的launch.json文件是这样的:
//launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "C/C++ Runner: Debug Session",
"type": "cppdbg",
"request": "launch",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}", // gdb程序的工作目录
"environment": [],
"program": "${workspaceFolder}/main",,
"internalConsoleOptions": "openOnSessionStart",
"MIMode": "gdb",
"miDebuggerPath": "/usr/bin/gdb",
"externalConsole": false,
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "gnss-sdr-lizw0.0.01" // 该项的值对应任务文件中的label的值,表示在执行debug前先执行编译任务
}
]
}
原理很简单,先编译成可执行文件,才能用gdb调试,这一行就是告诉编译器,先编译再调试。
好了,加上这一行之后非常顺利的解决了!!可以调试了!!
另外还有个问题一直没解决,我把launch.json里的"externalConsole": false,改为"externalConsole": true,之后为什么还是不能显示外部终端那个黑框呢,难道是远程连接的模式就是不能显示嘛?目前只能用字符终端看啦,不过也好凑合是能调试了!!
参考: vscode远程调试