如何在尚未加载到 gdb 中的共享库中的函数上设置断点
我有一个共享库 libtest.so
,它将使用 dlopen
加载到主程序中。函数test()
驻留在libtest.so
中,将通过dlsym
在主程序中调用。有什么方法可以在 test
上设置断点吗?
请注意,在链接期间主程序尚未链接到libtest.so
。否则,我应该能够设置断点,尽管它是一个待处理的操作。就我而言,当我进行b test
时,gdb会告诉我Function "test" not Define
。
I have a shared library libtest.so
which will be loaded into the the main program using dlopen
. Function test()
reside in libtest.so
and will be called in the main program through dlsym
. Is there any way I could set up a break point on test
?
Please note that the main programm has not been linked to libtest.so
during linking time. Otherwise , I should be able to set the break point although it is a pending action. In my case, when I do b test
, gdb will tell me Function "test" not defined
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
实际上,gdb 应该告诉您,将来加载新库时它能够解析符号:
稍后加载 .so 对象后,它将解析断点,例如:
默认情况下,gdb 要求手动确认以设置此类待定断点。 gdb可以通过发出命令
设置断点挂起
来指示直接设置断点,而无需询问(文档)。Actually gdb should tell you that it's able to resolve the symbol in the future, when new libraries are loaded:
And later on once the .so object is loaded, it will resolve the breakpoint, e.g.:
By default, gdb asks for manual confirmation to set such pending breakpoint. gdb can be instructed to directly set the breakpoint without asking by issuing the command
set breakpoint pending on
(documentation).首先设置
当 gdb 停止此 catch 时
First set
And when gdb will stop on this catch do
另一种方法是指定文件名和der函数,例如:
这应该是唯一的。也许您还想通过以下方式指定源代码的路径(如已经建议的那样):
Another way is to specify the filename and der function, e.g.:
This should be unique. Maybe you want also to specify the path to the source code (as already suggested) by:
引用自 https://sourceware.org/gdb/onlinedocs/gdb/Set- Breaks.html
也许你可以使用“设置目录the_location_of_object5.c_file”来修复它。
quote from https://sourceware.org/gdb/onlinedocs/gdb/Set-Breaks.html
maybe you can use "set directory the_location_of_object5.c_file" to fix it.