c++ - gdb单步全停止模式下的单线程


在gdb All-Stop模式下,一旦遇到断点,所有线程都将在该断点处停止(我目前看到线程2导致了断点的命中)。现在,我希望在我按下一步时仅运行线程4,并且希望所有其他线程继续保持停止状态。 IE。我想使用线程4来确保所有其他线程保持停止状态。




On some OSes, you can modify gdb's default behavior by locking the OS scheduler to allow only a single thread to run.

set scheduler-locking mode

Set the scheduler locking mode. It applies to normal execution, record mode, and replay mode. If it is off, then there is no locking and any thread may run at any time. If on, then only the current thread may run when the inferior is resumed. The step mode optimizes for single-stepping; it prevents other threads from preempting the current thread while you are stepping, so that the focus of debugging does not change unexpectedly. Other threads never get a chance to run when you step, and they are completely free to run when you use commands like ‘continue’, ‘until’, or ‘finish’. However, unless another thread hits a breakpoint during its timeslice, gdb does not change the current thread away from the thread that you are debugging. The replay mode behaves like off in record mode and like on in replay mode.