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

M1 Mac下VSCode调试Golang失败问题求助

M1 Mac(arm64)下VSCode调试Golang失败:debugserver找不到/权限拒绝解决办法

问题说明

此前正常工作的VSCode launch.json配置,在M1 Mac(arm64架构)上调试Golang时失效,VSCode弹出错误:

Failed to launch: could not launch process: fork/exec /Applications/Xcode.app/Contents/SharedFrameworks/LLDB.framework/Versions/A/Resources/debugserver: no such file or directory

手动启动debugserver时,出现权限拒绝提示:

$ /Applications/Xcode.app/Contents/SharedFrameworks/LLDB.framework/Versions/A/Resources/debugserver -D -F -R 127.0.0.1:30000 /path/to/go/file.go
debugserver-@(#)PROGRAM:LLDB  PROJECT:lldb-1500.0.404.7
 for arm64.
error: failed to launch process /Applications/Xcode.app/Contents/SharedFrameworks/LLDB.framework/Versions/A/Resources/debugserver: Permission denied
Exiting

现有公开方案多针对x86架构,无法适配arm64环境。

解决方案(arm64专属)

1. 确保Xcode Command Line Tools完整安装

执行命令安装或更新工具链:

xcode-select --install

安装完成后重启VSCode。

2. 修复debugserver权限

M1 Mac上debugserver需要系统权限授权:

  • 打开系统设置 → 隐私与安全性 → 完全磁盘访问权限
  • 点击左下角锁图标解锁,添加/Applications/Xcode.app/Contents/SharedFrameworks/LLDB.framework/Versions/A/Resources/debugserver到权限列表
  • 重启Mac使权限生效

3. 调整VSCode launch.json配置

修改launch.json,强制适配arm64架构,示例配置:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Launch Go Program",
            "type": "go",
            "request": "launch",
            "mode": "debug",
            "program": "${file}",
            "env": {
                "GOARCH": "arm64",
                "GOOS": "darwin"
            },
            "dlvFlags": ["--check-go-version=false"]
        }
    ]
}

通过GOARCH和GOOS指定架构,dlvFlags关闭版本检查避免兼容性冲突。

4. 安装arm64版本Delve调试器

执行命令安装适配arm64的Delve:

go install github.com/go-delve/delve/cmd/dlv@latest

之后打开VSCode命令面板(Cmd+Shift+P),选择Go: Install/Update Tools,更新所有Go工具。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.23 23:57:13