编译

GOOS=linux GOARCH=amd64 go build -gcflags="all = -N -l"  main.go

远程机器

# ${pid} 远程机器上运行go程序的pid
dlv --listen=:2345 --headless=true --api-version=2 attach ${pid}

vscode launch.json配置

{
    "name": "remote debug",
    "type": "go",
    "request": "attach",
    "mode": "remote",
    "cwd": "${workspaceFolder}/testgo",
    "port": 2345,
    "host": "10.200.20.117" // 远程机器的host
}