GDB/MI Notifications In Python (Debugging with GDB)

Next: Parameters In Python, Previous: GDB/MI Commands In Python, Up: Python API [Contents][Index]

#### 23.3.2.23 GDB/MI Notifications In Python

It is possible to emit GDB/MI notifications from Python. Use the `gdb.notify_mi` function to do that.

Function: gdb.notify_mi (name [, data])

  Emit a GDB/MI asynchronous notification. name is the name of the notification, consisting of alphanumeric characters and a hyphen (`-`). data is any additional data to be emitted with the notification, passed as a Python dictionary. This argument is optional. The dictionary is converted to a GDB/MI result records (see GDB/MI Output Syntax) the same way as result of Python MI command (see GDB/MI Commands In Python).

  If data is `None` then no additional values are emitted.

While using existing notification names (see GDB/MI Async Records) with `gdb.notify_mi` is allowed, users are encouraged to prefix user-defined notification with a hyphen (`-`) to avoid possible conflict. GDB will never introduce notification starting with hyphen.

Here is how to emit `=-connection-removed` whenever a connection to remote GDB server is closed (see Connections In Python):

    def notify_connection_removed(event):
        data = {"id": event.connection.num, "type": event.connection.type}
        gdb.notify_mi("-connection-removed", data)

    gdb.events.connection_removed.connect(notify_connection_removed)

Then, each time a connection is closed, there will be a notification on MI channel:

    =-connection-removed,id="1",type="remote"