如何在尚未加载到 gdb 中的共享库中的函数上设置断点

发布于 2024-08-28 22:50:17 字数 338 浏览 7 评论 0原文

我有一个共享库 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

娇女薄笑 2024-09-04 22:50:17

实际上,gdb 应该告诉您,将来加载新库时它能够解析符号:

(gdb) b test
Function "test" not defined.
Make breakpoint pending on future shared library load? (y or [n]) y
Breakpoint 1 (test) pending.
(gdb) r

稍后加载 .so 对象后,它将解析断点,例如:

Reading symbols for shared libraries . done
Breakpoint 1 at 0xcafebebe
Pending breakpoint 1 - "test" resolved

默认情况下,gdb 要求手动确认以设置此类待定断点gdb可以通过发出命令设置断点挂起来指示直接设置断点,而无需询问(文档)。

Actually gdb should tell you that it's able to resolve the symbol in the future, when new libraries are loaded:

(gdb) b test
Function "test" not defined.
Make breakpoint pending on future shared library load? (y or [n]) y
Breakpoint 1 (test) pending.
(gdb) r

And later on once the .so object is loaded, it will resolve the breakpoint, e.g.:

Reading symbols for shared libraries . done
Breakpoint 1 at 0xcafebebe
Pending breakpoint 1 - "test" resolved

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).

任性一次 2024-09-04 22:50:17

首先设置

catch load libtest.so

当 gdb 停止此 catch 时

b test

First set

catch load libtest.so

And when gdb will stop on this catch do

b test
纵性 2024-09-04 22:50:17

另一种方法是指定文件名和der函数,例如:

b object5.c:test

这应该是唯一的。也许您还想通过以下方式指定源代码的路径(如已经建议的那样):

set directories path_of_object5.c

Another way is to specify the filename and der function, e.g.:

b object5.c:test

This should be unique. Maybe you want also to specify the path to the source code (as already suggested) by:

set directories path_of_object5.c
旧梦荧光笔 2024-09-04 22:50:17

<块引用>

如何在共享库上设置断点。

共享库内有断点是很常见的。共享库可以在程序执行时显式地加载和卸载,并且可能重复加载和卸载。为了支持此用例,每当加载或卸载任何共享库时,gdb 都会更新断点位置。通常,您可以在调试会话开始时、未加载库以及库中的符号不​​可用时在共享库中设置断点。当您尝试设置断点时,gdb 会询问您是否要设置所谓的挂起断点——地址尚未解析的断点。

引用自 https://sourceware.org/gdb/onlinedocs/gdb/Set- Breaks.html

<块引用>

(gdb) b object5.c:66
没有名为 object5.c 的源文件。

也许你可以使用“设置目录the_location_of_object5.c_file”来修复它。

how to set a breakpoint on a shared lib.

It's quite common to have a breakpoint inside a shared library. Shared libraries can be loaded and unloaded explicitly, and possibly repeatedly, as the program is executed. To support this use case, gdb updates breakpoint locations whenever any shared library is loaded or unloaded. Typically, you would set a breakpoint in a shared library at the beginning of your debugging session, when the library is not loaded, and when the symbols from the library are not available. When you try to set breakpoint, gdb will ask you if you want to set a so called pending breakpoint—breakpoint whose address is not yet resolved.

quote from https://sourceware.org/gdb/onlinedocs/gdb/Set-Breaks.html

(gdb) b object5.c:66
No source file named object5.c.

maybe you can use "set directory the_location_of_object5.c_file" to fix it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文