20080925

Debugging child processes

Problem:
Program A executes program B.
You want to debug program B.
B exits before you can attach your debugger.

Solution:
Insert an infinite loop in main() in program B:

while(1) {}

Run program A.
Attach debugger to program B.
Set the program counter to the next line:

In gdb, use the "jump" command.
In Visual Studio, use the "Set next statement" command on the context menu.

2 comments:

Raul said...

just put a messagebox or a _Debugbreak(); or an assert()

Malcolm Parsons said...

Raul: yes, any of those would work on MS Windows.

I don't use MS Windows.