Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. How to get all the thread name itself instead of the hex value like 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 ()
like image 748
Whoami Avatar asked Jan 20 '12 16:01

Whoami


People also ask

How to see the thread name in GDB?

Use the "info threads" command to see the IDs of currently known threads. The gdb thread debugging facility allows you to observe all threads while your program runs—but whenever gdb takes control, one thread in particular is always the focus of debugging. This thread is called the current thread .

What is LWP in GDB?

The operating system's lightweight process (LWP) ID value for the thread. This ID is used in part for the OS to keep track of this thread for scheduling purposes. The GDB ID for the thread. This is the ID to use when specifying a specific thread in GDB commands.


2 Answers

If you upgrade to gdb 7.3 or later, "info thread" will show thread names; at least on native (not remote) Linux.

like image 168
Tom Tromey Avatar answered Oct 21 '22 16:10

Tom Tromey


Threads don't have names by default - the JKMainT string there is the name of the current function.

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.

like image 40
James McLaughlin Avatar answered Oct 21 '22 16:10

James McLaughlin