When I hit a breakpoint in GDB, and I need to find out what thread this is on, I do info thr
. This prints out the list of all the threads in my program, and the current thread is marked with a *
Instead of having GDB dump the entire list of threads, and then manually reading what thread has the *
, is there a command in gdb which simply prints out the current thread?
I need this because I am logging some behavior in my program. In other words, I have something like this -
(gdb) command 12
>> p " xyz just happpened"
>> whatThreadIsThis // I would like this
>> c
>> end
If GDB implemented something like the whatThreadIsThis
command, then I could use GDB to log all occurrences of xyz with the threads they happened on.
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.
Thread Id is a long positive integer that is created when the thread was created. During the entire lifecycle of a thread, the thread ID is unique and remains unchanged. It can be reused when the thread is terminated.
A backtrace is a summary of how your program got where it is. It shows one line per frame, for many frames, starting with the currently executing frame (frame zero), followed by its caller (frame one), and on up the stack.
A thread is a sequence of instructions to which the operating system grants processor time. Every process that is running in the operating system consists of at least one thread.
You can use the "thread thread-id" command to switch to another thread as the docs mentions. What the docs doesn't seem to mention is that without any argument, it just prints the current thread:
(gdb) thread
[Current thread is 1 (Thread 0x7ffff7fc2700 (LWP 4641))]
gdb also has Convenience Variables. One of the them is:
$_thread
The thread number of the current thread.
You can print it with:
(gdb) p $_thread
$2 = 2
Also it can be used in conditions:
condition 1 $_thread != 1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With