默认情况下,当任何断点被击中时,GDB会停止所有线程,并恢复
所有
当你发出任何命令(如
continue
、
next
、
step
、
finish
等),要求下级进程(你正在调试的进程)开始执行时,线程。
然而,你可以告诉GDB不要这样做。
(gdb) help set scheduler-locking
Set mode for locking scheduler during execution.
off == no locking (threads may preempt at any time)
on == full locking (no thread except the current thread may run)
step == scheduler locked during every single-step operation.
In this mode, no other thread may run during a step command.
Other threads may run while stepping over a function call ('next').
所以你要设置断点,然后set scheduler-locking on
,然后在线程1中continue
或finish
(线程2仍然停止)。然后按Ctrl-C重新获得GDB的控制权,切换到线程2,continue
(线程1仍然停止),等等。
注意:通过设置scheduler-locking on
,很容易导致低级程序自我停顿。