如何使用 gdb 重新运行程序,直到出现分段错误? [英] How can I rerun a program with gdb until a segmentation fault occurs?

查看:13
本文介绍了如何使用 gdb 重新运行程序,直到出现分段错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的程序有段错误的问题,但是很少出现错误(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屋!

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