ld-checks: tweak overflow checks.
[deliverable/binutils-gdb.git] / gdb / python / py-stopevent.c
index 122fe6bec38acf6f8f6207ea73e7a6058c255c66..cfa45918625d3234aa665b4a6a6ba4896c484cb6 100644 (file)
@@ -1,6 +1,6 @@
 /* Python interface to inferior stop events.
 
-   Copyright (C) 2009, 2010, 2011 Free Software Foundation, Inc.
+   Copyright (C) 2009-2017 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 *
 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;
+  return create_thread_event_object (py_type);
 }
 
 /* Callback observers when a stop event occurs.  This function will create a
@@ -42,51 +34,71 @@ create_stop_event_object (PyTypeObject *py_type)
    returns -1.  */
 
 int
-emit_stop_event (struct bpstats *bs, enum target_signal stop_signal)
+emit_stop_event (struct bpstats *bs, enum gdb_signal stop_signal)
 {
-  PyObject *stop_event_obj = NULL; /* Appease GCC warning.  */
+  gdbpy_ref<> stop_event_obj;
+  gdbpy_ref<> list;
+  PyObject *first_bp = NULL;
+  struct bpstats *current_bs;
 
   if (evregpy_no_listeners_p (gdb_py_events.stop))
     return 0;
 
-  if (bs && bs->breakpoint_at
-      && bs->breakpoint_at->py_bp_object)
+  /* Add any breakpoint set at this location to the list.  */
+  for (current_bs = bs; current_bs != NULL; current_bs = current_bs->next)
     {
-      stop_event_obj = create_breakpoint_event_object ((PyObject *) bs
-                                                       ->breakpoint_at
-                                                       ->py_bp_object);
-      if (!stop_event_obj)
-       goto fail;
+      if (current_bs->breakpoint_at
+          && current_bs->breakpoint_at->py_bp_object)
+        {
+          PyObject *current_py_bp =
+              (PyObject *) current_bs->breakpoint_at->py_bp_object;
+
+          if (list == NULL)
+            {
+              list.reset (PyList_New (0));
+              if (list == NULL)
+               return -1;
+            }
+
+          if (PyList_Append (list.get (), current_py_bp))
+           return -1;
+
+          if (first_bp == NULL)
+            first_bp = current_py_bp;
+        }
+    }
+
+  if (list != NULL)
+    {
+      stop_event_obj.reset (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 != TARGET_SIGNAL_0
-      && stop_signal != TARGET_SIGNAL_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.reset (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;
+      stop_event_obj.reset (create_stop_event_object (&stop_event_object_type));
+      if (stop_event_obj == NULL)
+       return -1;
     }
 
-  return evpy_emit_event (stop_event_obj, gdb_py_events.stop);
-
-  fail:
-   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*/);
+                      thread_event_object_type);
This page took 0.025337 seconds and 4 git commands to generate.