1. 应用场景
2. 需要安装 "remote-ssh", "c/c++" 和"native debug"
2.1 安装 remote-ssh
2.2 安装 c/c++
2.3 安装 native debug
3. 在inux 服务器上创建测试程序
#include <unistd.h>
#include <pwd.h>
#include <iostream>
int main()
{
struct passwd* pwd;
uid_t userid;
userid = getuid();
pwd = getpwuid(userid);
std::cout << "pw_name:" << pwd->pw_name << std::endl;
std::cout << "pw_passwd:" << pwd->pw_passwd << std::endl;
std::cout << "pw_uid:" << pwd->pw_uid << std::endl;
std::cout << "pw_gid:" << pwd->pw_gid << std::endl;
std::cout << "pw_gecos:" << pwd->pw_gecos << std::endl;
std::cout << "pw_dir:" << pwd->pw_dir << std::endl;
std::cout << "pw_shell:" << pwd->pw_shell << std::endl;
return 0;
}
使用对应arm板子的交叉编译工具链对代码进行编译,参数可以参考以下:
user@ubuntu:~/vscode_gdb$ pwd
/home/user/vscode_gdb
user@ubuntu:~/vscode_gdb$ g++ -g main.cpp -o arm_test
4. 通过 remote-ssh 连接 linux 服务器
4.1 增加ssh主机: ssh linuxuser@10.22.67.53
4.2 选择 ssh 配置文件
4.3 连接
4.4 选择目标PC, 使用当前窗口打开主机
4.5 输入密码
4.6 已登陆linux主机
4.7 打开测试代码目录
4.8 再次输入密码
4.9 可以查看linux服务器上的测试代码
4.10 创建 lauch.json , 选择 GDB, 运行和调试
4.11 新的 lauch.json 如下
用下面的配置替换 lauch.json,其中arm-oe-linux-gnueabi-gdb 为运行在linux服务器上的对应于arm板子交叉工具链中的gdb客户端
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: Debugging in Visual Studio Code
"version": "0.2.0",
"configurations": [
{
"name": "Debug",
"type": "gdb",
"request": "attach",
"target": "127.0.0.1:9001",
"remote": true,
"gdbpath": "/opt/***/arm-oe-linux-gnueabi-gdb",
"cwd": "${workspaceRoot}",
"valuesFormatting": "parseText"
}
]
}
4.12 使用 gdbserver 运行 arm_test, 在嵌入式arm开发板上
# ./gdbserver :9001 arm_test
4.13 在 windows 上使用MobaXterm运行ssh服务器
4.14 linux服务器上运行 ssh客户端,连接windows上的ssh服务器
ssh -N -g -L 9001:192.168.225.1:9001 windowsuser@10.22.44.181
4.15 设置断点运行gdb调试,效果如下: