GDB provides a general event facility so that Python code can be notified of various state changes, particularly changes that occur in the inferior.
An event is just an object that describes some state change. The type of the object and its attributes will vary depending on the details of the change. All the existing events are described below.
In order to be notified of an event, you must register an event handler
with an event registry. An event registry is an object in the
gdb.events module which dispatches particular events. A registry
provides methods to register and unregister event handlers:
objectto the registry. This object will be called when an event corresponding to this registry occurs.
objectfrom the registry. Once removed, the object will no longer receive notifications of events.
Here is an example:
def exit_handler (event): print "event type: exit" print "exit code: %d" % (event.exit_code) gdb.events.exited.connect (exit_handler)
In the above example we connect our handler
exit_handler to the
events.exited. Once connected,
called when the inferior exits. The argument event in this example is
gdb.ExitedEvent. As you can see in the example the
ExitedEvent object has an attribute which indicates the exit code of
The following is a listing of the event registries that are available and details of the events they emit:
Some events can be thread specific when GDB is running in non-stop
mode. When represented in Python, these events all extend
gdb.ThreadEvent. Note, this event is not emitted directly; instead,
events which are emitted by this or other modules might extend this event.
Examples of these events are
In non-stop mode this attribute will be set to the specific thread which was
involved in the emitted event. Otherwise, it will be set to
gdb.ContinueEvent which extends
This event indicates that the inferior has been continued after a stop. For
inherited attribute refer to
events.ExitedEvent which indicates that the inferior has exited.
events.ExitedEvent has two attributes:
An integer representing the exit code, if available, which the inferior has returned. (The exit code could be unavailable if, for example, GDB detaches from the inferior.) If the exit code is unavailable, the attribute does not exist.
A reference to the inferior which triggered the
gdb.StopEvent which extends
Indicates that the inferior has stopped. All events emitted by this registry
extend StopEvent. As a child of
will indicate the stopped thread when GDB is running in non-stop
mode. Refer to
gdb.ThreadEvent above for more details.
gdb.SignalEvent which extends
This event indicates that the inferior or one of its threads has received as
gdb.SignalEvent has the following attributes:
A string representing the signal received by the inferior. A list of possible
signal values can be obtained by running the command
info signals in
the GDB command prompt.
gdb.BreakpointEvent which extends
gdb.BreakpointEvent event indicates that one or more breakpoints have
been hit, and has the following attributes:
A sequence containing references to all the breakpoints (type
gdb.Breakpoint) that were hit.
See Breakpoints In Python, for details of the
A reference to the first breakpoint that was hit.
This function is maintained for backward compatibility and is now deprecated
in favor of the
gdb.NewObjFileEvent which indicates that a new object file has
been loaded by GDB.
gdb.NewObjFileEvent has one attribute:
A reference to the object file (
gdb.Objfile) which has been loaded.
See Objfiles In Python, for details of the
gdb.ClearObjFilesEvent which indicates that the list of object
files for a program space has been reset.
gdb.ClearObjFilesEvent has one attribute:
A reference to the program space (
gdb.Progspace) whose objfile list has
been cleared. See Progspaces In Python.
Emits events just before and after a function in the inferior is
called by GDB. Before an inferior call, this emits an event
gdb.InferiorCallPreEvent, and after an inferior call,
this emits an event of type
Indicates that a function in the inferior is about to be called.
The thread in which the call will be run.
The location of the function to be called.
Indicates that a function in the inferior has just been called.
The thread in which the call was run.
The location of the function that was called.
gdb.MemoryChangedEvent which indicates that the memory of the
inferior has been modified by the GDB user, for instance via a
set *addr = value. The event has the following
gdb.RegisterChangedEvent which indicates that a register in the
inferior has been modified by the GDB user.
This is emitted when a new breakpoint has been created. The argument
that is passed is the new
This is emitted when a breakpoint has been modified in some way. The
argument that is passed is the new
This is emitted when a breakpoint has been deleted. The argument that
is passed is the
gdb.Breakpoint object. When this event is
gdb.Breakpoint object will already be in its
invalid state; that is, the
is_valid method will return
This event carries no payload. It is emitted each time GDB presents a prompt to the user.
This is emitted when a new inferior is created. Note that the inferior is not necessarily running; in fact, it may not even have an associated executable.
The event is of type
gdb.NewInferiorEvent. This has a single
This is emitted when an inferior has been deleted. Note that this is
not the same as process exit; it is notified when the inferior itself
is removed, say via
The event is of type
gdb.InferiorDeletedEvent. This has a single
This is emitted when GDB notices a new thread. The event is of
gdb.NewThreadEvent, which extends
This has a single attribute: