2015-09-27 95 views
0

有時我正在嘗試調試gdb中的程序,並且在bug出現之前需要一段時間才能運行。掛鉤到gdb或使gdb執行命令出現異常

當我在等待時,我喜歡做其他事情。如果gdb在異常發生時可以向我發出嗶聲,那將會很好。

有沒有辦法讓gdb在發生異常時運行外部命令?或者一個標準的方式來鉤入gdb的這種事情?

回答

0

你可以利用defineshell的,所以:

(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。

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