arm, objdump: print obsolote warning when 26-bit set in instructions
[binutils-gdb.git] / gdb / python / py-evtregistry.c
blob7ae3997ec9ed6c8082b5699be36179656cad5cb4
1 /* Python interface to inferior thread event registries.
3 Copyright (C) 2009-2024 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/>. */
20 #include "command.h"
21 #include "py-events.h"
23 events_object gdb_py_events;
25 extern PyTypeObject eventregistry_object_type
26 CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("eventregistry_object");
28 /* Implementation of EventRegistry.connect () -> NULL.
29 Add FUNCTION to the list of listeners. */
31 static PyObject *
32 evregpy_connect (PyObject *self, PyObject *function)
34 PyObject *func;
35 PyObject *callback_list = (((eventregistry_object *) self)->callbacks);
37 if (!PyArg_ParseTuple (function, "O", &func))
38 return NULL;
40 if (!PyCallable_Check (func))
42 PyErr_SetString (PyExc_RuntimeError, "Function is not callable");
43 return NULL;
46 if (PyList_Append (callback_list, func) < 0)
47 return NULL;
49 Py_RETURN_NONE;
52 /* Implementation of EventRegistry.disconnect () -> NULL.
53 Remove FUNCTION from the list of listeners. */
55 static PyObject *
56 evregpy_disconnect (PyObject *self, PyObject *function)
58 PyObject *func;
59 int index;
60 PyObject *callback_list = (((eventregistry_object *) self)->callbacks);
62 if (!PyArg_ParseTuple (function, "O", &func))
63 return NULL;
65 index = PySequence_Index (callback_list, func);
66 if (index < 0)
67 Py_RETURN_NONE;
69 if (PySequence_DelItem (callback_list, index) < 0)
70 return NULL;
72 Py_RETURN_NONE;
75 /* Create a new event registry. This function uses PyObject_New
76 and therefore returns a new reference that callers must handle. */
78 eventregistry_object *
79 create_eventregistry_object (void)
81 gdbpy_ref<eventregistry_object>
82 eventregistry_obj (PyObject_New (eventregistry_object,
83 &eventregistry_object_type));
85 if (eventregistry_obj == NULL)
86 return NULL;
88 eventregistry_obj->callbacks = PyList_New (0);
89 if (!eventregistry_obj->callbacks)
90 return NULL;
92 return eventregistry_obj.release ();
95 static void
96 evregpy_dealloc (PyObject *self)
98 Py_XDECREF (((eventregistry_object *) self)->callbacks);
99 Py_TYPE (self)->tp_free (self);
102 /* Initialize the Python event registry code. */
104 static int CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
105 gdbpy_initialize_eventregistry (void)
107 return gdbpy_type_ready (&eventregistry_object_type);
110 /* Return the number of listeners currently connected to this
111 registry. */
113 bool
114 evregpy_no_listeners_p (eventregistry_object *registry)
116 /* REGISTRY can be nullptr if gdb failed to find the data directory
117 at startup. */
118 return registry == nullptr || PyList_Size (registry->callbacks) == 0;
121 GDBPY_INITIALIZE_FILE (gdbpy_initialize_eventregistry);
123 static PyMethodDef eventregistry_object_methods[] =
125 { "connect", evregpy_connect, METH_VARARGS, "Add function" },
126 { "disconnect", evregpy_disconnect, METH_VARARGS, "Remove function" },
127 { NULL } /* Sentinel. */
130 PyTypeObject eventregistry_object_type =
132 PyVarObject_HEAD_INIT (NULL, 0)
133 "gdb.EventRegistry", /* tp_name */
134 sizeof (eventregistry_object), /* tp_basicsize */
135 0, /* tp_itemsize */
136 evregpy_dealloc, /* tp_dealloc */
137 0, /* tp_print */
138 0, /* tp_getattr */
139 0, /* tp_setattr */
140 0, /* tp_compare */
141 0, /* tp_repr */
142 0, /* tp_as_number */
143 0, /* tp_as_sequence */
144 0, /* tp_as_mapping */
145 0, /* tp_hash */
146 0, /* tp_call */
147 0, /* tp_str */
148 0, /* tp_getattro */
149 0, /* tp_setattro */
150 0, /* tp_as_buffer */
151 Py_TPFLAGS_DEFAULT, /* tp_flags */
152 "GDB event registry object", /* tp_doc */
153 0, /* tp_traverse */
154 0, /* tp_clear */
155 0, /* tp_richcompare */
156 0, /* tp_weaklistoffset */
157 0, /* tp_iter */
158 0, /* tp_iternext */
159 eventregistry_object_methods, /* tp_methods */
160 0, /* tp_members */
161 0, /* tp_getset */
162 0, /* tp_base */
163 0, /* tp_dict */
164 0, /* tp_descr_get */
165 0, /* tp_descr_set */
166 0, /* tp_dictoffset */
167 0, /* tp_init */
168 0 /* tp_alloc */