[英]Cannot run debug Go using VSCode on Mac M1
我发现了一个遇到相同问题的主题( Can't debug Golang in vscode apple m1 )但我不确定它是否是旧解决方案,因为我使用的是 Go 版本
go1.17.1 darwin/arm64
和
dlv version 1.7.2
和
VSCode version 1.60.2 (arm64)
上
Mac M1 BigSur (11.6)
当我运行调试( fn+f5
)时,调试控制台显示:
Starting: /Users/username/go/bin/dlv-dap dap --check-go-version=false --listen=127.0.0.1:53115 --log-dest=3 from /Users/username/go/src/project-name
DAP server listening at: 127.0.0.1:53115
并且有一个弹出错误:
Failed to launch: could not launch process: can not run under Rosetta, check that the installed build of Go is right for your CPU architecture
我尝试使用 dlv 1.6.1 将 go 版本降级到 1.16.8 arm64,但仍然出现相同的错误。
我可以在两个版本上成功使用 go 构建。
确保您的 VSCode 使用 arm64 版本。 (它可以使用与系统不同的 go 版本)
运行 Go:安装/更新工具。 它将使用 arm64 go 版本重建所有工具。
这是我解决此问题的方法。
go env GOARCH
确认$GOPATH/bin
中删除(VS-Code 使用的工具)二进制文件(重要) 问题的根本原因:我不小心在我的Apple Mac M1
中安装了amd-64
版本而不是arm-64
版本。
感谢Painhardcore的回答为我指明了正确的方向。
什么对我有用:
"About This Mac" > "Overview" > "Chip"
中进行检查让我知道,如果您也想要“launch.json”文件配置来调试。
编辑 11-04-22
分享launch.json
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Debug",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/main.go",
"args": [],
}
]
}
这个答案对我有用。 安装了ARM64并再次尝试。
https://github.com/go-delve/delve/issues/2604#issuecomment-1069740132
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.