挂钩到gdb或在异常时创建gdb执行命令

时间:2015-09-27 02:53:08

标签: gdb

有时候我正在尝试调试gdb中的程序,并且在错误出现之前需要一段时间才能运行。

在我等待的时候,我喜欢做其他事情。如果发生异常,gdb会在我身上发出哔哔声会很好。

当异常发生时,有没有办法让gdb运行外部命令?或者是这种事情挂钩到gdb的标准方法?

1 个答案:

答案 0 :(得分:0)

您可以使用defineshell,所以:

(gdb) define nrun
run
shell notify-send "Go look at GDB now...."
end

这将创建一个执行nrun命令的新命令run(用于通知运行),然后在run完成后使用shell执行notify-send }。

notify-sendgdb无关,这只是我$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.