Go插件调试

huangapple go评论96阅读模式
英文:

Go plugin debugging

问题

有一个使用golang编写的应用程序,在运行时加载插件。我正在开发这个插件,我想问一下是否有机会调试我的插件代码?

我尝试使用--gcflags="all=-N -l"编译应用程序和插件,并在调试器中运行应用程序,但是我得到了一个错误消息:可执行文件不包含插件的调试信息

有没有办法调试golang插件?

英文:

There is a golang application that loads the plugin at runtime. I am developing this plugin and I would like to ask if there is an opportunity to debug the code of my plugin?

I tried to run delve by compiling both the application and the plugin with --gcflags="all=-N -l", but running the application in the debugger I got an error the executable file does not contain debugging information for the plugin

Are there ways to debug golang plugin?

答案1

得分: 2

解决方案:通过runtime.Breakpoint()设置断点,然后使用delve运行应用程序。它将在插件代码的断点处停止。

不要忘记使用以下标志构建插件和应用程序:go build -trimpath -gcflags "all=-N -l"

英文:

Solution: put breakpoint via runtime.Breakpoint(), then run application with delve. It will stop on breakpoint at the plugin code.

Don't forget to build plugin and application with flags: go build -trimpath -gcflags "all=-N -l"

huangapple
  • 本文由 发表于 2022年2月7日 20:41:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/71018770.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定