From: Kevin Pouget Date: Thu, 15 Sep 2011 12:27:20 +0000 (+0000) Subject: 2011-09-15 Kevin Pouget X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=6839b47f2b1cd56c90dc38da7bb612df7e052d90;p=binutils-gdb.git 2011-09-15 Kevin Pouget 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. --- diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 18af26c3923..380f75fd509 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,13 @@ +2011-09-15 Kevin Pouget + + 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 * breakpoint.c (describe_other_breakpoints): Do not write 'duplicate' diff --git a/gdb/NEWS b/gdb/NEWS index 6665bdd95ca..20e58a0d18b 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/ChangeLog b/gdb/doc/ChangeLog index e5d2161aa4e..54dd4e885c2 100644 --- a/gdb/doc/ChangeLog +++ b/gdb/doc/ChangeLog @@ -1,3 +1,10 @@ +2011-09-15 Kevin Pouget + + 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 * gdb.texinfo: Set EDITION to "Tenth" and change ISBN. diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index ccef92cf7ca..76c804b9c7c 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 c7f79654a16..f37b2486b36 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 122fe6bec38..1ecbe6c9c84 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 52f3511df39..85ac4d37059 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/ChangeLog b/gdb/testsuite/ChangeLog index 62eb2913377..c33f55b503c 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,11 @@ +2011-04-30 Kevin Pouget + + 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 Jan Kratochvil diff --git a/gdb/testsuite/gdb.python/py-events.exp b/gdb/testsuite/gdb.python/py-events.exp index 84938090102..2d2139d1fd2 100644 --- a/gdb/testsuite/gdb.python/py-events.exp +++ b/gdb/testsuite/gdb.python/py-events.exp @@ -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. diff --git a/gdb/testsuite/gdb.python/py-events.py b/gdb/testsuite/gdb.python/py-events.py index 9f05b9f03c1..10aea4f5d21 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: