[英]Hook into gdb or make gdb execute command on exception
有时,我试图在gdb
调试程序,但要花一些时间才能运行该错误。
在等待时,我喜欢做其他事情。 如果gdb可以在发生异常时向我发出蜂鸣声,那就太好了。
有没有办法让gdb在发生异常时运行外部命令? 还是一种标准的方法可以挂接到gdb上呢?
您可以使用define
和shell
,因此:
(gdb) define nrun
run
shell notify-send "Go look at GDB now...."
end
这将创建一个新命令nrun
(用于notify run),该命令执行一个run
命令,然后在run
完成后使用shell
执行notify-send
。
notify-send
与gdb
无关,这只是我的$PATH
中的一个程序,该程序会导致弹出通知对话框出现,您可以用所需的任何内容替换notify-send
。
现在,不使用run
而是使用nrun
,一旦gdb
停止,我会看到一条通知,请查看gdb。
您可以将nrun
的define
添加到您的~/.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.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.