Thumbnail image

Go 远程 Delve 调试缓慢问题

  • 在双方机器安装调试工具
go install github.com/go-delve/delve/cmd/dlv@latest
  • 配置环境变量:
export PATH=$PATH:$GOPATH/bin
  • 在远程机器启动对应服务:
dlv --listen :33333 --api-version=2 --headless --accept-multiclient --allow-non-terminal-interactive exec {program-to-run} -- {program-args}
  • 在 vscode 中进行类似配置进行远程调试:
{
    "version": "0.2.0", 
    "configurations": [
        {
            "name": "remote-debug",
            "type": "go",
            "request": "attach",
            "mode": "remote",
            "host": "{address-to-remote-server}",
            "port": 33333,
            "debugAdapter": "dlv-dap", // 适配器
            "substitutePath": [ // 源代码路径映射
                {
                    "from":"${workspaceFolder}",
                    "to":"{remote-source-folder},
                }
            ]
        }
    ]
}
    "debugAdapter": "dlv-dap"