在gdb中达到断点时是否有可能停止执行所有其他线程? [英] Is it possible to halt the execution of all other threads when reaching a breakpoint in gdb?

查看:435
本文介绍了在gdb中达到断点时是否有可能停止执行所有其他线程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,只要我在某个线程中遇到断点,是否可以暂停其他线程直到我继续? 解决方案

p>在全停止模式(当前发布的版本支持的唯一模式)下,GDB将在任何线程停止时立即停止所有线程(由于断点或信号)。



继续停止的线程时,除非您在上设置 set scheduler-locking,否则所有其他线程也会继续。请注意,任何步骤下一步等等将继续当前(并且因此所有其他)线程(在适当的地方设置临时断点后,例如在下一个命令的下一行)。



也许你希望能够单步停止线程而无需恢复所有其他线程?在这种情况下,上设置调度程序锁定就是答案。



注意:如果另一个线程持有锁,您打开调度程序锁定,并且当前线程也需要相同的锁定,程序将无限期地等待。如果其中一个线程位于malloc / realloc中,并且当前语句试图分配一些内存,这通常会出现。



另外不要忘记 continue 之前关闭设置调度程序锁定,否则只有当前线程会进行任何前进。


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

解决方案

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.

这篇关于在gdb中达到断点时是否有可能停止执行所有其他线程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆