gdb:多线程 [英] gdb : multithreading

查看:158
本文介绍了gdb:多线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用两个线程的程序。我已经把这个断点放在两个线程中。在gdb下运行程序时,我想在线程之间切换并让它们运行。
(线程t1处于活动状态并正在运行,线程t2;在断点处暂停时,我想停止T1运行并运行T2)。

我可以在gdb中安排线程的任何方式?



感谢
Arpit

解决方案

当任何断点被命中时停止所有线程,并在发出任何命令(例如 continue , next)时恢复所有线程 step finish 等),这要求劣质过程

但是,您可以告诉GDB不要这么做:

 (gdb)help set scheduler-locking 
设置执行期间锁定调度程序的模式。
关闭==不锁定(线程可以随时抢占)
on ==完全锁定(除当前线程外可以运行的任何线程)
步骤==每个单步操作。
在此模式下,在步骤命令中不会运行其他线程。
在执行函数调用('next')时可能会运行其他线程。

所以你需要设置断点,然后 set scheduler-locking on ,然后在线程1中线程2仍然停止,然后 continue finish ,然后Ctrl-C重新控制GDB,切换到线程2,继续(线程1仍然停止)等。



注意:通过在上设置调度器锁定,很容易导致低级进程自行死锁。


I have a program which uses two threads. I have put the break point in both the threads. While running the program under gdb I want to switch between the threads and make them run. (thread t1 is active and running and thread t2; when paused on the breakpoint. I want to stop T1 running and run the T2).

Is there any way that I can schedule the threads in gdb?

Thanks Arpit

解决方案

By default, GDB stops all threads when any breakpoint is hit, and resumes all threads when you issue any command (such as continue, next, step, finish, etc.) which requires that the inferior process (the one you are debugging) start to execute.

However, you can tell GDB not to do that:

(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').

So you'll want to set breakpoints, then set scheduler-locking on, then continue or finish in thread 1 (thread 2 is still stopped), then Ctrl-C to regain control of GDB, switch to thread 2, continue (thread 1 is still stopped), etc.

Beware: by setting scheduler-locking on it is very easy to cause the inferior process to self-deadlock.

这篇关于gdb:多线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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