gpt4 book ai didi

gdb - 使用 gdb 7.7 时,信息线程命令中未显示线程名称

转载 作者:行者123 更新时间:2023-12-04 16:49:40 25 4
gpt4 key购买 nike

在一些相关问题的答案中,我可以看到 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 错误。

关于gdb - 使用 gdb 7.7 时,信息线程命令中未显示线程名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24716010/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com