[英]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.