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?
if you change and recompile your program in another window, you don't need to restart gdb. Just type "run" again, and gdb will notice the changes and load the new copy of your program. pressing enter executes the last command again. This makes it easily to step through your program line by line.
The following are some typical causes of a segmentation fault: Attempting to access a nonexistent memory address (outside process's address space) Attempting to access memory the program does not have rights to (such as kernel structures in process context) Attempting to write read-only memory (such as code segment)
When you're doing a usual gdb session on an executable file on the same computer, you can give the run command and it will start the program over again.
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) set pagination off (gdb) break exit (gdb) commands >run >end (gdb) run
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With