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

时间:2011-09-20 06:40:08

标签: gdb command

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

2 个答案:

答案 0 :(得分:11)

这是我发现的简单方法:

define hook-stop
  ...commands to be executed when execution stops
end

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

答案 1 :(得分:3)

另一种“新”方法是使用Python Event interface

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

 gdb.events.stop.connect (stop_handler)

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

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

events.cont
events.exited

分别在下等继续或存在时触发。

相关问题