Long time ago I noticed that using
set follow-fork-mode child
in GDB on FreeBSD doesn't really work. This problem occurs very often with some challenges on various Capture The Flag contests. For example, a server will spawn a child which would handle the connection. The child code has a vulnerability which I would like to debug, but gdb just never follows the childs execution and I can't really observe the vulnerability being triggered.
So far, I've solved this problem in two ways:
Making a connection, waiting for a child to spawn and than attaching GDB to it.
This works since the spawned child has it's own PID to which I can attach, but is rather painful since first I have to make a connection from one session, attach with GDB in another, and then send the payload/continue the connection in the first.
Patching the binary after the fork call to continue the execution in the parent process instead of the child.
This is also painful since then I have to restart the whole parent process to create another debugging session.
There are some other tricks that can be employed, but these are enough to illustrate my point.
Now I know there have been some limitations on FreeBSD in the past regarding this but has anything improved?
Is there any way to patch GDB to add this functionality? Any suggestions for an easier way of overcoming this?