且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

gdb多线程调试如何与Linux线程调度协调?

更新时间:2023-12-03 23:05:34

当gdb从另一个(t2)切换到线程(例如t1)时,它如何与内核协调,因为内核可能仍要在一段时间内运行t2.

When gdb switch to a thread (say t1) from another(t2), how does it coordinate with the kernel since the kernel might still want to run t2 for some period of time.

默认情况下,GDB以全停模式运行.这意味着,每当您看到(gdb)提示时,所有线程都会被 stopped 停止.在2个已停止线程之间切换不需要与内核进行任何协调,因为内核不会运行不可运行(已停止)的线程.

By default, GDB operates in all-stop mode. That means that all threads are stopped whenever you see the (gdb) prompt. Switching between 2 stopped threads doesn't need any coordination with the kernel, because kernel will not run non-runnable (stopped) threads.

不间断模式中,其他线程比目前的版本可以***运行,内核可以并且会安排它们按自己认为合适的方式运行.

In a non-stop mode, threads other than current run freely, and the kernel can and will schedule them to run as it sees fit.

当gdb步骤在一个特定线程中调试时(通过发出"si"命令),在此期间如何运行其他线程(或完全暂停)?

when gdb step is debugging in one specific thread (by issuing "si" command), how does other threads get run (or totally paused) during this period?

stepstepi时,默认情况下将恢复所有线程.您可以使用set scheduler-locking on进行控制,在这种情况下,将仅恢复单线程.如果您忘记关闭调度程序锁定 并执行continue,则仅恢复当前线程,这可能会使您感到困惑.

When you step or stepi, by default all threads are resumed. You can control this with set scheduler-locking on, in which case only the single thread will be resumed. If you forget to turn scheduler-locking off and do continue, only the current thread will be resumed, which is likely to confuse you.

文档.