使用gdb 7.7时,info thread命令中未显示线程名称

时间:2014-07-12 18:25:29

标签: gdb

在相关问题的一些答案中,我可以看到gdb 7.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; 
    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&amp;&amp;制造&amp;&amp; make install

2 个答案:

答案 0 :(得分:1)

据我所知,核心转储中不存在线程名称。

如果它们以某种方式可用,请提交gdb错误。

答案 1 :(得分:0)

我在CentOS6.5上显示线程名称,但未在CentOS6.4上显示。