gdb nostop SIGSEGV on a specific thread
gdb nostop SIGSEGV on a specific thread
我有一个程序故意在一个线程上分段,但我遇到了另一个线程正在分段的问题,我想用GDB来捕捉它,我看到我可以:
handle SIGSEGV nostop noprint
但我只想在有意这样做的线程上这样做。。有可能吗?
我会解释:我有两个线程,一个线程是分段故障(并恢复(mprotect只读,然后释放内存)),这很好,另一个线程做了其他事情,但遗憾的是,有一个错误,它是分段故障,我想捕捉那个分段故障,而不是其他线程中发生的其他故障。
正如我所知,根据操作系统的不同,我假设linux是我的答案,答案是"否"!
Posix异常每个线程可以有一个sigmask,但每个任务只能有一个处理程序。因此,不可能为每个线程设置不同的处理。sigaction将处理整个过程。所以我认为gdb没有办法改变这一点。
我将解释:我有两个线程,一个线程是分段故障(并恢复(mprotect只读,然后释放内存)),这很好,另一个线程做了其他事情,但遗憾的是,有一个错误,它是分段故障,我想捕捉那个分段故障,而不是其他线程中发生的其他故障
您必须告诉gdb忽略第一个SIGSEGV信号。因此,在第一次sagfault之后,在此线程中使用signal 0
命令。您的程序将在gdb下恢复执行,这正是您想要的。然后它将在第二个线程中的第二个segfault处停止,这就是您想要检查的内容。
(gdb) help signal
Continue program with the specified signal.
Usage: signal SIGNAL
The SIGNAL argument is processed the same as the handle command.
An argument of "0" means continue the program without sending it a signal.
This is useful in cases where the program stopped because of a signal,
and you want to resume the program while discarding the signal.
所以
- 不要使用
handle SIGSEGV nostop noprint
。在下运行程序gdb - 当它在前三个中出现故障时,执行
signal 0
。您的程序恢复执行 - 然后它在另一个线程中分段。现在使用
backtrace
查看问题
或者,如果你的两个线程不相互依赖,你可以在第一个segfault的线程中等待,而另一个segfoot发生。只要在第一个线程中执行call sleep(60)
,它就会导致segfault,并在另一个线程中等待另一个segfault。您的第一个线程将等待:
Program received signal SIGFPE, Arithmetic exception.
[Switching to Thread 0x7ffff7fde700 (LWP 25744)]
0x000000000040075d in my_thread_func1 (arg=0x0) at my_test_2.cpp:17
17 ptr1 = ptr1 / 0;
(gdb) call sleep(60)
Thread 140737343510272:
Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7ffff75dd700 (LWP 25745)]
0x00000000004007a3 in my_thread_func2 (arg=0x0) at my_test_2.cpp:27
27 *ptr2 = *ptr2 + 2;
The program received a signal in another thread while
making a function call from GDB.
Evaluation of the expression containing the function
(sleep) will be abandoned.
When the function is done executing, GDB will silently stop.
(gdb)
相关文章:
- 在std::thread中,joinable()然后join()线程安全吗
- <Windows>为什么 std::thread::native_handle 返回类型为"long long unsigned int"的值,而不是 void*(又名 HANDLE)?
- 分离一个静态常量 std::thread?
- 尝试使用 std::vector<std::thread时出现静态断言失败错误>
- 使用 thread 类在 C++ 中构造线程的动态数组时出错
- 当指向对象的指针作为参数传递给 std::thread 时,内存可见性
- 如何从 std::thread 返回值
- 在C++中使用并行化的预期速度是多少(不是 OpenMp,而是 <thread>)
- 将 std::thread by 值推送到列表中
- 转发变量参数列表以模拟 std::thread
- 嵌入式设备 -> std::thread -> FreeRTOS?
- 对 'std::thread::_M_start_thread CMake 的未定义引用进行基准测试
- std::thread 增加 DLL 引用计数,从而防止卸载 DLL
- 如何防止 std::thread 在 QT 中冻结 GUI?
- 对带有唯一指针的 std::thread 使用类成员函数时出现编译错误
- C++ - Thread Pool
- 为什么参数在构造 std::thread 时移动两次
- std::thread::_Invoker 使用线程编程时出错
- "Segfault using proj4 with OpenMP"或"How to use thread-specific globals with OpenMP"
- gdb nostop SIGSEGV on a specific thread