GoLand on Apple Silicon 无法调试 golang 项目

问题描述

Edit 2021-01-28:这整个问题现在已经过时了,因为 GoLand 2020.3.2 是 released today,并且它包括一个有效的研究。不要忘记删除您的更改正如发行说明所指出的那样,可能已经做到了。

我正在尝试在 Apple Silicon 上使用 GoLand 调试 golang 项目,但它不起作用;错误如下:

API server listening at: [::]:62619
debugserver-@(#)PROGRAM:LLDB  PROJECT:lldb-1200.0.44 for x86_64.
error: failed to launch process /Library/Developer/CommandLineTools/Library/PrivateFrameworks/LLDB.framework/Versions/A/Resources/debugserver: (os/kern) invalid argument
Exiting.
could not launch process: stub exited while waiting for connection: exit status 0

解决方法

编辑 2021-01-28:整个问题(和这个答案)现在已经过时了,因为 GoLand 2020.3.2 是 released today,并且它包括一个有效的研究。正如发行说明指出的那样,忘记删除您可能做出的更改。

user14892075's answer 和主要是 https://www.reddit.com/r/golang/comments/kqgxel/debugging_wcli_and_goland_works_on_apple_m1/ 的刺激,这里是技术,直到 Goland 和 dlv 正式发布

  1. 为 arm64 安装 golang。最简单的方法是 brew install golang if 你有 arm64 版本的 brew,它现在工作得很好。这将让您此时获得 golang v1.16-beta1。
  2. 安装 Goland 的 Apple Silicon 版本
  3. 查看钻研。 PR 已经合并,git clone https://github.com/go-delve/delve,然后用 cd delve && make install 构建它,这会将 delve 放入 ~/go/bin/dlv
  4. 打开 Goland 并转到“帮助”->“编辑自定义 VM 选项”。在那里添加一行 -Ddlv.path=/Users/rfay/go/bin/dlv(将用户名从 rfay 更改为您的用户名,或者将路径编辑为您构建的 dlv 的完整路径)。
  5. 重启 Goland
,

GoLand 使用 Delve 作为调试器。 Delve 尚不支持 Apple Silicon。

Jetbrains 和 Delve 提供错误票来跟踪此情况。我建议您观看这些门票以获取更新:

  1. https://youtrack.jetbrains.com/issue/GO-10235
  2. https://github.com/go-delve/delve/issues/2246

但是不要指望在 Go 1.16 版之前会有一些“稳定”和官方的东西,它有官方的 Apple Silicon 支持。目前,计划于 2 月发布。

Go 支持 Apple Silicon 可能是 Delve 在 Apple Silicon 上工作的先决条件,因为通过 Rosetta 进行调试似乎不可行。因此,Delve 需要使用 Go 1.16 进行编译才能在 Apple Silicon 上原生运行。

因此,Apple Silicon 对 Delve 的官方支持可能不会在 2021 年 2 月之前实现

,

它现在可以工作了。参见:https://github.com/oxisto/delve/tree/darwin-arm64-lldb它没有合并到主分支;“去构建”它并替换 Goland dlv 插件,然后 Degbugger 工作。

,

我有 golang 1.16.6 并且仍然面临与此错误消息相同的问题: Use go sdk for darwin/arm64

我的解决方案是添加以下 ENV

GOOS=darwin,GOARCH=arm64

enter image description here

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...