Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Thread specific data from linux core dump

How do I get pointer to thread's local storage or thread specific data while analyzing core dump for Linux ?

I use pthread_setspecific to store some data in the pthread's local storage.

my multi threaded program on Linux crashed, and I want to see what is stored in current running thread's local storage.

If I get pointer to thread's local storage I can use key to get the data that is stored.

Is there a command in gdb to get the pointer to thread's local storage?

like image 527
Vishwanath Sungal Avatar asked May 31 '12 21:05

Vishwanath Sungal


1 Answers

If you're debugging a live program, you can:

print pthread_getspecific(i)

If you have access to the pthread_t of the thread, you can:

print ((struct pthread*)pth)->specific[i/32][i%32]

where i in the index you want and pth is the pthread_t. See nptl/pthread_getspecific.c in the glibc sources.

To do this without calling a function, you need to find the struct pthread. On x86-64, it's stored in the fs base, which is set using arch_prctl(ARCH_SET_FS_BASE, ...). I don't know how to access this from gdb, but you can get it with eu-readelf. Run eu-readelf --notes core_file and look through the records for fs.base. That number is the pthread_t value. (To figure out which one it is, you can match up the pid field in the same record with the LWP shown in gdb's info threads command.)

Good luck!

like image 160
Andy Lutomirski Avatar answered Sep 21 '22 13:09

Andy Lutomirski