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?
Just press c. It will continue execution until the next breakpoint.
It is often useful to do ' display/i $pc ' when stepping by machine instructions. This makes GDB automatically display the next instruction to be executed, each time your program stops.
continue (shorthand: c ) will resume execution until the next breakpoint is hit or the program exits. finish will run until the current function call completes and stop there.
You can use the finish command. finish : Continue running until just after function in the selected stack frame returns.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With