Search code examples
cdebugginggdbld-preload

How to debug functions in a dynamic library loaded with LD_PRELOAD with gdb?


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.


Solution

  • 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

    set follow-fork-mode child
    

    to make gdb attach to the child that gets created in a vfork().