2011-09-15 Kevin Pouget <kevin.pouget@st.com>
authorKevin Pouget <kpouget@sourceware.org>
Thu, 15 Sep 2011 12:27:20 +0000 (12:27 +0000)
committerKevin Pouget <kpouget@sourceware.org>
Thu, 15 Sep 2011 12:27:20 +0000 (12:27 +0000)
Handle multiple breakpoint hits in Python interface:
* python/py-bpevent.c (create_breakpoint_event_object): Rename C/Python
variable to breakpoints.
* python/py-stopevent.c (emit_stop_event): Return a Python tuple of
bps instead of single breakpoint. Fix some space typos.
* python/py-stopevent.c (create_breakpoint_event_object): Rename
variable to breakpoints.

testsuite:
* gdb.python/py-events.exp: Set a duplicate breakpoint and check its
presence.
* gdb.python/py-events.py (breakpoint_stop_handler): Browse all the
breakpoint hits.

doc:
* gdb.texinfo (Events In Python): New function documentation:
gdb.BreakpointEvent.breakpoints. Indicate that
gdb.BreakpointEvent.breakpoint is now deprecated.

gdb/ChangeLog
gdb/NEWS
gdb/doc/ChangeLog
gdb/doc/gdb.texinfo
gdb/python/py-bpevent.c
gdb/python/py-stopevent.c
gdb/python/py-stopevent.h
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.python/py-events.exp
gdb/testsuite/gdb.python/py-events.py

index 18af26c39237327b4f02437d48543794f0e71272..380f75fd5098778c434893397b27154eaaaa4570 100644 (file)
@@ -1,3 +1,13 @@
+2011-09-15  Kevin Pouget  <kevin.pouget@st.com>
+
+       Handle multiple breakpoint hits in Python interface:
+       * python/py-bpevent.c (create_breakpoint_event_object): Rename C/Python
+       variable to breakpoints.
+       * python/py-stopevent.c (emit_stop_event): Return a Python tuple of
+       bps instead of single breakpoint. Fix some space typos.
+       * python/py-stopevent.c (create_breakpoint_event_object): Rename
+       variable to breakpoints.
+
 2011-09-15  Kevin Pouget  <kevin.pouget@st.com>
 
        * breakpoint.c (describe_other_breakpoints): Do not write 'duplicate'
index 6665bdd95ca205470313cc7581d10c96884eb100..20e58a0d18b596c3ea1f417b2d6ec6d2268251e9 100644 (file)
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -38,6 +38,9 @@
 
   ** Symbols now provide the "type" attribute, the type of the symbol.
 
+  ** The "gdb.breakpoint" function has been deprecated in favor of
+     "gdb.breakpoints".
+
 * libthread-db-search-path now supports two special values: $sdir and $pdir.
   $sdir specifies the default system locations of shared libraries.
   $pdir specifies the directory where the libpthread used by the application
index e5d2161aa4e21b2ab5093cd1264bdabbe24883c2..54dd4e885c295415986ada416d9cebfd18778355 100644 (file)
@@ -1,3 +1,10 @@
+2011-09-15  Kevin Pouget  <kevin.pouget@st.com>
+
+       Handle multiple breakpoint hits in Python interface:
+       * gdb.texinfo (Events In Python): New function documentation:
+       gdb.BreakpointEvent.breakpoints. Indicate that
+       gdb.BreakpointEvent.breakpoint is now deprecated.
+
 2011-09-04  Joel Brobecker  <brobecker@adacore.com>
 
        * gdb.texinfo: Set EDITION to "Tenth" and change ISBN.
index ccef92cf7ca18096c6243f6a7e589002d2a8841f..76c804b9c7c95e357d856549dfb05fdea1dd44df 100644 (file)
@@ -22317,14 +22317,19 @@ the @value{GDBN} command prompt.
 
 Also emits  @code{gdb.BreakpointEvent} which extends @code{gdb.StopEvent}.
 
-@code{gdb.BreakpointEvent} event indicates that a breakpoint has been hit, and
-has the following attributes:
+@code{gdb.BreakpointEvent} event indicates that one or more breakpoints have
+been hit, and has the following attributes:
 
 @table @code
-@defivar BreakpointEvent breakpoint
-A reference to the breakpoint that was hit of type @code{gdb.Breakpoint}.
+@defivar BreakpointEvent breakpoints
+A sequence containing references to all the breakpoints (type 
+@code{gdb.Breakpoint}) that were hit.
 @xref{Breakpoints In Python}, for details of the @code{gdb.Breakpoint} object.
 @end defivar
+@defivar BreakpointEvent breakpoint
+A reference to the first breakpoint that was hit.
+This function is maintained for backward compatibility and is now deprecated 
+in favor of the @code{gdb.BreakpointEvent.breakpoints} function.
 @end table
 
 @end table
index c7f79654a16d5c66cab856c147a6e68761fcf8b8..f37b2486b3609fac8a6861cbf4f94f60eae34498 100644 (file)
@@ -24,7 +24,7 @@ static PyTypeObject breakpoint_event_object_type;
 /* Create and initialize a BreakpointEvent object.  */
 
 PyObject *
-create_breakpoint_event_object (PyObject *breakpoint)
+create_breakpoint_event_object (PyObject *breakpoint_list, PyObject *first_bp)
 {
   PyObject *breakpoint_event_obj =
       create_stop_event_object (&breakpoint_event_object_type);
@@ -34,7 +34,11 @@ create_breakpoint_event_object (PyObject *breakpoint)
 
   if (evpy_add_attribute (breakpoint_event_obj,
                           "breakpoint",
-                          breakpoint) < 0)
+                          first_bp) < 0)
+    goto fail;
+  if (evpy_add_attribute (breakpoint_event_obj,
+                          "breakpoints",
+                          breakpoint_list) < 0)
     goto fail;
 
   return breakpoint_event_obj;
index 122fe6bec38acf6f8f6207ea73e7a6058c255c66..1ecbe6c9c8463a847b7dc5b27fde626a42eee509 100644 (file)
@@ -45,18 +45,42 @@ int
 emit_stop_event (struct bpstats *bs, enum target_signal stop_signal)
 {
   PyObject *stop_event_obj = NULL; /* Appease GCC warning.  */
+  PyObject *list = NULL;
+  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 (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 = PyList_New (0);
+              if (!list)
+                goto fail;
+            }
+
+          if (PyList_Append (list, current_py_bp))
+            goto fail;
+
+          if (first_bp == NULL)
+            first_bp = current_py_bp;
+        }
+    }
+
+  if (list != NULL)
+    {
+      stop_event_obj = create_breakpoint_event_object (list, first_bp);
       if (!stop_event_obj)
-       goto fail;
+        goto fail;
     }
 
   /* Check if the signal is "Signal 0" or "Trace/breakpoint trap".  */
@@ -75,13 +99,14 @@ emit_stop_event (struct bpstats *bs, enum target_signal stop_signal)
     {
       stop_event_obj = create_stop_event_object (&stop_event_object_type);
       if (!stop_event_obj)
-       goto fail;
+        goto fail;
     }
 
   return evpy_emit_event (stop_event_obj, gdb_py_events.stop);
 
-  fail:
-   return -1;
+ fail:
+  Py_XDECREF (list);
+  return -1;
 }
 
 GDBPY_NEW_EVENT_TYPE (stop,
index 52f3511df39c674c888a60d9b4443daf3c2431f0..85ac4d37059e64ce92c4d7342b64c0d765f3bac1 100644 (file)
@@ -28,7 +28,8 @@ extern void stop_evpy_dealloc (PyObject *self);
 extern int emit_stop_event (struct bpstats *bs,
                             enum target_signal stop_signal);
 
-extern PyObject *create_breakpoint_event_object (PyObject *breakpoint);
+extern PyObject *create_breakpoint_event_object (PyObject *breakpoint_list,
+                                                 PyObject *first_bp);
 
 extern PyObject *create_signal_event_object (enum target_signal stop_signal);
 
index 62eb29133770233a6828c156ed75837b20ce5c8b..c33f55b503c98898081b93ea44c71b5673a02219 100644 (file)
@@ -1,3 +1,11 @@
+2011-04-30  Kevin Pouget  <kevin.pouget@st.com>
+
+       Handle multiple breakpoint hits in Python interface:
+       * gdb.python/py-events.exp: Set a duplicate breakpoint and check its
+       presence.
+       * gdb.python/py-events.py (breakpoint_stop_handler): Browse all the
+       breakpoint hits.
+
 2011-09-13  Sami Wagiaalla  <swagiaal@redhat.com>
            Jan Kratochvil  <jan.kratochvil@redhat.com>
 
index 849380901028624cea8385c62aa22df06b787dde..2d2139d1fd28030f9ca9e66945878233e5c8a4c5 100644 (file)
@@ -39,13 +39,16 @@ if ![runto_main ] then {
 
 gdb_test "Test_Events" "Event testers registered."
 
+gdb_breakpoint "first"
 gdb_breakpoint "first"
 
 # Test continue event and breakpoint stop event
 gdb_test "continue" ".*event type: continue.*
 .*event type: stop.*
 .*stop reason: breakpoint.*
+.*first breakpoint number: 2.*
 .*breakpoint number: 2.*
+.*breakpoint number: 3.*
 all threads stopped"
 
 #test exited event.
index 9f05b9f03c11d97f23226e13cb9ef271ff3c4f11..10aea4f5d218c74f603cf166f35c7494d707f67f 100644 (file)
@@ -31,7 +31,9 @@ def breakpoint_stop_handler (event):
         print "event type: stop"
     if (isinstance (event, gdb.BreakpointEvent)):
         print "stop reason: breakpoint"
-        print "breakpoint number: %s" % (event.breakpoint.number)
+        print "first breakpoint number: %s" % (event.breakpoint.number)
+        for bp in event.breakpoints:
+               print "breakpoint number: %s" % (bp.number)
         if ( event.inferior_thread is not None) :
             print "thread num: %s" % (event.inferior_thread.num);
         else: