在不附加GDB的情况下获取所有线程的堆栈跟踪

编程入门 行业动态 更新时间:2024-10-21 19:43:16
本文介绍了在不附加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的情况下获取所有线程的堆栈跟踪

本文发布于:2023-11-02 14:41:07,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1552678.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:堆栈   线程   情况下   GDB

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!