How can I rerun a program with gdb until a segmentation fault occurs?

Gdb

Gdb Problem Overview


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?

Gdb Solutions


Solution 1 - 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

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.

Solution 2 - Gdb

(gdb) set pagination off
(gdb) break exit
(gdb) commands
>run
>end
(gdb) run

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMKoView Question on Stackoverflow
Solution 1 - GdbborribleView Answer on Stackoverflow
Solution 2 - GdbOleksandr KozlovView Answer on Stackoverflow