Are there any easy ways to debug forked child processes in *nix, without having to sleep them and create new gdb instances, using ps to get the child's pid? Are there any debuggers that do this?
You can already do this using gdb. Here is how:
(gdb) set detach-on-fork off
(gdb) set follow-fork-mode child
(gdb) catch fork # use breakpoint if catch fork not available
Then at some point you will reach your fork. Jump over it and gdb should inform you there is a new process.
[New process 813]
At this point you should view the "inferiors"
(gdb) info inferiors
Num Description Executable
* 2 process 813 /home/cnicutar/fork
1 process 810 /home/cnicutar/fork
To switch to a different inferior, use
(gdb) inferior 1
[Switching to inferior 1 [process 810] (/home/cnicutar/fork)]
[Switching to thread 1 (process 810)]
(gdb) info inferiors
Num Description Executable
2 process 813 /home/cnicutar/fork
* 1 process 810 /home/cnicutar/fork
Hope this helps :-)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With