public inbox for archer-commits@sourceware.org
help / color / mirror / Atom feed
* [SCM]  archer-pmuldoon-python-breakpoints: Review changes Mar 10th
@ 2011-03-10 15:10 pmuldoon
  0 siblings, 0 replies; only message in thread
From: pmuldoon @ 2011-03-10 15:10 UTC (permalink / raw)
  To: archer-commits

The branch, archer-pmuldoon-python-breakpoints has been updated
       via  30a9c263e61fa56df113230d5ef06775edc38e85 (commit)
      from  4a9147d74d8eecb3b3b7edb5aa61ec772c27838f (commit)

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

- Log -----------------------------------------------------------------
commit 30a9c263e61fa56df113230d5ef06775edc38e85
Author: Phil Muldoon <pmuldoon@redhat.com>
Date:   Thu Mar 10 15:09:38 2011 +0000

    Review changes Mar 10th

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

Summary of changes:
 gdb/breakpoint.c                           |   11 ++--
 gdb/python/py-breakpoint.c                 |   71 +++++++++++++++++++++++----
 gdb/python/python.c                        |   16 ++++++
 gdb/python/python.h                        |    4 +-
 gdb/testsuite/gdb.python/py-breakpoint.exp |    6 +-
 5 files changed, 87 insertions(+), 21 deletions(-)

First 500 lines of diff:
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index a0bafdc..f728021 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -72,10 +72,7 @@
 #undef savestring
 
 #include "mi/mi-common.h"
-
-#if HAVE_PYTHON
 #include "python/python.h"
-#endif
 
 /* Arguments to pass as context to some catch command handlers.  */
 #define CATCH_PERMANENT ((void *) (uintptr_t) 0)
@@ -647,6 +644,9 @@ condition_command (char *arg, int from_tty)
   ALL_BREAKPOINTS (b)
     if (b->number == bnum)
       {
+	if (gdbpy_breakpoint_has_py_cond (b->py_bp_object))
+	  error (_("Cannot set a condition where a Python 'should_stop' " \
+		   "method has been defined in the breakpoint."));
 	set_breakpoint_condition (b, p, from_tty);
 	return;
       }
@@ -4074,12 +4074,11 @@ bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid)
       int value_is_zero = 0;
       struct expression *cond;
 
-#if HAVE_PYTHON
       /* Evaluate Python breakpoints that have a "condition"
 	 method implemented.  */
       if (b->py_bp_object)
-	bs->stop = gdbpy_stop_p (b->py_bp_object);
-#endif
+	bs->stop = gdbpy_should_stop (b->py_bp_object);
+
       if (is_watchpoint (b))
 	cond = b->cond_exp;
       else
diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c
index 4551416..1069dd5 100644
--- a/gdb/python/py-breakpoint.c
+++ b/gdb/python/py-breakpoint.c
@@ -40,6 +40,9 @@ static int bppy_live;
    constructor and the breakpoint-created hook function.  */
 static breakpoint_object *bppy_pending_object;
 
+/* Function that is called when a Python condition is evaluated.  */
+char *stop_func = "should_stop";
+
 struct breakpoint_object
 {
   PyObject_HEAD
@@ -705,24 +708,24 @@ gdbpy_breakpoints (PyObject *self, PyObject *args)
   return PyList_AsTuple (list);
 }
 
-/* Call the "eval" method (if implemented) in the breakpoint class.  If
-   the method returns True, the inferior  will be stopped at the
-   breakpoint.  Otherwise the inferior will be allowed to continue.  */
+/* Call the "should_stop" method (if implemented) in the breakpoint
+   class.  If the method returns True, the inferior  will be
+   stopped at the breakpoint.  Otherwise the inferior will be
+   allowed to continue.  */
 
 int
-gdbpy_stop_p (struct breakpoint_object *bp_obj)
+gdbpy_should_stop (struct breakpoint_object *bp_obj)
 {
   int should_stop = 1;
-  char *method = "stop_p";
 
   PyObject *py_bp = (PyObject *) bp_obj;
   struct breakpoint *b = bp_obj->bp;
   struct gdbarch *garch = b->gdbarch ? b->gdbarch : get_current_arch ();
   struct cleanup *cleanup = ensure_python_env (garch, current_language);
 
-  if (PyObject_HasAttrString (py_bp, method))
+  if (PyObject_HasAttrString (py_bp, stop_func))
     {
-      PyObject *result = PyObject_CallMethod (py_bp, method, NULL);
+      PyObject *result = PyObject_CallMethod (py_bp, stop_func, NULL);
 
       if (result)
 	{
@@ -731,9 +734,9 @@ gdbpy_stop_p (struct breakpoint_object *bp_obj)
 	  if (evaluate == -1)
 	    gdbpy_print_stack ();
 
-	  /* If the evaluate function returns False that means the
-	     Python breakpoint wants GDB to continue.  */
-	  if (!evaluate)
+	  /* If the "should_stop" function returns False that means
+	     the Python breakpoint wants GDB to continue.  */
+	  if (! evaluate)
 	    should_stop = 0;
 
 	  Py_DECREF (result);
@@ -746,6 +749,22 @@ gdbpy_stop_p (struct breakpoint_object *bp_obj)
   return should_stop;
 }
 
+/* Checks if the  "should_stop" method exists in this breakpoint.
+   Used by condition_command to ensure mutual exclusion of breakpoint
+   conditions.  */
+
+int
+gdbpy_breakpoint_has_py_cond (struct breakpoint_object *bp_obj)
+{
+  PyObject *py_bp = (PyObject *) bp_obj;
+  struct cleanup *cleanup = ensure_python_env (garch, current_language);
+  
+  if (py_bp == NULL)
+    return 0;
+
+  return PyObject_HasAttrString (py_bp, stop_func);
+}
+
 \f
 
 /* Event callback functions.  */
@@ -866,6 +885,36 @@ gdbpy_initialize_breakpoints (void)
 
 \f
 
+/* Helper function that overrides this Python object's
+   PyObject_GenericSetAttr to allow extra validation of the attribute
+   being set.  */
+static int 
+local_setattro (PyObject *self, PyObject *name, PyObject *v)
+{
+  breakpoint_object *obj = (breakpoint_object *) self;  
+  char *attr = python_string_to_host_string (name);
+  
+  if (attr == NULL)
+    return -1;
+  
+  /* If the attribute trying to be set is the "should_stop" method,
+     but we already have a condition set in the CLI, disallow this
+     operation.  */
+  if (strcmp (attr, stop_func) == 0 && obj->bp->cond_string)
+    {
+      xfree (attr);
+      PyErr_SetString (PyExc_RuntimeError, 
+		       _("Cannot set should_stop method.  There is an " \
+			 "existing GDB condition attached to the " \
+			 "breakpoint."));
+      return -1;
+    }
+  
+  xfree (attr);
+  
+  return PyObject_GenericSetAttr ((PyObject *)self, name, v);  
+}
+
 static PyGetSetDef breakpoint_object_getset[] = {
   { "enabled", bppy_get_enabled, bppy_set_enabled,
     "Boolean telling whether the breakpoint is enabled.", NULL },
@@ -935,7 +984,7 @@ static PyTypeObject breakpoint_object_type =
   0,				  /*tp_call*/
   0,				  /*tp_str*/
   0,				  /*tp_getattro*/
-  0,				  /*tp_setattro*/
+  (setattrofunc)local_setattro,   /*tp_setattro */
   0,				  /*tp_as_buffer*/
   Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,  /*tp_flags*/
   "GDB breakpoint object",	  /* tp_doc */
diff --git a/gdb/python/python.c b/gdb/python/python.c
index 3b10d8c..9da1c19 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -864,6 +864,22 @@ source_python_script (FILE *stream, const char *file)
 	       _("Python scripting is not supported in this copy of GDB."));
 }
 
+int
+gdbpy_should_stop (struct breakpoint_object *bp_obj)
+{
+  /* Just assume default breakpoint behavior if Python is not
+     installed.  */
+  return 1;
+}
+
+int
+gdbpy_breakpoint_has_py_cond (struct breakpoint_object *bp_obj)
+{
+  /* If Python is not installed, then neither can a Python
+     "should_stop" function.  */
+  return 0;
+}
+
 #endif /* HAVE_PYTHON */
 
 \f
diff --git a/gdb/python/python.h b/gdb/python/python.h
index 801282e..ce0eb35 100644
--- a/gdb/python/python.h
+++ b/gdb/python/python.h
@@ -43,6 +43,8 @@ void preserve_python_values (struct objfile *objfile, htab_t copied_types);
 
 void load_auto_scripts_for_objfile (struct objfile *objfile);
 
-int gdbpy_stop_p (struct breakpoint_object *bp_obj);
+int gdbpy_should_stop (struct breakpoint_object *bp_obj);
+
+int gdbpy_breakpoint_has_py_cond (struct breakpoint_object *bp_obj);
 
 #endif /* GDB_PYTHON_H */
diff --git a/gdb/testsuite/gdb.python/py-breakpoint.exp b/gdb/testsuite/gdb.python/py-breakpoint.exp
index 1474afe..6bf90cb 100644
--- a/gdb/testsuite/gdb.python/py-breakpoint.exp
+++ b/gdb/testsuite/gdb.python/py-breakpoint.exp
@@ -212,7 +212,7 @@ gdb_py_test_multiple "Sub-class a breakpoint" \
   "class bp_eval (gdb.Breakpoint):" "" \
   "   inf_i = 0" "" \
   "   count = 0" "" \
-  "   def stop_p (self):" "" \
+  "   def should_stop (self):" "" \
   "      self.count = self.count + 1" "" \
   "      self.inf_i = gdb.parse_and_eval(\"i\")" "" \
   "      if self.inf_i == 3:" "" \
@@ -224,7 +224,7 @@ gdb_py_test_multiple "Sub-class a second breakpoint" \
   "python" "" \
   "class bp_also_eval (gdb.Breakpoint):" "" \
   "   count = 0" "" \
-  "   def stop_p (self):" "" \
+  "   def should_stop (self):" "" \
   "      self.count = self.count + 1" "" \
   "      if self.count == 9:" "" \
   "        return True" "" \
@@ -256,7 +256,7 @@ gdb_test "python print check_eval.count" "1" \
 gdb_py_test_multiple "Sub-class a watchpoint" \
   "python" "" \
   "class wp_eval (gdb.Breakpoint):" "" \
-  "   def stop_p (self):" "" \
+  "   def should_stop (self):" "" \
   "      self.result = gdb.parse_and_eval(\"result\")" "" \
   "      if self.result == 788:" "" \
   "        return True" "" \


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


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

only message in thread, other threads:[~2011-03-10 15:10 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-03-10 15:10 [SCM] archer-pmuldoon-python-breakpoints: Review changes Mar 10th 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).