【GoLand】无法debug 无法运行

GoLand,点击debug报错:

复制代码
GOROOT=/Users/tiantian19/sdk/go1.21.9 #gosetup
GOPATH=/Users/tiantian19/go #gosetup
/Users/tiantian19/sdk/go1.21.9/bin/go build -o /Users/tiantian19/Library/Caches/JetBrains/GoLand2023.1/tmp/GoLand/___go_build_icode_baidu_com_baidu_cov_smartUT_comate -gcflags all=-N -l icode.baidu.com/baidu/cov/smartUT-comate #gosetup
/Applications/GoLand.app/Contents/plugins/go-plugin/lib/dlv/macarm/dlv --listen=127.0.0.1:58724 --headless=true --api-version=2 --check-go-version=false --only-same-user=false exec /Users/tiantian19/Library/Caches/JetBrains/GoLand2023.1/tmp/GoLand/___go_build_icode_baidu_com_baidu_cov_smartUT_comate --
API server listening at: 127.0.0.1:58724
debugserver-@(#)PROGRAM:LLDB  PROJECT:lldb-1600.0.39.109
 for arm64.
Got a connection, launched process /Users/tiantian19/Library/Caches/JetBrains/GoLand2023.1/tmp/GoLand/___go_build_icode_baidu_com_baidu_cov_smartUT_comate (pid = 81255).
Exiting.
could not launch process: decoding dwarf section info at offset 0x0: too short - debuggee must not be built with 'go run' or -ldflags='-s -w', which strip debug info

Debugger finished with the exit code 1

解决方法:

升级dlv

  1. 下载delve
    git clone https://github.com/go-delve/delve
    cd /delve/cmd/dlv 进入build目录,
    go build main.go 编译main.go并生成可执行文件main (这里要确保工作用户与目录的权限一致,否则无法编译)
    mv main dlv 修改可执行文件名
  2. 替换goland dlv

查出dlv路径 需要golang执行一下debug

ps -ef|grep dlv

替换dlv

拷贝旧的debug文件,将新的dlv替换旧的

/Applications/GoLand.app/Contents/plugins/go-plugin/lib/dlv/macarm/dlv

如果还不能debug

查看GoLand中使用的go版本与工程go mod文件中指定版本是否一致

相关推荐
FellAveal2 小时前
【Go语言入门学习笔记】Part18.工作池与WaitGroup(也即协程池)
笔记·学习·golang
ldmd2843 小时前
地图生成算法(噪声篇-Perlin,Simplex,Value noise)
算法·go·地图生成
妙码生花4 小时前
从 PHP 到 AI + Golang,程序员自救转型手记(四十一):增加管理员账号管理接口
后端·go·gin
Wang's Blog7 小时前
Go-Zero项目开发40: 基于Jaeger的分布式链路跟踪实战
开发语言·分布式·golang
TDengine (老段)7 小时前
TDengine Go 与 Rust 连接器 — 高性能异步访问
大数据·数据库·物联网·golang·rust·时序数据库·tdengine
Wang's Blog10 小时前
Go-Zero项目开发38:深入限流器实现与应用
开发语言·golang·go-zero
xcLeigh10 小时前
Go入门:main包与main函数的特殊地位
开发语言·后端·golang
Wang's Blog13 小时前
Go-Zero项目开发39: 熔断、限流与降级的高可用实践
开发语言·后端·golang·go-zero
FfHUCisI13 小时前
快速排序(Quick Sort)
golang
高铭杰14 小时前
Golang sync.Mutex实现原理学习
java·学习·golang