[英]Hook into gdb or make gdb execute command on exception
Sometimes I am trying to debug a program in gdb
and it takes it a while of running before the bug comes up. 有时,我试图在
gdb
调试程序,但要花一些时间才能运行该错误。
While I'm waiting, I like to do other things. 在等待时,我喜欢做其他事情。 It would be nice if gdb could beep at me when an exception happens.
如果gdb可以在发生异常时向我发出蜂鸣声,那就太好了。
Is there a way to make gdb run an external command when an exception happens? 有没有办法让gdb在发生异常时运行外部命令? Or a standard way to hook into gdb for this sort of thing?
还是一种标准的方法可以挂接到gdb上呢?
You could make use of the define
and shell
, so: 您可以使用
define
和shell
,因此:
(gdb) define nrun
run
shell notify-send "Go look at GDB now...."
end
This creates a new command nrun
(for notify run) that does a run
command, then when the run
has finished uses shell
to execute notify-send
. 这将创建一个新命令
nrun
(用于notify run),该命令执行一个run
命令,然后在run
完成后使用shell
执行notify-send
。
The notify-send
is nothing to do with gdb
, this is just a program in my $PATH
that causes a popup notification dialogue to appear, you could replace notify-send
with anything that you want. notify-send
与gdb
无关,这只是我的$PATH
中的一个程序,该程序会导致弹出通知对话框出现,您可以用所需的任何内容替换notify-send
。
Now instead of using run
I use nrun
, and once gdb
stops I see a notification to go look at gdb. 现在,不使用
run
而是使用nrun
,一旦gdb
停止,我会看到一条通知,请查看gdb。
You can add the define
for nrun
to your ~/.gdbinit
file, and then it will always be available, if you're going to do that you might also want to add some documentation, like this: 您可以将
nrun
的define
添加到您的~/.gdbinit
文件中,然后它将始终可用,如果您要这样做,则可能还需要添加一些文档,例如:
documentation nrun
Perform a standard run command and notify the user when gdb stops.
end
Now in gdb
if your forget what your command does you can do this: 现在在
gdb
如果您忘记了命令,可以执行以下操作:
(gdb) help nrun
Perform a standard run command and notify the user when gdb stops.
And if you forget what you called you command, but you know that it performs a notify when gdb stops you can do this: 而且,如果您忘记了所调用的命令,但是知道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.