This is the mail archive of the gdb@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Need help in debugging daemons with GDB


>  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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]