Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Kevin Pouget <kevin.pouget@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>, Pedro Alves <pedro@codesourcery.com>
Cc: tromey@redhat.com, gdb-patches@sourceware.org
Subject: Re: [PATCH] Handle multiple breakpoint hits in Python interface
Date: Thu, 01 Sep 2011 11:41:00 -0000	[thread overview]
Message-ID: <CAPftXUJgB7iXt7yQcj4H9ywte_kw9i7Zk2djDT=MLNGEURmU1A@mail.gmail.com> (raw)
In-Reply-To: <E1Qz4G6-0006mK-Uf@fencepost.gnu.org>

[-- Attachment #1: Type: text/plain, Size: 2983 bytes --]

On Thu, Sep 1, 2011 at 11:56 AM, Pedro Alves <pedro@codesourcery.com> wrote:
> Please teach your browser to attach files to gmail as
> some text based content type, like patch/diff or
> text/x-patch.

I'm sorry for that, it was on purpose that I removed the '.patch', but
I actually mixed up everything ...
From now one there should be no problem, I'll take extra care about
it, thanks for the tip (I guess there is no way to clean up the
archive ... ?)

On Thu, Sep 1, 2011 at 12:12 PM, Eli Zaretskii <eliz@gnu.org> wrote:
>> +  ** The "gdb.breakpoint" function has been deprecated and in favor of
>> +     "gdb.breakpoints".
>
> Without the "and", this is okay.

done

>> +@code{gdb.BreakpointEvent} event indicates that one or several breakpoints have
>                                                   ^^^^^^^^^^^^^^
> "one or more"

done

>> +@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.
>> +@defivar BreakpointEvent breakpoint
>
> This cannot be right: each @defivar should end with the corresponding
> "@end defivar".  Didn't makeinfo bitch at you?

yes sorry it does; I naïvely expected `make' to build --and crash--
the documentation

>> +A reference to the first breakpoint that was hit of type @code{gdb.Breakpoint}.
>
> As opposed to what? watchpoints, catchpoints etc.?  IOW, why do you
> need to mention the type issue?

these are not my words, I just updated the sentence to mention that
it's now deprecated.
But you're right, it is redundant with "(type @code{gdb.Breakpoint})"
mentioned in the previous lines (I removed it).

I understand this precision as a way to tell the Python type of the
object, and/or that it's a breakpoint hit, and nothing else
(watchpoints/catchpoints are not handled in Python yet, AFAIK)


Cordially,

Kevin

--

2011-04-30  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-04-30  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-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.

[-- Attachment #2: 0001-Handle-multiple-breakpoint-hits-in-Python-interface.patch --]
[-- Type: text/x-patch, Size: 7444 bytes --]

From 71b7f9086f3cab392459dabf102f33d0d88053a8 Mon Sep 17 00:00:00 2001
From: Kevin Pouget <kevin.pouget@st.com>
Date: Thu, 1 Sep 2011 10:27:09 +0200
Subject: [PATCH] Handle multiple breakpoint hits in Python interface

---
 gdb/NEWS                               |    3 ++
 gdb/doc/gdb.texinfo                    |   13 ++++++---
 gdb/python/py-bpevent.c                |    8 ++++-
 gdb/python/py-stopevent.c              |   43 +++++++++++++++++++++++++------
 gdb/python/py-stopevent.h              |    3 +-
 gdb/testsuite/gdb.python/py-events.exp |    3 ++
 gdb/testsuite/gdb.python/py-events.py  |    4 ++-
 7 files changed, 60 insertions(+), 17 deletions(-)

diff --git a/gdb/NEWS b/gdb/NEWS
index 255a22e..2c27337 100644
--- 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
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 23b2a98..ca8b50e 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -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
diff --git a/gdb/python/py-bpevent.c b/gdb/python/py-bpevent.c
index c7f7965..f37b248 100644
--- a/gdb/python/py-bpevent.c
+++ b/gdb/python/py-bpevent.c
@@ -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;
diff --git a/gdb/python/py-stopevent.c b/gdb/python/py-stopevent.c
index 122fe6b..1ecbe6c 100644
--- a/gdb/python/py-stopevent.c
+++ b/gdb/python/py-stopevent.c
@@ -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,
diff --git a/gdb/python/py-stopevent.h b/gdb/python/py-stopevent.h
index 52f3511..85ac4d3 100644
--- a/gdb/python/py-stopevent.h
+++ b/gdb/python/py-stopevent.h
@@ -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);
 
diff --git a/gdb/testsuite/gdb.python/py-events.exp b/gdb/testsuite/gdb.python/py-events.exp
index e5d6daf..8eff165 100644
--- a/gdb/testsuite/gdb.python/py-events.exp
+++ b/gdb/testsuite/gdb.python/py-events.exp
@@ -45,12 +45,15 @@ 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.
diff --git a/gdb/testsuite/gdb.python/py-events.py b/gdb/testsuite/gdb.python/py-events.py
index 9f05b9f..10aea4f 100644
--- a/gdb/testsuite/gdb.python/py-events.py
+++ b/gdb/testsuite/gdb.python/py-events.py
@@ -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:
-- 
1.7.6


  reply	other threads:[~2011-09-01 11:29 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <BANLkTik-ffBpfx4BALF5+Y0xSx_NnaCs7g@mail.gmail.com>
2011-04-22  9:34 ` Kevin Pouget
2011-05-19 18:34   ` Tom Tromey
2011-05-23  9:39     ` Kevin Pouget
2011-05-23 10:51       ` Eli Zaretskii
2011-05-23 11:01         ` Kevin Pouget
2011-05-23 11:59           ` Eli Zaretskii
2011-05-27 20:09       ` Tom Tromey
2011-05-30  7:37         ` Kevin Pouget
2011-05-30  7:49           ` Eli Zaretskii
2011-05-30 10:53             ` Kevin Pouget
2011-08-31 17:49               ` Tom Tromey
2011-09-01  8:36                 ` Kevin Pouget
2011-09-01  8:52                   ` Kevin Pouget
2011-09-01 10:08                     ` Pedro Alves
2011-09-01 10:18                   ` Eli Zaretskii
2011-09-01 11:41                     ` Kevin Pouget [this message]
2011-09-01 15:39                       ` Pedro Alves
2011-09-01 20:53                       ` Eli Zaretskii
2011-09-15 12:34                         ` Kevin Pouget
2011-09-16  7:55                           ` [commit] gdb.python/py-evthreads.exp regression [Re: [PATCH] Handle multiple breakpoint hits in Python interface] Jan Kratochvil
2011-09-16  9:12                             ` Kevin Pouget

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAPftXUJgB7iXt7yQcj4H9ywte_kw9i7Zk2djDT=MLNGEURmU1A@mail.gmail.com' \
    --to=kevin.pouget@gmail.com \
    --cc=eliz@gnu.org \
    --cc=gdb-patches@sourceware.org \
    --cc=pedro@codesourcery.com \
    --cc=tromey@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox