繁体   English   中英

挂接到gdb或使gdb在异常时执行命令

[英]Hook into gdb or make gdb execute command on exception

有时,我试图在gdb调试程序,但要花一些时间才能运行该错误。

在等待时,我喜欢做其他事情。 如果gdb可以在发生异常时向我发出蜂鸣声,那就太好了。

有没有办法让gdb在发生异常时运行外部命令? 还是一种标准的方法可以挂接到gdb上呢?

您可以使用defineshell ,因此:

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

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

notify-sendgdb无关,这只是我的$PATH中的一个程序,该程序会导致弹出通知对话框出现,您可以用所需的任何内容替换notify-send

现在,不使用run而是使用nrun ,一旦gdb停止,我会看到一条通知,请查看gdb。

您可以将nrundefine添加到您的~/.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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM