如何使用gdb查找线程树? [英] How do I find thread tree using gdb?
问题描述
我在网上搜索,但徒劳无功。 info thread
提供了在附加gdb的进程中当前活动的所有线程。我想知道gdb是否可能显示线程树,即列出的线程之间的父子关系。
I searched online but in vain. info thread
provides all the threads the are currently alive in the process attached with gdb. I want to know if it is possible for gdb to show a thread tree i.e. parent child relationship between the listed threads.
为什么我想知道?十几个线程,其中一个线程正在等待其子线程的join_all()。
Why do I want to know that?: Amongst a dozen threads, one of the thread is waiting on join_all() of its child threads. If I can understand on which threads is the main thread waiting on, I can debug better.
元数据:
gdb版本7.7
Metadata: gdb version 7.7
推荐答案
我不认为你想要的信息是可用的,所以gdb没有内置的方式显示它。
I don't think the information you want is available, so gdb doesn't have a built-in way to display it.
如果这很重要,我想你有几个选择。
If it is very important I guess you have a couple of choices.
一个,在你的后续评论中,你提到一个线程试图加入它的孩子。所以,作为一个快速和脏的东西,你可以切换到这个线程,上,并看看它正在等待的线程。
One, in your follow-up comment you mention that a thread is trying to join its children. So, as a quick-and-dirty thing you could switch to that thread, go "up", and look at the threads it is waiting on.
或者,你可以使用Python编写一些gdb代码以某种方式自动化这些代码,无论是特定于应用程序还是通过在适当的位置(pthread_create等)设置断点来记录parentage信息。这有点难。
Or, you could use Python to write some gdb code to automate this in a way, either app-specific or by setting breakpoints at the appropriate spots (pthread_create, etc) to record the parentage information. This is somewhat harder.
这篇关于如何使用gdb查找线程树?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!