You want eu-stack from elfutils. For example,
$ sudo eu-stack -id -p $$
PID 9189 - process
TID 9189:
#0 0x00007fd36c69e687 __GI___waitpid
#1 0x000055ba004c0c19
#2 0x000055ba004c234b wait_for
#3 0x000055ba004b1b64 execute_command_internal
#4 0x000055ba004b1bf2 execute_command
#5 0x000055ba0049c274 reader_loop
#6 0x000055ba0049ac7f main
#7 0x00007fd36c5dbb97 __libc_start_main
#8 0x000055ba0049b54a _start
One can write one-liners for more complex stuff. For example, to list all thread stacks for the Google Chrome (which is running multiple processes and threads!) one can do
sudo true
pidof chrome | sudo xargs -rn1 timeout 1s eu-stack -id -p
The timeout is used to prevent stalling on processes in uninterruptible sleep (some more recent kernel versions may allow getting stacks for those processes, too). Set timeout longer if you're willing to wait longer to get the stack.
And if you have a busy system where only some of the threads or processes are locked, one can take a snapshot of current process states like this
sudo true
pidof apache2 | sort -n | sudo xargs -rn1 timeout 1s eu-stack -id -p > snap1
sleep 10s
pidof apache2 | sort -n | sudo xargs -rn1 timeout 1s eu-stack -id -p > snap2
diff -u100 --color snap1 snap2
and you can identify stacks that did not change during 10 seconds (the sort is needed to make the stack order stable so you can meaningfully compare the outputs). If you get an errors such as
eu-stack: dwfl_linux_proc_report pid 25062: No such file or directory
eu-stack: dwfl_linux_proc_report pid 25068: Exec format error
it just means that the process 25062 exited after pidof listed it but before eu-stack had queried its state, and process 25068 was tearing down at the same time the stack trace was being built and as a result the stack building failed while reading the executable pointed via proc filesystem.