在GDB中,如何在程序停止时自动执行命令?(如显示)

neu*_*ron 9 command gdb

我希望每次程序停止时都会自动执行一些命令,就像显示x一样.我怎么做?

neu*_*ron 12

这是我发现的简单方法:

define hook-stop
  ...commands to be executed when execution stops
end
Run Code Online (Sandbox Code Playgroud)

有关详细信息,请参阅此页:http://sourceware.org/gdb/current/onlinedocs/gdb/Hooks.html#Hooks


Kev*_*vin 5

另一种“新”方法是使用Python 事件接口

 def stop_handler (event):
     print "event type: stop"

 gdb.events.stop.connect (stop_handler)
Run Code Online (Sandbox Code Playgroud)

这将触发stop_handler每个下级停止的功能。

还有另外两种类似的事件类型:

events.cont
events.exited
Run Code Online (Sandbox Code Playgroud)

分别在劣势延续或存在时触发。