英文:
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"
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论