c++ - gdb 使用 All-Stop 模式单步执行单个线程

标签 c++ multithreading gdb

我有一个系统,其中 5 个线程并行运行。我已经设置了一个断点。

在 gdb All-Stop Mode 中,一旦遇到断点,所有线程都会在该断点处停止(我目前看到线程 2 导致断点命中)。现在我希望当我按下下一步时只有线程 4 运行并且所有其他线程继续保持停止状态。 IE。我想继续执行线程 4,确保所有其他线程保持停止状态。

你能建议我该怎么做吗。

最佳答案

来自 gdb 文档:https://sourceware.org/gdb/onlinedocs/gdb/All_002dStop-Mode.html

On some OSes, you can modify gdb's default behavior by locking the OS scheduler to allow only a single thread to run.

set scheduler-locking mode

Set the scheduler locking mode. It applies to normal execution, record mode, and replay mode. If it is off, then there is no locking and any thread may run at any time. If on, then only the current thread may run when the inferior is resumed. The step mode optimizes for single-stepping; it prevents other threads from preempting the current thread while you are stepping, so that the focus of debugging does not change unexpectedly. Other threads never get a chance to run when you step, and they are completely free to run when you use commands like ‘continue’, ‘until’, or ‘finish’. However, unless another thread hits a breakpoint during its timeslice, gdb does not change the current thread away from the thread that you are debugging. The replay mode behaves like off in record mode and like on in replay mode.

关于c++ - gdb 使用 All-Stop 模式单步执行单个线程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38760642/

相关文章:

c++ - opencv:foundWeights 在 vi​​rtual void detectMultiScale(..) 中意味着什么

c++ - 导致除法溢出错误 (x86)

c++ - 如何确保多线程 C++ 程序由多核服务器上的所有内核运行?

c++ - gdb如何附加到多线程进程

c++ - GDB 中的嵌套类

c++ - C++中如何获取executor的路径?

c++ - flutter :即使 shouldRepaint() 返回 true,自定义画家也不会重新绘制

java - 了解同步块(synchronized block)

java - 为什么这段代码等待 1000 毫秒而不是 500 毫秒?

c - GDB 没有那个文件或目录