I have a C linux application (A) that spawns another process (P) when it is started. When I want to debug P I start A as usual and I connect with ddd/gdb to P.
Problems appear when I want to debug the entry-point (start of main) of P. If I follow the usual approach when I connect the debugger to P is already to late. The solution I’ve found was to insert a sleep at the begining of the main of P so I have time to connect with gdb but this is not a very elegant solution.
I’ve also tried using asm('int $3') but it doesn’t seems to work.
Do you have any idea how I could solve this problem? (preferably without altering the code of A or P)
You should use this option:
Where mode is one of
parent,childorask.To follow the parent (this is the default) use:
To follow the child:
To have the debugger ask you each time:
So basically you’d start out connecting gdb to A, then set gdb to follow the child, and then when A spawns P, gdb will connect to P and detach from A.