gdb: implement missing debug handler hook for Python
[binutils-gdb.git] / gdb / python / py-progspace.c
index f636ffd0460da6c96f4d071b83ce8a72884036ae..0797ef1fa6bf55ffed4900e7cb6d4f04f44cfea0 100644 (file)
@@ -55,6 +55,9 @@ struct pspace_object
 
   /* The debug method list.  */
   PyObject *xmethods;
+
+  /* The missing debug handler list.  */
+  PyObject *missing_debug_handlers;
 };
 
 extern PyTypeObject pspace_object_type
@@ -164,6 +167,7 @@ pspy_dealloc (PyObject *self)
   Py_XDECREF (ps_self->frame_unwinders);
   Py_XDECREF (ps_self->type_printers);
   Py_XDECREF (ps_self->xmethods);
+  Py_XDECREF (ps_self->missing_debug_handlers);
   Py_TYPE (self)->tp_free (self);
 }
 
@@ -199,6 +203,10 @@ pspy_initialize (pspace_object *self)
   if (self->xmethods == NULL)
     return 0;
 
+  self->missing_debug_handlers = PyList_New (0);
+  if (self->missing_debug_handlers == nullptr)
+    return 0;
+
   return 1;
 }
 
@@ -353,6 +361,47 @@ pspy_get_xmethods (PyObject *o, void *ignore)
   return self->xmethods;
 }
 
+/* Return the list of missing debug handlers for this program space.  */
+
+static PyObject *
+pspy_get_missing_debug_handlers (PyObject *o, void *ignore)
+{
+  pspace_object *self = (pspace_object *) o;
+
+  Py_INCREF (self->missing_debug_handlers);
+  return self->missing_debug_handlers;
+}
+
+/* Set this program space's list of missing debug handlers to HANDLERS.  */
+
+static int
+pspy_set_missing_debug_handlers (PyObject *o, PyObject *handlers,
+                                void *ignore)
+{
+  pspace_object *self = (pspace_object *) o;
+
+  if (handlers == nullptr)
+    {
+      PyErr_SetString (PyExc_TypeError,
+                      "cannot delete the missing debug handlers list");
+      return -1;
+    }
+
+  if (!PyList_Check (handlers))
+    {
+      PyErr_SetString (PyExc_TypeError,
+                      "the missing debug handlers attribute must be a list");
+      return -1;
+    }
+
+  /* Take care in case the LHS and RHS are related somehow.  */
+  gdbpy_ref<> tmp (self->missing_debug_handlers);
+  Py_INCREF (handlers);
+  self->missing_debug_handlers = handlers;
+
+  return 0;
+}
+
 /* Set the 'type_printers' attribute.  */
 
 static int
@@ -745,6 +794,8 @@ static gdb_PyGetSetDef pspace_getset[] =
     "Type printers.", NULL },
   { "xmethods", pspy_get_xmethods, NULL,
     "Debug methods.", NULL },
+  { "missing_debug_handlers", pspy_get_missing_debug_handlers,
+    pspy_set_missing_debug_handlers, "Missing debug handlers.", NULL },
   { NULL }
 };