Add "info connections" command, "info inferiors" connection number/string
[deliverable/binutils-gdb.git] / gdb / python / py-stopevent.c
index d351915951fee242dd2875420b3950e569c6c406..98c8b20c33b006d3a623fad3532c072ab67a7ddd 100644 (file)
@@ -1,6 +1,6 @@
 /* Python interface to inferior stop events.
 
-   Copyright (C) 2009-2012 Free Software Foundation, Inc.
+   Copyright (C) 2009-2020 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
+#include "defs.h"
 #include "py-stopevent.h"
 
-PyObject *
+gdbpy_ref<>
 create_stop_event_object (PyTypeObject *py_type)
 {
-  PyObject *stop_event_obj = create_thread_event_object (py_type);
-
-  if (!stop_event_obj)
-    goto fail;
-
-  return stop_event_obj;
-
-  fail:
-   Py_XDECREF (stop_event_obj);
-   return NULL;
+  gdbpy_ref<> thread = py_get_event_thread (inferior_ptid);
+  return create_thread_event_object (py_type, thread.get ());
 }
 
 /* Callback observers when a stop event occurs.  This function will create a
@@ -44,8 +37,8 @@ create_stop_event_object (PyTypeObject *py_type)
 int
 emit_stop_event (struct bpstats *bs, enum gdb_signal stop_signal)
 {
-  PyObject *stop_event_obj = NULL; /* Appease GCC warning.  */
-  PyObject *list = NULL;
+  gdbpy_ref<> stop_event_obj;
+  gdbpy_ref<> list;
   PyObject *first_bp = NULL;
   struct bpstats *current_bs;
 
@@ -63,13 +56,13 @@ emit_stop_event (struct bpstats *bs, enum gdb_signal stop_signal)
 
           if (list == NULL)
             {
-              list = PyList_New (0);
-              if (!list)
-                goto fail;
+              list.reset (PyList_New (0));
+              if (list == NULL)
+               return -1;
             }
 
-          if (PyList_Append (list, current_py_bp))
-            goto fail;
+          if (PyList_Append (list.get (), current_py_bp))
+           return -1;
 
           if (first_bp == NULL)
             first_bp = current_py_bp;
@@ -78,41 +71,29 @@ emit_stop_event (struct bpstats *bs, enum gdb_signal stop_signal)
 
   if (list != NULL)
     {
-      stop_event_obj = create_breakpoint_event_object (list, first_bp);
-      if (!stop_event_obj)
-        goto fail;
-      Py_DECREF (list);
+      stop_event_obj = create_breakpoint_event_object (list.get (),
+                                                      first_bp);
+      if (stop_event_obj == NULL)
+       return -1;
     }
 
   /* Check if the signal is "Signal 0" or "Trace/breakpoint trap".  */
   if (stop_signal != GDB_SIGNAL_0
       && stop_signal != GDB_SIGNAL_TRAP)
     {
-      stop_event_obj =
-         create_signal_event_object (stop_signal);
-      if (!stop_event_obj)
-       goto fail;
+      stop_event_obj = create_signal_event_object (stop_signal);
+      if (stop_event_obj == NULL)
+       return -1;
     }
 
   /* If all fails emit an unknown stop event.  All event types should
      be known and this should eventually be unused.  */
-  if (!stop_event_obj)
+  if (stop_event_obj == NULL)
     {
       stop_event_obj = create_stop_event_object (&stop_event_object_type);
-      if (!stop_event_obj)
-        goto fail;
+      if (stop_event_obj == NULL)
+       return -1;
     }
 
-  return evpy_emit_event (stop_event_obj, gdb_py_events.stop);
-
- fail:
-  Py_XDECREF (list);
-  return -1;
+  return evpy_emit_event (stop_event_obj.get (), gdb_py_events.stop);
 }
-
-GDBPY_NEW_EVENT_TYPE (stop,
-                      "gdb.StopEvent",
-                      "StopEvent",
-                      "GDB stop event object",
-                      thread_event_object_type,
-                      /*no qual*/);
This page took 0.041408 seconds and 4 git commands to generate.