简体   繁体   English

gdb 如何显示线程名称

[英]gdb how to get thread name displayed

There are many threads created in my application.我的应用程序中创建了很多线程。 some of the threads name are visible in the gdb while i execute the command 'info threads', others are not displayed.当我执行命令“信息线程”时,一些线程名称在 gdb 中可见,其他线程名称未显示。 How to get all the thread name itself instead of the hex value like 0xb7fe1424如何获取所有线程名称本身而不是像 0xb7fe1424 这样的十六进制值

4 Thread 0xb68ffb70 (LWP 18377)  0xb7fe1424 in __kernel_vsyscall ()
* 3 Thread 0xb7291b70 (LWP 18375)  JKMainT (arg=0x0) at mylib.cpp:482
2 Thread 0xb7a92b70 (LWP 18374)  0xb7fe1424 in __kernel_vsyscall ()
1 Thread 0xb7a94730 (LWP 18371)  0xb7fe1424 in __kernel_vsyscall ()

Threads don't have names by default - the JKMainT string there is the name of the current function. 默认情况下,线程没有名称JKMainT字符串包含当前函数的名称。

Try selecting one of the threads and viewing the backtrace - that might give you a good idea which thread it is. 尝试选择一个线程并查看回溯-这可能会让您很好地知道它是哪个线程。 Otherwise, you could try prctl with PR_SET_NAME if it's available. 否则,您可以尝试使用PR_SET_NAME prctl (如果可用)。

If you upgrade to gdb 7.3 or later, "info thread" will show thread names; 如果升级到gdb 7.3或更高版本,则“信息线程”将显示线程名称;否则,将显示线程名称。 at least on native (not remote) Linux. 至少在本机(非远程)Linux上。

You can set the thread name via non-standard POSIX api calls. 您可以通过非标准POSIX API调用来设置线程名称。 GDB (and other debuggers) will display these names. GDB(和其他调试器)将显示这些名称。

On Linux 在Linux上

// watch out, 16 char limit on the name
pthread_setname_np(pthread_self(), "My thread name");

On Mac 在Mac上

pthread_setname_np("My thread name");
  • (gdb) info threads - will display all the threads (gdb) info threads - 将显示所有线程

  • (gdb) thread will switch to the thread you selected and display the thread name (gdb)thread 会切换到你选择的线程并显示线程名称

  • (gdb) thread - will display current thread name (gdb) thread - 将显示当前线程名称

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM