在 OS X/gdb 中查找崩溃线程的创建者?
假设我在 gdb 中并且有一个像这样的调用堆栈:
Thread 24 (process 6449):
#0 0x994010e2 in semaphore_wait_signal_trap ()
#1 0x9942ec9c in _pthread_cond_wait ()
#2 0x9947745f in pthread_cond_wait ()
#3 0x92ed1ccd in jpegdecompress_MPLoop ()
#4 0x9942e7fd in _pthread_start ()
#5 0x9942e682 in thread_start ()
如何找出谁创建了该线程?
let's say I'm in gdb and have a call stack like this:
Thread 24 (process 6449):
#0 0x994010e2 in semaphore_wait_signal_trap ()
#1 0x9942ec9c in _pthread_cond_wait ()
#2 0x9947745f in pthread_cond_wait ()
#3 0x92ed1ccd in jpegdecompress_MPLoop ()
#4 0x9942e7fd in _pthread_start ()
#5 0x9942e682 in thread_start ()
How do I find out who created that thread?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一般来说,您不能:pthread 库没有任何理由记录和存储该信息。
在只创建少量线程的应用程序中,这通常也不需要 - 如果您知道是 jpegdecompressor 线程崩溃了,并且您只创建了其中一个线程,那么告诉哪里 该线程已创建。
如果您确实需要答案,则必须在调用 pthread_create 时记录堆栈跟踪,并将其传递给新线程以保存在某个线程本地中。
In general, you can't: the pthread library doesn't have any reason to record and store that info.
In applications that create only a handful of threads, this usually isn't needed either -- if you know that it's the jpegdecompressor thread that crashed, and you only create one of them, then it's trivial to tell where that thread was created.
If you really need the answer, you'll have to record the stack trace at the time of
pthread_create
call, and pass that to the new thread to save away in some thread-local.