如何在GDB中重新运行程序几次? [英] How to re-run program in GDB several times?
问题描述
我有一个偶尔失败的程序,但是有同样的错误。为了调试它,我想在GDB下运行它,直到它失败,设置断点并重新运行它。
我该做什么:
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:
gdb --args /path/to/program <program args>
但是我找不到任何地方,例如我如何告诉GDB运行这个程序100次 。
But I can't find anywhere how do I tell GDB "run this program 100 times" for example.
推荐答案
这个gdb脚本会运行程序100次,或者直到它接收到一个信号。如果程序由于信号而停止,则 $ _ siginfo
是非空的,如果程序退出则无效。据我所知,包括断点,观察点和单步执行的任何停止进程都会将 $ _ siginfo
设置为某个值。
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
这篇关于如何在GDB中重新运行程序几次?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!