I'm debug-running a daemon application in foreground mode inside gdb inside a tmux session. This daemon 开发者_如何学Gooccasionally crashes with a SIGSEGV. Results of this crash are not immediately evident to the outside world, so it might take a while for me to discover the daemon has crashed. I would like to receive some sort of a notification immediately when a crash happens, even e-mail is fine. I've found no help from man gdb. How (if at all) is this achieved?
~ $ gdb --version
GNU gdb (Gentoo 7.2 p1) 7.2
It looks like I've solved this one getting back to it after a while. Tip about $_exitcode in one of the answers for Make gdb quit automatically on successful termination? put me on the path and some googling turned up gdb hooks.
After some experimenting, this is what I have now for this app's .gdbinit. Nice thing is, I can differentiate between signals, so normal kill commands give me a normal complete exit out of the three headed monster (tmux + gdb + app), while anything out of the ordinary will drop to gdb shell, pump out an email and wait for me to tmux in to diagnose:
set $_exitcode = -999
set height 0
handle SIGTERM nostop print pass
handle SIGPIPE nostop
define hook-stop
if $_exitcode != -999
quit
else
shell echo | mail -s "NOTICE: app has stopped on unhandled signal" root
end
end
echo .gdbinit: running app\n
run
Something cheap and ugly:
while sleep 30 ; ps auxw | grep progname | grep " t "` && mail -s CRASHED username@host < /etc/hostname ; done
If you'd like it to only mail once ;) then there's more work to be done. But an email every 30 seconds until you kill this might be just the trick.
精彩评论