gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 16:18:22 26 4
gpt4 key购买 nike

我有一个多线程 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com