如何使用 gdb 重新运行程序,直到出现分段错误? [英] How can I rerun a program with gdb until a segmentation fault occurs?
问题描述
我的程序有段错误的问题,但是很少出现错误(20次或更多一次),并且在GDB中调试它,我需要手动重新运行程序,直到出现段错误(在半天的重新运行期间只有一次失败:().
My program has a segmentation fault problem, but it faults rarely(once in 20 times or more), and to debug it in GDB, I need to manually rerun the program until the segmentation fault occurs (during a half day of reruns only once it fails :( ).
所以问题是,有没有办法告诉 GDB 重新运行程序,直到出现一些段错误?
So the questions is, is there any way to tell the GDB to rerun program until some segfault?
推荐答案
在你的程序的退出处放置一个触发 run
命令的断点,不要忘记 set pagination off代码>.断点命令列表 gdb 文档的部分.简而言之:
Put a breakpoint at the exit of your program that triggers the run
command, and don't forget set pagination off
. Information on settings commands is available in the Breakpoint Command Lists section of the gdb documentation. In short:
set pagination off
break _exit
commands
run
end
在 commands
行之后,您会看到接下来的两行作为到达断点时要执行的命令输入.
After the commands
line you'll see that the next two lines are being entered as the command to execute when the breakpoint is reached.
这篇关于如何使用 gdb 重新运行程序,直到出现分段错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!