cro*_*ght 23 go visual-studio-code vscode-debugger apple-m1
我发现一个遇到同样问题的主题(Can't debug Golang in vscode apple m1)但我不确定它是否是一个旧的解决方案,因为我使用的是 Go 版本
go1.17.1 darwin/arm64
Run Code Online (Sandbox Code Playgroud)
和
dlv version 1.7.2
Run Code Online (Sandbox Code Playgroud)
和
VSCode version 1.60.2 (arm64)
Run Code Online (Sandbox Code Playgroud)
在
Mac M1 BigSur (11.6)
Run Code Online (Sandbox Code Playgroud)
当我运行 debug ( 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
Run Code Online (Sandbox Code Playgroud)
并且出现弹出错误:
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
Run Code Online (Sandbox Code Playgroud)
我尝试使用 dlv 1.6.1 将 go 版本降级到 1.16.8 arm64 但仍然遇到相同的错误。
我可以在两个版本上成功使用 go build 。
Pra*_*dey 37
这是我解决这个问题的方法。
go env GOARCH$GOPATH/bin(重要)问题的根本原因:我不小心安装了amd-64版本而不是arm-64我的Apple Mac M1.
感谢Painhardcore 的回答为我指明了正确的方向。
小智 29
确保您的 VSCode 使用 arm64 版本。(可以使用与系统不同的go版本)
运行Go:安装/更新工具。它将使用arm64 go版本重建所有工具。
对我有用的:
"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": [],
}
]
}
Run Code Online (Sandbox Code Playgroud)