Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting stacktrace of all threads without attaching GDB

Tags:

c++

linux

gdb

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?

like image 983
Vivek Goel Avatar asked Sep 12 '12 19:09

Vivek Goel


1 Answers

elfutils among other utilities includes eu-stack:

eu-stack
    Print a stack for each thread in a process or core file.

It is faster than gdb or pstack, which is just a shell script wrapper around gdb. To print stack traces run eu-stack as follows:

$ eu-stack -p 2209
PID 2209 - process
TID 2209:
#0  0x00007f53476b667b __poll
#1  0x00007f5348f98e99 g_main_context_iterate.isra.23
#2  0x00007f5348f99232 g_main_loop_run
#3  0x000055e604b1e56a main
#4  0x00007f53475cc00a __libc_start_main
#5  0x000055e604b1e76a _start
TID 2223:
#0  0x00007f53476b667b __poll
#1  0x00007f5348f98e99 g_main_context_iterate.isra.23
#2  0x00007f5348f98fac g_main_context_iteration
#3  0x00007f5348f98ff1 glib_worker_main
#4  0x00007f5348fc0486 g_thread_proxy
#5  0x00007f534813761b start_thread
#6  0x00007f53476c2c2f __clone
TID 2224:
#0  0x00007f53476b667b __poll
#1  0x00007f5348f98e99 g_main_context_iterate.isra.23
#2  0x00007f5348f99232 g_main_loop_run
#3  0x00007f5349581b56 gdbus_shared_thread_func
#4  0x00007f5348fc0486 g_thread_proxy
#5  0x00007f534813761b start_thread
#6  0x00007f53476c2c2f __clone
like image 196
ks1322 Avatar answered Oct 08 '22 07:10

ks1322