How to re-run the program in GDB several times?

I have a program that interrupts sporadically, but with the same error. To debug it, I would like to run it under GDB until it works, set breakpoints and restart it. what should I do:

gdb --args /path/to/program <program args> 

But I can't find anywhere else to tell GDB to "run this program 100 times", for example.

+7
debugging gdb
source share
2 answers

This gdb script will run the program 100 times or until it receives a signal. $_siginfo is non-empty if the program is stopped due to a signal and is invalid if the program exits. As far as I can tell, any process shutdown, including breakpoints, watchpoints and a single click, will set $_siginfo to something.

 set $n = 100 while $n-- > 0 printf "starting program\n" run if $_siginfo printf "Received signal %d, stopping\n", $_siginfo.si_signo loop_break else printf "program exited\n" end end 
+5
source share

The easiest solution I can think of is to run the program in an endless while loop until it works, or press Ctrl + C to break the loop.

 (gdb) while 1 >run >end 
+5
source share

All Articles