Vscode remote 调试 go
Remote ssh
安装:
左侧列表 extension 搜 remote ssh 安装
配置:
-
左侧列表 远程资源管理器
-
选择设置
-
选择第一个配置
-
编辑配置保存,写入 name,ip,user,port,密钥
Host kata
HostName 172.18.22.233
User root
Port 22
IdentityFile C:\Users\xu.junjie_99cloudnet.ssh\id_rsa -
保存后右键指定 配置选择 new window 或 current window
-
选择资源管理器,打开远程文件夹,然后输入路径
调试 kata-containers
Git 后,通过打开远程文件夹打开
- 如果要支持 远程调试,需要安装 extension -> go
- 然后直接在代码打断点
- 编译,可以通过 终端 -> 新建终端 登录到远程终端
- 开启调试,需要在 makefile 中加 -gcflags “all=-N -l” src/runtime/Makefile
- Make or build
- 在 vscode 设置 launch
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Connect to server",
"type": "go",
"request": "attach",
"mode": "remote",
// "remotePath": "${workspaceFolder}",
"debugAdapter": "dlv-dap",
"port": 50002,
"host": "127.0.0.1"
}
]
}
- 运行代码
- ps 查进程号
- dlv --log --wd pwd --check-go-version=false --headless -l 127.0.0.1:50002 --api-version 2 --accept-multiclient attach $pwd
- Vscode connect to server