Abel'Blog

我干了什么?究竟拿了时间换了什么?

0%

go-debug

在Linux里面使用gdb/delve工具来调试程序。

安装

Linux

1
go get github.com/go-delve/delve/cmd/dlv

vscode中的-workspace中配置一份调试选项:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
"configurations": [
{
"name": "Attach to Process",
"type": "go",
"request": "attach",
"mode": "local",
// "remotePath": "${workspaceFolder:bin}\\Lobby.exe",
"presentation": {
"hidden": false,
"group": "1",
"order": 2
},
"processId": 2956
},

使用vscode,安装连接到远程,工具栏里面选择“运行”-“安装附加调试器”

1
Could not attach to pid 2956: this could be caused by a kernel security setting, try writing "0" to /proc/sys/kernel/yama/ptrace_scope

远程调试

1
2
3
4
go install github.com/go-delve/delve/cmd/dlv@latest
go build -gcflags "all=-N -l" -o your_program
ps aux | grep your_binary_name
dlv attach 12345 --headless --listen=:2345 --log --api-version=2 --accept-multiclient

{
“name”: “Attach to Remote”,
“type”: “go”,
“request”: “attach”,
“mode”: “remote”,
“remotePath”: “/home/youruser/your_project”, // 改成你远程项目路径
“port”: 2345,
“host”: “127.0.0.1”,
“apiVersion”: 2,
“showLog”: true,
“cwd”: “${workspaceFolder}”
}

参考