11

I want some commands to be automatically executed each time the program stops, just like what display does with x. How do I do that?

Captain Obvlious
  • 19,754
  • 5
  • 44
  • 74
neuron
  • 1,896
  • 1
  • 19
  • 24
  • 1
    Okay I found it for myself. I post it here just in case someone else's gonna need it. [CR] define hook-stop [CR] ...commands to be executed when execution stops [CR] end [CR] ' See [this page](http://sourceware.org/gdb/current/onlinedocs/gdb/Hooks.html#Hooks) of the GDB manual for more details – neuron Sep 20 '11 at 06:55
  • Why don't you write that as an answer, it can be useful for everyone! – Kevin Sep 21 '11 at 06:44
  • possible duplicate of [Get gdb to do a 'list' after every step](http://stackoverflow.com/questions/4362581/get-gdb-to-do-a-list-after-every-step) – Ciro Santilli OurBigBook.com Jun 23 '15 at 09:52

2 Answers2

14

Here's the easy way I found out:

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

Refer to this page for details: http://sourceware.org/gdb/current/onlinedocs/gdb/Hooks.html#Hooks

Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985
neuron
  • 1,896
  • 1
  • 19
  • 24
5

Another "new" way to do it is with the Python Event interface:

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

 gdb.events.stop.connect (stop_handler)

which will trigger the stop_handler function each the the inferior stops.

There are two other similar events type:

events.cont
events.exited

respectively triggered when the inferior is continued or exists.

Kevin
  • 4,618
  • 3
  • 38
  • 61