Need help in debugging daemons with GDB

Mark Kettenis mark.kettenis@xs4all.nl
Wed Aug 9 06:39:00 GMT 2006


>  I am not sure this is the correct mailing list for this but did not
>  find another  suitable one ...
>  I am debugging a daemon in FreeBSD and I am particularly interested in
>  the initialization functions activity as the daemon starts ...
>  conventionally I attach the GDB to the PID and supply the unstripped
>  object file of the daemon as argument. Now the problem with this is
>  when you stop the daemon and restart there is no info of the PID
>  avaliable for attaching the GDB, thus I cannot get to see the
>  initialization functions ... and by the time you get to know PID the
>  initialization stuff is already history :-)

I presume that your daemon calls daemon(3) (or has code equivalent to it)
and calls fork(2) early on and does the interesting stuff in the child
process.

You could change the code and put in a sleep(3) before the initialization
code you're interested in to give yourself a bit more time to attach to
the child.

The real solution would be for the FreeBSD people to implement an extension
to ptrace(2) that makes it possible for GDB to get notified when the
inferior forks.  I implemented this for OpenBSD a while ago and it
shouldn't be too difficult to adapt this code to FreeBSD.

Mark



More information about the Gdb mailing list