[英]GDB - What thread am I on?
When I hit a breakpoint in GDB, and I need to find out what thread this is on, I do info thr
.当我在 GDB 中遇到断点时,我需要找出它所在的线程,我执行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?不是让 GDB 转储整个线程列表,然后手动读取具有*
线程,而是 gdb 中有一个命令可以简单地打印出当前线程?
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.如果 GDB 实现了类似whatThreadIsThis
命令的东西,那么我可以使用 GDB 记录所有出现的 xyz 以及它们发生的线程。
You can use the "thread thread-id" command to switch to another thread as the docs mentions.您可以使用“thread thread-id”命令切换到文档中提到的另一个线程。 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 hasConvenience Variables . gdb 也有便利变量。 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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.