如何让gdb在接收信号时发送外部通知? [英] How to make gdb send an external notification on receiving a signal?
问题描述
我在tmux会话中以gdb内部的前台模式调试运行守护程序应用程序。这个守护进程偶尔会碰到一个SIGSEGV。这次崩溃的结果并不是立刻对外界显而易见的,因此我可能需要一段时间才能发现守护进程已经崩溃。我希望在发生崩溃时立即收到某种通知,即使电子邮件也没问题。我找不到man gdb的帮助。如何(如果有的话)这样做?
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
推荐答案
看来我已经解决了这个问题一段时间后回到它。有关在成功终止时自动退出gdb的答案之一提示$ _exitcode? 让我走上了路,一些谷歌搜索出现了 gdb钩子。
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.
经过一番尝试,现在我已经为这个应用程序的 .gdbinit 进行了测试。很好的一点是,我可以区分不同的信号,所以普通的kill命令会给我一个正常的完全退出三头怪物(tmux + gdb + app),而任何不寻常的东西都会掉到gdb shell中,抽出一封电子邮件并等待我进行诊断:
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
这篇关于如何让gdb在接收信号时发送外部通知?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!