1 /* Python interface to inferior events.
3 Copyright (C) 2009-2012 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
23 evpy_dealloc (PyObject
*self
)
25 Py_XDECREF (((event_object
*) self
)->dict
);
26 self
->ob_type
->tp_free (self
);
30 create_event_object (PyTypeObject
*py_type
)
32 event_object
*event_obj
;
34 event_obj
= PyObject_New (event_object
, py_type
);
38 event_obj
->dict
= PyDict_New ();
42 return (PyObject
*) event_obj
;
45 Py_XDECREF (event_obj
);
49 /* Add the attribute ATTR to the event object EVENT. In
50 python this attribute will be accessible by the name NAME.
51 returns 0 if the operation succeeds and -1 otherwise. */
54 evpy_add_attribute (PyObject
*event
, char *name
, PyObject
*attr
)
56 return PyObject_SetAttrString (event
, name
, attr
);
59 /* Initialize the Python event code. */
62 gdbpy_initialize_event (void)
64 gdbpy_initialize_event_generic (&event_object_type
,
68 /* Initialize the given event type. If BASE is not NULL it will
69 be set as the types base.
70 Returns 0 if initialization was successful -1 otherwise. */
73 gdbpy_initialize_event_generic (PyTypeObject
*type
,
76 if (PyType_Ready (type
) < 0)
80 if (PyModule_AddObject (gdb_module
, name
, (PyObject
*) type
) < 0)
91 /* Notify the list of listens that the given EVENT has occurred.
92 returns 0 if emit is successful -1 otherwise. */
95 evpy_emit_event (PyObject
*event
,
96 eventregistry_object
*registry
)
98 PyObject
*callback_list_copy
= NULL
;
101 /* Create a copy of call back list and use that for
102 notifying listeners to avoid skipping callbacks
103 in the case of a callback being disconnected during
105 callback_list_copy
= PySequence_List (registry
->callbacks
);
106 if (!callback_list_copy
)
109 for (i
= 0; i
< PyList_Size (callback_list_copy
); i
++)
111 PyObject
*func
= PyList_GetItem (callback_list_copy
, i
);
116 if (!PyObject_CallFunctionObjArgs (func
, event
, NULL
))
118 /* Print the trace here, but keep going -- we want to try to
119 call all of the callbacks even if one is broken. */
120 gdbpy_print_stack ();
124 Py_XDECREF (callback_list_copy
);
129 gdbpy_print_stack ();
130 Py_XDECREF (callback_list_copy
);
135 PyTypeObject event_object_type
=
137 PyObject_HEAD_INIT (NULL
)
139 "gdb.Event", /* tp_name */
140 sizeof (event_object
), /* tp_basicsize */
142 evpy_dealloc
, /* tp_dealloc */
148 0, /* tp_as_number */
149 0, /* tp_as_sequence */
150 0, /* tp_as_mapping */
156 0, /* tp_as_buffer */
157 Py_TPFLAGS_DEFAULT
| Py_TPFLAGS_BASETYPE
, /* tp_flags */
158 "GDB event object", /* tp_doc */
161 0, /* tp_richcompare */
162 0, /* tp_weaklistoffset */
170 0, /* tp_descr_get */
171 0, /* tp_descr_set */
172 offsetof (event_object
, dict
), /* tp_dictoffset */