【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文件中指定版本是否一致

相关推荐
资深web全栈开发2 小时前
[特殊字符]图解 Golang 反射机制:从底层原理看动态类型的秘密
开发语言·后端·golang
GM_8288 小时前
从0开始在Go当中使用Apache Thrift框架(万字讲解+图文教程+详细代码)
rpc·go·apache·thrift
Tony Bai9 小时前
【Go模块构建与依赖管理】09 企业级实践:私有仓库与私有 Proxy
开发语言·后端·golang
Lucky小小吴10 小时前
开源项目5——Go版本快速管理工具
开发语言·golang·开源
进化中的码农10 小时前
Go中的泛型编程和reflect(反射)
开发语言·笔记·golang
apocelipes13 小时前
POSIX兼容系统上read和write系统调用的行为总结
linux·c语言·c++·python·golang·linux编程
童话ing13 小时前
【Golang】常见数据结构原理剖析
数据结构·golang
Kratos开源社区14 小时前
别卷 LangChain 了!Blades AI 框架让 Go 开发者轻松打造智能体
go·agent·ai编程
Kratos开源社区15 小时前
跟 Blades 学 Agent 设计 - 01 用“提示词链”让你的 AI 助手变身超级特工
llm·go·agent
百锦再21 小时前
第10章 错误处理
java·git·ai·rust·go·错误·pathon