c - 仅在不使用调试器时出现段错误

标签 c debugging gdb segmentation-fault

我有一个多线程 C 程序,它始终在程序的特定点生成段错误。当我用 gdb 运行它时,没有显示任何错误。您能想到为什么只有在不使用调试器时才会出现故障吗?不能用它来发现问题是很烦人的!

最佳答案

经典Heisenbug .来自维基百科:

Time can also be a factor in heisenbugs. Executing a program under control of a debugger can change the execution timing of the program as compared to normal execution. Time-sensitive bugs such as race conditions may not reproduce when the program is slowed down by single-stepping source lines in the debugger. This is particularly true when the behavior involves interaction with an entity not under the control of a debugger, such as when debugging network packet processing between two machines and only one is under debugger control.

调试器可能正在改变时序,并隐藏竞争条件。

在 Linux 上,GDB 还禁用地址空间随机化,您的崩溃可能与地址空间布局有关。尝试 (gdb) set disable-randomization off

最后,ulimit -c unlimited 和事后调试(已由 Robie 建议)可能会起作用。

关于c - 仅在不使用调试器时出现段错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4628521/

相关文章:

c - 为什么会出现段错误?

c - 栈内存是在运行时分配的还是编译时分配的?

c# - Visual Studio 2010/2012 : when Stop Debugging on breakpoint hit debugged process hangs and is unkillable

c - 在 C 程序中为 jemalloc 设置 MALLOC_CONF 环境变量不起作用

c - C语言中long double的读入

c# - 为什么 Xamarin Debugger 会跳过断点/代码?

android-studio - 诊断Android应用程式当机的原因

xcode - 如何在 Xcode 中添加条件断点

emacs - Gdb 与 emacs 和 F*

c - 使用 gdb 调试 echo 程序时,K&R 对 echo 程序的解释令人困惑。怎么了?