I'd like to tell my gdb to automatically track each child process created by the parent process my gdb runs.
You can write a Python program to do that (assuming recent GDB built with embedded Python).
Often a much easier approach is to modify the failing test case like so (I am using gUnit example here, but the same technique works in general):
TEST(Foo, Bar) {
// Start added code.
volatile int go = 0; // Modified from GDB.
while (go == 0) {
fprintf(stderr, "Run 'gdb -p %d'\n", getpid());
sleep(1);
}
// End.
EXPECT_EQ(123, Bar()); // This is the test which fails.
}
Now just run all your tests, attach GDB when the test case runs, set breakpoints as desired, set go
to 1 and continue
.
P.S. Most test frameworks already have a mechanism to attach debugger on failure. If you are dealing with one that doesn't, you may want to fix that.