public inbox for archer-commits@sourceware.org
help / color / mirror / Atom feed
* [SCM]  archer-pmuldoon-python-breakpoints: Rewrite so all breakpoints are called regardless of stop status.  Add tests. Ensure language and arch are set.
@ 2010-12-08 15:53 pmuldoon
  0 siblings, 0 replies; only message in thread
From: pmuldoon @ 2010-12-08 15:53 UTC (permalink / raw)
  To: archer-commits

The branch, archer-pmuldoon-python-breakpoints has been updated
       via  e95153a3c062f9df9b6dd9ea24fe10a83cbf5f7d (commit)
      from  cc034e4d2070cdaabe546fd86c5d3f69a06f6d71 (commit)

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

- Log -----------------------------------------------------------------
commit e95153a3c062f9df9b6dd9ea24fe10a83cbf5f7d
Author: Phil Muldoon <pmuldoon@redhat.com>
Date:   Wed Dec 8 15:52:16 2010 +0000

    Rewrite so all breakpoints are called regardless of stop status.  Add
    tests. Ensure language and arch are set.

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

Summary of changes:
 gdb/breakpoint.c                           |   33 +++++++++++----------
 gdb/testsuite/gdb.python/py-breakpoint.exp |   42 ++++++++++++++++++++++++++++
 2 files changed, 59 insertions(+), 16 deletions(-)

First 500 lines of diff:
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index f1c7850..e57b45f 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -3934,36 +3934,36 @@ bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid)
 	 breakpoint has a condition and a python eval function.  I guess stop
 	 if either become true.  */
 #if HAVE_PYTHON
-      PyGILState_STATE state;
-      PyObject *gdbpy_bp_eval = PyString_FromString ("eval");
-      int evaluate = 0;
-      PyObject *result;
-      state = PyGILState_Ensure ();
-      
       if (b->py_bp_object)
 	{
+	  struct cleanup *cleanup = ensure_python_env (get_current_arch (),
+							current_language);
+	  PyObject *gdbpy_bp_eval = PyString_FromString ("eval");
 	  PyObject *py_bp = (PyObject *) b->py_bp_object;
+
 	  if (PyObject_HasAttr (py_bp, gdbpy_bp_eval))
 	    {
-	      result = PyObject_CallMethodObjArgs (py_bp, gdbpy_bp_eval, NULL);
+	      PyObject *result = PyObject_CallMethodObjArgs (py_bp, 
+							     gdbpy_bp_eval, 
+							     NULL);
+
 	      if (result)
 		{	    
-		  evaluate = PyObject_IsTrue (result);
+		  int evaluate = PyObject_IsTrue (result);
+
 		  if (evaluate == -1)
 		    error( _("Error while evaluating breakpoint function."));
 		  
-		  if (evaluate)
-		    bs->stop = 1;
-		  else
+		  /* If the eval function returns False that means the
+		     Python breakpoint wants the GDB to continue.  */
+		  if (!evaluate)
 		    bs->stop = 0;
-		  
-		  /* This does not seem right in this context.  */
-		  return;
 		}
+	      else
+		gdbpy_print_stack ();
 	    }
+	  do_cleanups (cleanup);
 	}
-    
-      PyGILState_Release (state);
 #endif
 
       if (is_watchpoint (b))
@@ -4144,6 +4144,7 @@ bpstat_stop_status (struct address_space *aspace,
 	}
     }
 
+
   /* Now go through the locations that caused the target to stop, and
      check whether we're interested in reporting this stop to higher
      layers, or whether we should resume the target transparently.  */
diff --git a/gdb/testsuite/gdb.python/py-breakpoint.exp b/gdb/testsuite/gdb.python/py-breakpoint.exp
index 34a64a3..093801e 100644
--- a/gdb/testsuite/gdb.python/py-breakpoint.exp
+++ b/gdb/testsuite/gdb.python/py-breakpoint.exp
@@ -198,3 +198,45 @@ gdb_py_test_silent_cmd  "python wp1 = gdb.Breakpoint (\"result\", type=gdb.BP_WA
 gdb_test "info breakpoints" "No breakpoints or watchpoints.*" "Check info breakpoints does not show invisible breakpoints"
 gdb_test "maint info breakpoints" ".*hw watchpoint.*result.*" "Check maint info breakpoints shows invisible breakpoints"
 gdb_test "continue" ".*\[Ww\]atchpoint.*result.*Old value = 0.*New value = 25.*" "Test watchpoint write"
+
+# Breakpoints that have an evaluation function.
+
+# Start with a fresh gdb.
+clean_restart ${testfile}
+
+if ![runto_main] then {
+    fail "Cannot run to main."
+    return 0
+}
+delete_breakpoints
+
+gdb_py_test_multiple "Sub-class a breakpoint" \
+  "python" "" \
+  "class bp_eval (gdb.Breakpoint):" "" \
+  "   inf_i = 0" "" \
+  "   def eval (self):" "" \
+  "      self.inf_i = gdb.parse_and_eval(\"i\")" "" \
+  "      if self.inf_i == 3:" "" \
+  "        return True" "" \
+  "      return False" "" \
+  "end" ""
+
+gdb_py_test_multiple "Sub-class a second breakpoint" \
+  "python" "" \
+  "class bp_also_eval (gdb.Breakpoint):" "" \
+  "   count = 0" "" \
+  "   def eval (self):" "" \
+  "      if self.count == 9:" "" \
+  "        return True" "" \
+  "      self.count = self.count + 1" "" \
+  "      return False" "" \
+  "end" ""
+
+set bp_location2 [gdb_get_line_number "Break at multiply."]
+gdb_py_test_silent_cmd  "python eval_bp1 = bp_eval(\"$bp_location2\")" "Set breakpoint" 0
+gdb_py_test_silent_cmd  "python also_eval_bp1 = bp_also_eval(\"$bp_location2\")" "Set breakpoint" 0
+gdb_continue_to_breakpoint "Break at multiply." ".*/$srcfile:$bp_location2.*"
+gdb_test "print i" "3" "Check inferior value matches python accounting"
+gdb_test "python print eval_bp1.inf_i" "3" "Check python accounting matches inferior"
+gdb_test "python print also_eval_bp1.count" "4" \
+    "Check non firing same-location breakpoint eval function was also called at each stop."


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


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

only message in thread, other threads:[~2010-12-08 15:53 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-12-08 15:53 [SCM] archer-pmuldoon-python-breakpoints: Rewrite so all breakpoints are called regardless of stop status. Add tests. Ensure language and arch are set 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).