仅在不使用调试器时出现段错误 [英] segfault only when NOT using debugger

查看:39
本文介绍了仅在不使用调试器时出现段错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个多线程 C 程序,它始终在程序的特定点生成分段错误.当我用 gdb 运行它时,没有显示任何错误.你能想出什么原因导致只有在不使用调试器时才会出现故障吗?不能用它来查找问题很烦人!

I have a multithreaded C program, which consistently generates a segmentation fault at a specific point in the program. When I run it with gdb, no fault is shown. Can you think of any reason why the fault might occur only when not using the debugger? It's pretty annoying not being able to use it to find the problem!

推荐答案

Classic Heisenbug.来自维基百科:

Classic Heisenbug. From Wikipedia:

时间也可能是黑森虫的一个因素.与正常执行相比,在调试器的控制下执行程序可以改变程序的执行时序.当程序被调试器中的单步源代码行减慢时,诸如竞态条件之类的时间敏感错误可能不会重现.当行为涉及与不受调试器控制的实体进行交互时尤其如此,例如在调试两台机器之间的网络数据包处理并且只有一台在调试器控制下时.

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.

调试器可能会改变时间,并隐藏竞争条件.

The debugger may be changing timing, and hiding a race condition.

在 Linux 上,GDB 还会禁用地址空间随机化,并且您的崩溃可能特定于地址空间布局.尝试 (gdb) set disable-randomization off.

On Linux, GDB also disables address space randomization, and your crash may be specific to address space layout. Try (gdb) set disable-randomization off.

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

Finally, ulimit -c unlimited and post-mortem debugging (already suggested by Robie) may work.

这篇关于仅在不使用调试器时出现段错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆