How to make gdb send an external notification on receiving a signal?

不羁的心 提交于 2019-12-11 05:19:33

问题


I'm debug-running a daemon application in foreground mode inside gdb inside a tmux session. This daemon occasionally 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

回答1:


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.




回答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


来源:https://stackoverflow.com/questions/4845617/how-to-make-gdb-send-an-external-notification-on-receiving-a-signal

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!