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

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

问题描述

我的程序有一个分段故障问题,但很少发生故障(一次发生20次或更多),并且在GDB中调试它,我需要手动重新运行程序直到出现分段故障(在重新运行半天只有一次失败:()。



所以问题是,有什么办法可以告诉GDB重新运行程序,直到出现段错误?

解决方案

在程序的出口放置一个断点,触发 run 命令,并且不要忘记关闭设置分页。关于设置命令的信息可以在断点命令列表部分gdb文档简而言之:

 设置分页关闭
分页结束
命令
运行
结束

命令行之后,您会看到接下来的两行是bein g作为要在达到断点时执行的命令输入。


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 :( ).

So the questions is, is there any way to tell the GDB to rerun program until some segfault?

解决方案

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

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天全站免登陆