Search code examples
debugginggdbfreebsdbsd

debugging forks on BSD using gdb


Currently GDB has an issue following child processes after a fork. A work around I saw online is to use patch the following instruction :-

call 0x8048740 <fork@plt>

as follows :-

gdb$ set *(0x08048d1f+1)=0x90909090
gdb$ set *(0x08048d1f)=0x9090c033

Doing this sets the instructions as :-

xor    eax,eax
nop    
nop    
nop

As a result the code supposed to be executed as the child is executed by the parent, and im able to debug it. However, typing out the two step statements every time I have to debug the process is too tedious. Is there any way I can instruct gdb to patch those instructions everytime I attach to the process? Some kind of automation, limited as it may be?


Solution

  • There are several ways to extend you GDB command list, using gdb extensions. Python scripts support is the latest development in GDB since 7.1 release. However looking at your requirement you don't need much scripting. You can use the simplest define command.

    I had answered a similar question some time back, you could use the same approach.