Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to halt the execution of all other threads when reaching a breakpoint in gdb?

So, as soon as I hit a breakpoint in some thread, is it possible to halt other threads until I continue?

like image 594
Paul Wicks Avatar asked Oct 18 '25 15:10

Paul Wicks


1 Answers

In all-stop mode (the only mode supported by currently released versions) GDB will stop all threads as soon as any thread stops (due to a breakpoint or a signal).

When you continue the stopped thread, all other threads will also continue, unless you do set scheduler-locking on. Note that any of step, next, etc. continues current (and thus all other) thread (after setting a temporary breakpoint in appropriate place, e.g. on the next line for next command).

Perhaps you want to be able to single-step stopped thread without resuming all the other threads? In that case, set scheduler-locking on is the answer.

Beware: if another thread is holding a lock, you turn scheduler-locking on, and your current thread also requires the same lock, your program will wait indefinitely. This often comes up if one of the threads is inside malloc/realloc, and your current statement tries to allocate some memory.

Also don't forget to set scheduler-locking off before continue, otherwise only the current thread will make any forward progress.

like image 95
Employed Russian Avatar answered Oct 21 '25 03:10

Employed Russian