如何使用 gdb 调试加载 LD_PRELOAD 的动态库中的函数?
我正在尝试调试动态共享库 libexecHook.so 中的一些函数。该库已预先加载并设置 LD_PRELOAD,以便拦截和重写对 execve() 等的一些调用。为了调试目的,我用符号构建了 gmake。从我在其他问题中读到的内容来看,这应该可行:
gdb ~/tmp/make-dfsg-3.81/make
set exec-wrapper env LD_PRELOAD=/home/marko/execHook.C027/lib/libexecHook.so.0.0.0
start
break execve
break execvp
cont
我确实看到断点设置正确,例如
4 breakpoint keep y 0x00007ffff7bd92e0 in execvp at execHook.c:128
,但 gdb 永远不会在我预加载的 exec..() 函数处中断。在执行期间观察调试输出,我看到正在调用我的库函数。
I'm trying to debug some functions in a dynamic shared library libexecHook.so. This library is preloaded setting LD_PRELOAD in order to intercept and rewrite some calls to execve() and friends. For debugging purposes I have built gmake with symbols. From what I read in other questions this should work:
gdb ~/tmp/make-dfsg-3.81/make
set exec-wrapper env LD_PRELOAD=/home/marko/execHook.C027/lib/libexecHook.so.0.0.0
start
break execve
break execvp
cont
I do see the breakpoints being set properly, e.g.
4 breakpoint keep y 0x00007ffff7bd92e0 in execvp at execHook.c:128
but gdb never breaks at my preloaded exec..() functions. Watching the debug output during execution I see that the my library functions are being called.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
gdb 没有在我的预加载包装器函数处中断的原因是,这些函数是从 gdb 未附加的子进程执行的。在 Linux 上,我可以
使 gdb 附加到在 vfork() 中创建的子级。
The reason gdb did not break at my preloaded wrapper functions is that these are executed from a child process to which gdb was not attached. On Linux I can
to make gdb attach to the child that gets created in a
vfork()
.在设置断点之前尝试说
start
。这将开始运行程序,这将导致库依赖关系得到满足,希望使用您的 LD_PRELOAD 路径。然后启动后设置断点,然后继续。Try saying
start
before setting your breakpoints. This will begin running the program which will cause the library dependencies to be satisfied, hopefully using your LD_PRELOAD path. Then set the breakpoints after start, and then do continue.