有时候我正在尝试调试gdb
中的程序,并且在错误出现之前需要一段时间才能运行。
在我等待的时候,我喜欢做其他事情。如果发生异常,gdb会在我身上发出哔哔声会很好。
当异常发生时,有没有办法让gdb运行外部命令?或者是这种事情挂钩到gdb的标准方法?
答案 0 :(得分:0)
您可以使用define
和shell
,所以:
(gdb) define nrun
run
shell notify-send "Go look at GDB now...."
end
这将创建一个执行nrun
命令的新命令run
(用于通知运行),然后在run
完成后使用shell
执行notify-send
}。
notify-send
与gdb
无关,这只是我$PATH
中的一个程序导致弹出通知对话框出现,您可以将notify-send
替换为任何你想要的东西。
现在我没有使用run
,而是使用nrun
,而gdb
停止后,我会看到通知,看看gdb。
您可以将define
nrun
添加到~/.gdbinit
文件中,然后它将始终可用,如果您要这样做,您可能还想添加一些文档,像这样:
documentation nrun
Perform a standard run command and notify the user when gdb stops.
end
现在在gdb
,如果你忘了你的命令,你可以这样做:
(gdb) help nrun
Perform a standard run command and notify the user when gdb stops.
如果你忘记了你所谓的命令,但是你知道它在gdb停止时执行通知你可以这样做:
(gdb) apropos notify
nrun -- Perform a standard run command and notify the user when gdb stops.