Reputation:
As in the title.
Sometimes step-by-step debugging of a process or a thread becomes inconvenient if other threads/processes continue their execution at full speed.
Bonus if it was possible to debug this way two processes when they were both started independently from bash (and not one a child of the other).
Upvotes: 1
Views: 1226
Reputation: 213879
For threads, this should already be happening.
GDB by default executes inferior in all-stop mode. In that mode, GDB will stop all threads as soon as one thread stops (either because it received a signal, or because it encountered a breakpoint). See also this answer.
While GDB also supports multiple inferiors, I don't believe there are any mechanisms to perform a "stop all inferiors" equivalent to "stop all threads" built in to GDB.
However, you can trivially achieve that with a command attached to your breakpoint:
(gdb) break foo.c:1234
(gdb) commands 1
shell kill -STOP 4321 # stop the other inferior
end
Bonus if it was possible to debug this way two processes when they were both started independently from bash
Sure: you can attach both processes to the current GDB ((gdb) help attach
) or to separate ones. It doesn't much matter where they were started from.
Upvotes: 1