在不附加GDB的情况下获取所有线程的堆栈跟踪 [英] Getting stacktrace of all threads without attaching GDB
本文介绍了在不附加GDB的情况下获取所有线程的堆栈跟踪的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
或者是否有一个命令可以用作gdb批处理模式打印所有线程的堆栈跟踪线程?
解决方案
在GDB中有一个线程应用所有
命令:
(gdb)线程全部应用bt
线程12(线程0x7f7fe2116700(LWP 5466)):
#0 sem_wait()at ../nptl/sysdeps/unix/sysv/linux/x86_64/sem_wait.S:86
#1 0x0000000000425358 in ?? ()
...
线程1(线程0x7f7feabc27c0(LWP 5465)):
#0 0x00007f7fe76c5203在select()at ../sysdeps/unix/syscall-template.S:82
不幸的是,GDB似乎无法从管道读取命令,因此要运行命令在批处理模式下,必须使用一个临时文件:
$ gdbbt(){
tmp = $(tempfile )
echo thread apply all bt>$ tmp
gdb -batch -nx -q -x$ tmp-p$ 1
rm -f$ tmp
}
$ gdbbt $(pidof $ SHELL)
Is there a way to print stacktrace of all threads without attaching GDB?
Or is there a command which I can use as gdb batch mode to print stacktrace of all threads?
解决方案
There is a thread apply all
command in GDB:
(gdb) thread apply all bt
Thread 12 (Thread 0x7f7fe2116700 (LWP 5466)):
#0 sem_wait () at ../nptl/sysdeps/unix/sysv/linux/x86_64/sem_wait.S:86
#1 0x0000000000425358 in ?? ()
...
Thread 1 (Thread 0x7f7feabc27c0 (LWP 5465)):
#0 0x00007f7fe76c5203 in select () at ../sysdeps/unix/syscall-template.S:82
Sadly, GDB seems not to be able to read the commands from a pipe, so to run the commands in its batch mode, a temporary file must be used:
$ gdbbt() {
tmp=$(tempfile)
echo thread apply all bt >"$tmp"
gdb -batch -nx -q -x "$tmp" -p "$1"
rm -f "$tmp"
}
$ gdbbt $(pidof $SHELL)
这篇关于在不附加GDB的情况下获取所有线程的堆栈跟踪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文