GDB:遇到断点时切换到线程

GDB: Switch to thread when breakpoint is hit

我在多线程下设了一个断点。任何线程都可能到达断点。当遇到断点时,我想让 gdb 切换到遇到断点的线程。

目前,我收到通知说 bp 被命中了。然后我必须查看每个线程的顶部堆栈帧才能知道它是哪一个,如下所示:

(gdb) info threads
(gdb) thread apply all bt 1 full
(gdb) thread 2

我希望自动切换。

I'd like this switching to be automatic.

GDB 应该已经自动执行此操作,请参阅 documentation:

Whenever GDB stops your program, due to a breakpoint or a signal, it automatically selects the thread where that breakpoint or signal happened. GDB alerts you to the context switch with a message such as ‘[Switching to Thread n]’ to identify the thread.

除了通知您命中断点外,您还应该收到有关切换到另一个线程的通知。