来自linux core dump的线程特定数据

Vis*_*gal 10 linux gdb coredump

在分析linux的核心转储时,如何获取指向线程本地存储或线程特定数据的指针?

我使用pthread_setspecific在pthread的本地stoare中存储一些数据.

我在linux上的多线程程序崩溃了,我想看看当前运行的线程的本地存储中存储了什么.

如果我获得指向线程本地存储的指针,我可以使用密钥来获取存储的数据.

gdb中是否有一个命令来获取指向线程本地存储指针

And*_*ski 5

如果您正在调试实时程序,则可以:

print pthread_getspecific(i)
Run Code Online (Sandbox Code Playgroud)

如果您可以访问该线程的pthread_t,则可以:

print ((struct pthread*)pth)->specific[i/32][i%32]
Run Code Online (Sandbox Code Playgroud)

在你想要的索引中我和pth是pthread_t.请参阅glibc源代码中的nptl/pthread_getspecific.c.

要在不调用函数的情况下执行此操作,您需要找到struct pthread.在x86-64上,它存储在fs基础中,使用arch_prctl(ARCH_SET_FS_BASE,...)设置.我不知道如何从gdb访问它,但你可以用eu-readelf获取它.运行eu-readelf --notes core_file并查看记录fs.base.该数字是pthread_t值.(要弄清楚它是哪一个,你可以pid将同一记录中的字段与gdb info threads命令中显示的LWP 匹配.)

祝好运!