使用gdb 7.7时,info Thread命令中未显示线程名称
在一些相关问题的答案中,我可以看到GDB7.3应该至少支持使用'info threads'命令显示线程名称。 但我甚至没有得到那种奢侈。请帮助我理解我做错了什么 用于测试的示例代码:使用gdb 7.7时,info Thread命令中未显示线程名称,gdb,Gdb,在一些相关问题的答案中,我可以看到GDB7.3应该至少支持使用'info threads'命令显示线程名称。 但我甚至没有得到那种奢侈。请帮助我理解我做错了什么 用于测试的示例代码: #include <stdio.h> #include <pthread.h> #include <sys/prctl.h> static pthread_t ta, tb; void * fx (void *param) { int i = 0; prct
#include <stdio.h>
#include <pthread.h>
#include <sys/prctl.h>
static pthread_t ta, tb;
void *
fx (void *param)
{
int i = 0;
prctl (PR_SET_NAME, "Mythread1", 0, 0, 0);
while (i < 1000)
{
i++;
printf ("T1%d ", i);
}
}
void *
fy (void *param)
{
int i = 0;
prctl (PR_SET_NAME, "Mythread2", 0, 0, 0);
while (i < 100)
{
i++;
printf ("T2%d ", i);
}
sleep (10);
/* generating segmentation fault */
int *p;
p = NULL;
printf ("%d\n", *p);
}
int
main ()
{
pthread_create (&ta, NULL, fx, 0);
pthread_create (&tb, NULL, fy, 0);
void *retval;
pthread_join (ta, &retval);
pthread_join (tb, &retval);
return 0;
}
正如你所看到的,我看不到我设置的任何线程名称。有什么不对劲吗
注:
我使用的是gdb 7.7版(下载和编译时不使用特殊选项)
用于编译和安装gdb:./configure&&make&&makeinstall的命令据我所知,核心转储中不存在线程名称
如果它们以某种方式可用,请提交一个gdb错误。我得到的线程名称显示在CentOS6.5上,但不显示在CentOS6.4上 在我的系统(GDB7.6,xf86_64)中,我只能在实时调试时看到线程名称。在进行后期分析时,线程名不会显示。我试图直接从gdb启动elf。但是我没有看到任何线程名显示。我也会尝试7.6版。@Sigismondo我尝试过使用7.6版,运气不好。我不确定我遗漏了什么(我使用的是32位版本),我刚刚使用了Fedora19 gdb-开箱即用,它与您的测试代码配合得很好,只使用“gcc-g”编译。它在ubuntu中工作。我试过ubuntu 14.04,它预装了gdb7.7。但是我的CentOS没有给出与我自己的gdb7.7编译版本相同的结果。我如何确认内核转储中是否存在线程名[root@ServThreads]#grep-inr MyThread2 core.5546二进制文件core.5546 matches如果字符串出现在堆中,则可能匹配。我想最好的方法是挖掘文档或者相关的内核源代码。我想你是对的。它需要比gdb做更多的核心文件生成,因为它可以在实时调试中工作
(gdb) core-file core.14001
[New LWP 14003]
[New LWP 14001]
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/libthread_db.so.1".
Core was generated by `./thread_Ex'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0 0x08048614 in fy (param=0x0) at thread_Ex.c:30
30 printf("%d\n",*p);
(gdb) info threads
Id Target Id Frame
2 Thread 0xb77d76c0 (LWP 14001) 0x00b95424 in __kernel_vsyscall ()
* 1 Thread 0xb6dd5b70 (LWP 14003) 0x08048614 in fy (param=0x0) at thread_Ex.c:30
(gdb) bt
#0 0x08048614 in fy (param=0x0) at thread_Ex.c:30
#1 0x006919e9 in start_thread () from /lib/libpthread.so.0
#2 0x005d3f3e in clone () from /lib/libc.so.6
(gdb) thread apply all bt
Thread 2 (Thread 0xb77d76c0 (LWP 14001)):
#0 0x00b95424 in __kernel_vsyscall ()
#1 0x006920ad in pthread_join () from /lib/libpthread.so.0
#2 0x080486a4 in main () at thread_Ex.c:50
Thread 1 (Thread 0xb6dd5b70 (LWP 14003)):
#0 0x08048614 in fy (param=0x0) at thread_Ex.c:30
#1 0x006919e9 in start_thread () from /lib/libpthread.so.0
#2 0x005d3f3e in clone () from /lib/libc.so.6
(gdb) q