How to re-run program in GDB several times?

前端 未结 2 519
星月不相逢
星月不相逢 2021-02-08 11:43

I have a program which fails sporadically, but with the same error. To debug it I\'d like to run it under GDB until it fails, set breakpoints and re-run it. what do I do:

2条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-08 12:31

    This gdb script will run the program 100 times, or until it receives a signal. $_siginfo is non-void if the program is stopped due to a signal, and is void if the program exited. As far as I can tell, any stop of the process, including breakpoints, watchpoints, and single-stepping, 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
    

提交回复
热议问题