You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何解决Docker环境下Go Delve调试器适配器报错问题?

Go远程调试断点报错问题排查

问题场景

已在容器内启动Go Delve调试器无头实例,远程监听2345端口,使用如下VS Code的launch.json配置连接:

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Launch",
      "type": "go",
      "mode": "remote",
      "request": "launch",
      "program": "${workspaceFolder}",
      "remotePath": "/demo",
      "port": 2345,
      "env": {},
      "args": [],
      "showLog": true,
      "trace": "verbose"
    }
  ]
}

Docker运行正常,但设置断点时触发如下错误:

Unhandled error in debug adapter: TypeError: Cannot read properties of undefined (reading 'addr')
    at GoDebugSession.convertDebugVariableToProtocolVariable (/Users/user/.vscode/extensions/golang.go-0.35.1/dist/debugAdapter.js:16709:25)
    at /Users/user/.vscode/extensions/golang.go-0.35.1/dist/debugAdapter.js:16249:55
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Promise.all (index 1)

解决方法

  • 升级VS Code Go扩展:当前使用的0.35.1版本存在调试适配bug,直接在扩展市场更新到最新稳定版,多数用户反馈此操作可解决该报错。
  • 同步Delve版本:确保容器内的Delve版本与本地Go扩展依赖版本一致。容器内执行dlv version查看版本,本地执行go install github.com/go-delve/delve/cmd/dlv@latest同步至最新版。
  • 添加路径映射配置:在launch.json的配置项中加入substitutePath,映射本地代码路径和容器内路径,避免路径不匹配导致的变量解析异常:
    "substitutePath": [
      {
        "from": "${workspaceFolder}",
        "to": "/demo"
      }
    ]
    
  • 调整日志级别:暂时移除trace: "verbose"配置(或改为trace: "log"),verbose日志可能触发调试适配器的异常逻辑。

内容的提问来源于stack exchange,提问作者Chirag Rayani

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.25 13:03:25