Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to dump thread stacks

Tags:

c

linux

x86

I want to dump the stacks of the threads in a file. How can I do that in linux? How can I find the starting address of the stack and its size? Note that I want to do this progammatically from the same process (not using ptrace, gdb or something like that).

like image 962
MetallicPriest Avatar asked Jun 02 '26 16:06

MetallicPriest


2 Answers

if you use the gnu c lib, you can use the backtrace() function

http://www.gnu.org/s/hello/manual/libc/Backtraces.html

like image 103
Chris Avatar answered Jun 05 '26 07:06

Chris


Use the pthread_attr_getstack function; this yields the thread's stack address and size.

like image 40
Brett Hale Avatar answered Jun 05 '26 06:06

Brett Hale



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!