【发布时间】:2014-07-12 18:25:28
【问题描述】:
在一些相关问题的答案中,我可以看到 gdb 7.3 应该支持至少使用“信息线程”命令显示线程名称。 但我什至没有得到那种奢侈。请帮助我理解我做错了什么。
我用于测试的示例代码:
#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) 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
如您所见,我看不到我设置的任何线程名称。有什么问题?
注意: 我正在使用 gdb 7.7 版(没有使用特殊选项下载和编译) 用于编译和安装 gdb 的命令:./configure && make && make install
【问题讨论】:
-
使用我的系统 (gdb 7.6, xf86_64) 我只能在实时调试时看到线程名称。像您一样使用它进行事后分析,线程名称不会显示
-
我尝试直接从 gdb 启动精灵。但我没有看到任何线程名称出现。我也会尝试 7.6 版。
-
@Sigismondo 我尝试使用 7.6,没有运气。我不确定我错过了什么(我使用的是 32 位版本)
-
我刚刚使用了 Fedora19 gdb - 开箱即用,它适用于您的测试代码,仅使用“gcc -g”编译。
-
它在 ubuntu 中工作。我尝试使用 gdb7.7 预装的 ubuntu 14.04。但是我的 CentOS 与我自己的 gdb7.7 编译版本的结果不同。
标签: gdb