public inbox for archer-commits@sourceware.org
help / color / mirror / Atom feed
* [SCM]  archer-pmuldoon-python-breakpoints: Implement breakpoint iterator, and other review requests.
@ 2010-10-13 10:43 pmuldoon
  0 siblings, 0 replies; only message in thread
From: pmuldoon @ 2010-10-13 10:43 UTC (permalink / raw)
  To: archer-commits

The branch, archer-pmuldoon-python-breakpoints has been updated
       via  74d8dadb4affedcfb27bef74e5e7f14db6f00150 (commit)
      from  ebc57bfe1060c5fc0c490b198803248f73871328 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email.

- Log -----------------------------------------------------------------
commit 74d8dadb4affedcfb27bef74e5e7f14db6f00150
Author: Phil Muldoon <pmuldoon@redhat.com>
Date:   Wed Oct 13 11:42:32 2010 +0100

    Implement breakpoint iterator, and other review requests.

-----------------------------------------------------------------------

Summary of changes:
 gdb/breakpoint.c           |   21 +++++++++
 gdb/breakpoint.h           |   18 +++++---
 gdb/python/py-breakpoint.c |  108 +++++++++++++++++++++++---------------------
 3 files changed, 89 insertions(+), 58 deletions(-)

First 500 lines of diff:
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index 47d5bf2..7ef97ec 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -345,6 +345,12 @@ static int executing_breakpoint_commands;
 /* Are overlay event breakpoints enabled? */
 static int overlay_events_enabled;
 
+/* Walk the following statement or block through all breakpoints.
+   ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current
+   breakpoint.  */
+
+#define ALL_BREAKPOINTS(B)  for (B = breakpoint_chain; B; B = B->next)
+
 #define ALL_BREAKPOINTS_SAFE(B,TMP)	\
 	for (B = breakpoint_chain;	\
 	     B ? (TMP=B->next, 1): 0;	\
@@ -11674,6 +11680,21 @@ save_command (char *arg, int from_tty)
   help_list (save_cmdlist, "save ", -1, gdb_stdout);
 }
 
+struct breakpoint *
+iterate_over_breakpoints (int (*callback) (struct breakpoint *, void *),
+			  void *data)
+{
+  struct breakpoint *b, *temp;
+
+  ALL_BREAKPOINTS_SAFE (b, temp)
+    {
+      if ((*callback) (b, data))
+	return b;
+    }
+
+  return NULL;
+}
+
 void
 _initialize_breakpoint (void)
 {
diff --git a/gdb/breakpoint.h b/gdb/breakpoint.h
index da4461a..d3fbc6a 100644
--- a/gdb/breakpoint.h
+++ b/gdb/breakpoint.h
@@ -32,13 +32,6 @@
 struct value;
 struct block;
 
-/* Walk the following statement or block through all breakpoints.
-   ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current
-   breakpoint.  */
-
-extern struct breakpoint *breakpoint_chain;
-#define ALL_BREAKPOINTS(B)  for (B = breakpoint_chain; B; B = B->next)
-
 /* This is the maximum number of bytes a breakpoint instruction can take.
    Feel free to increase it.  It's just used in a few places to size
    arrays that should be independent of the target architecture.  */
@@ -1132,4 +1125,15 @@ extern void check_tracepoint_command (char *line, void *closure);
 extern void start_rbreak_breakpoints (void);
 extern void end_rbreak_breakpoints (void);
 
+/* Breakpoint iterator function.
+
+   Calls a callback function once for each breakpoint, so long as the
+   callback function returns false.  If the callback function returns
+   true, the iteration will end and the current breakpoint will be
+   returned.  This can be useful for implementing a search for a
+   breakpoint with arbitrary attributes, or for applying an operation
+   to every breakpoint.  */
+extern struct breakpoint *iterate_over_breakpoints (int (*) (struct breakpoint *, 
+							     void *), void *);
+
 #endif /* !defined (BREAKPOINT_H) */
diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c
index a9a02f7..8d55230 100644
--- a/gdb/python/py-breakpoint.c
+++ b/gdb/python/py-breakpoint.c
@@ -570,8 +570,12 @@ bppy_new (PyTypeObject *subtype, PyObject *args, PyObject *kwargs)
 				     &spec, &type, &access_type, &internal))
     return NULL;
 
-  if (internal && PyObject_IsTrue (internal))
-    internal_bp = 1;
+  if (internal) 
+    {
+      internal_bp = PyObject_IsTrue (internal);
+      if (internal_bp == -1)
+	return NULL;
+    }
 
   result = subtype->tp_alloc (subtype, 0);
   if (! result)
@@ -625,40 +629,50 @@ bppy_new (PyTypeObject *subtype, PyObject *args, PyObject *kwargs)
 
 \f
 
+static int
+build_bp_list (struct breakpoint *b, void *arg)
+{
+  PyObject *list = arg;
+  PyObject *bp = b->py_bp_object;
+  int iserr = 0;
+
+  /* Not all breakpoints will have a companion Python object.
+     Only breakpoints that were created via bppy_new, or
+     breakpoints that were created externally and are tracked by
+     the Python Scripting API.  */
+  if (bp)
+    iserr = PyList_Append (list, bp);
+  
+  if (iserr == -1)
+    return 1;
+  
+  return 0;
+}
+
 /* Static function to return a tuple holding all breakpoints.  */
 
 PyObject *
 gdbpy_breakpoints (PyObject *self, PyObject *args)
 {
-  PyObject *result;
-  struct breakpoint *b;
+  PyObject *list;
 
   if (bppy_live == 0)
     Py_RETURN_NONE;
 
-  result = PyTuple_New (bppy_live);
-  if (result)
+  list = PyList_New (0);
+  if (!list)
+    return NULL;
+
+  /* If iteratre_over_breakpoints returns non NULL it signals an error
+     condition.  In that case abandon building the list and return
+     NULL.  */
+  if (iterate_over_breakpoints (build_bp_list, list) != NULL)
     {
-      int i = 0;
-      ALL_BREAKPOINTS (b)
-      {
-	/* Not all breakpoints will have a companion Python object.
-	   Only breakpoints that were created via bppy_new, or
-	   breakpoints that were created externally and are tracked by
-	   the Python Scripting API.  */
-	if (b->py_bp_object)
-	  {
-	    if (PyTuple_SetItem (result, i, (PyObject *) b->py_bp_object) != 0)
-	      {
-		Py_DECREF (result);
-		return NULL;
-	      }
-	    Py_INCREF (b->py_bp_object);
-	    ++i;
-	  }
-      }
+      Py_DECREF (list);
+      return NULL;
     }
-  return result;
+
+  return PyList_AsTuple (list);
 }
 
 \f
@@ -673,12 +687,14 @@ gdbpy_breakpoint_created (int num)
   breakpoint_object *newbp;
   struct breakpoint *bp = NULL;
   PyGILState_STATE state;
-  int error = 0;
 
   bp = get_breakpoint (num);
   if (! bp)
     return;
 
+  if (num < 0 && bppy_pending_object == NULL)
+    return;
+
   if (bp->type != bp_breakpoint 
       && bp->type != bp_watchpoint
       && bp->type != bp_hardware_watchpoint  
@@ -699,23 +715,17 @@ gdbpy_breakpoint_created (int num)
     {
       newbp->number = num;
       newbp->bp = bp;
-      newbp->bp->py_bp_object = (PyObject *)newbp;
+      newbp->bp->py_bp_object = (PyObject *) newbp;
       Py_INCREF (newbp);
+      ++bppy_live;
     }
   else
     {
       PyErr_SetString (PyExc_RuntimeError,
 		       _("Error while creating breakpoint from GDB."));
       gdbpy_print_stack ();
-      error = 1;
     }
 
-  if (! error)
-    ++bppy_live;
-
-  /* Just ignore errors here.  */
-  PyErr_Clear ();
-
   PyGILState_Release (state);
 }
 
@@ -725,25 +735,21 @@ static void
 gdbpy_breakpoint_deleted (int num)
 {
   PyGILState_STATE state;
-  struct breakpoint *b = NULL;
+  struct breakpoint *bp = NULL;
+  breakpoint_object *bp_obj;
 
   state = PyGILState_Ensure ();
-  ALL_BREAKPOINTS (b)
-  {
-    if (b->number == num)
-      {
-	breakpoint_object *bp_obj = 
-	  ((breakpoint_object *)b->py_bp_object);
-
-	if (bp_obj)
-	  {
-	    bp_obj->bp = NULL;
-	    --bppy_live;
-	    Py_DECREF (bp_obj);
-	  }
-	break;
-      }
-  }
+  bp = get_breakpoint (num);
+  if (! bp)
+    return;
+
+  bp_obj = ((breakpoint_object *) bp->py_bp_object);
+  if (bp_obj)
+    {
+      bp_obj->bp = NULL;
+      --bppy_live;
+      Py_DECREF (bp_obj);
+    }
   PyGILState_Release (state);
 }
 


hooks/post-receive
--
Repository for Project Archer.


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2010-10-13 10:43 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-10-13 10:43 [SCM] archer-pmuldoon-python-breakpoints: Implement breakpoint iterator, and other review requests pmuldoon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).