public inbox for archer-commits@sourceware.org
help / color / mirror / Atom feed
* [SCM] archer-pmuldoon-python-breakpoints: Write documentation. Change eval to evaluate. Clean up code and prepare for submission.
@ 2010-12-10 14:33 pmuldoon
0 siblings, 0 replies; only message in thread
From: pmuldoon @ 2010-12-10 14:33 UTC (permalink / raw)
To: archer-commits
The branch, archer-pmuldoon-python-breakpoints has been updated
via 221d4ddff7db968e34442c0a93753bdaa8e290bd (commit)
from 6d10d6492fe95ecc02bda0b46076537203cb21aa (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email.
- Log -----------------------------------------------------------------
commit 221d4ddff7db968e34442c0a93753bdaa8e290bd
Author: Phil Muldoon <pmuldoon@redhat.com>
Date: Fri Dec 10 14:32:48 2010 +0000
Write documentation. Change eval to evaluate. Clean up code and
prepare for submission.
-----------------------------------------------------------------------
Summary of changes:
gdb/breakpoint.c | 24 +++++++++++-------------
gdb/doc/gdb.texinfo | 21 ++++++++++++++++++++-
gdb/testsuite/gdb.python/py-breakpoint.exp | 28 +++++++++++++++++++++++++---
3 files changed, 56 insertions(+), 17 deletions(-)
First 500 lines of diff:
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index e57b45f..2c4be32 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -3914,7 +3914,6 @@ bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid)
int thread_id = pid_to_thread_id (ptid);
const struct bp_location *bl;
struct breakpoint *b;
- int python_condition_sprung = 0;
/* BS is built for existing struct breakpoint. */
bl = bs->bp_location_at;
@@ -3930,32 +3929,31 @@ bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid)
int value_is_zero = 0;
struct expression *cond;
- /* TODO: Put the Python case here for now. Not sure what happens when a
- breakpoint has a condition and a python eval function. I guess stop
- if either become true. */
+ /* Evaluate any Python breakpoints that have an "evaluate"
+ function implemented. */
#if HAVE_PYTHON
if (b->py_bp_object)
{
struct cleanup *cleanup = ensure_python_env (get_current_arch (),
- current_language);
- PyObject *gdbpy_bp_eval = PyString_FromString ("eval");
+ current_language);
+ PyObject *gdbpy_bp_eval = PyString_FromString ("evaluate");
PyObject *py_bp = (PyObject *) b->py_bp_object;
if (PyObject_HasAttr (py_bp, gdbpy_bp_eval))
{
- PyObject *result = PyObject_CallMethodObjArgs (py_bp,
- gdbpy_bp_eval,
+ PyObject *result = PyObject_CallMethodObjArgs (py_bp,
+ gdbpy_bp_eval,
NULL);
if (result)
- {
+ {
int evaluate = PyObject_IsTrue (result);
if (evaluate == -1)
- error( _("Error while evaluating breakpoint function."));
-
- /* If the eval function returns False that means the
- Python breakpoint wants the GDB to continue. */
+ error ( _("Error while evaluating breakpoint function."));
+
+ /* If the evaluate function returns False that means the
+ Python breakpoint wants GDB to continue. */
if (!evaluate)
bs->stop = 0;
}
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index dc9630a..b91b852 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -22872,7 +22872,26 @@ Return the symbol table's source absolute file name.
@tindex gdb.Breakpoint
Python code can manipulate breakpoints via the @code{gdb.Breakpoint}
-class.
+class. The @code{gdb.Breakpoint} class can be sub-classed and, in
+particular, you may choose to implement the @code{evaluate} function.
+If this function is defined it will be called when @value{GDBN} stops
+at that breakpoint. If the @code{evaluate} function returns
+@code{True}, the inferior will be stopped at the breakpoint, otherwise
+if the function returns @code{False} the inferior will continue. The
+@code{evaluate} function should not attempt to influence any element
+of the inferior (i.e., step) or otherwise alter any of its state or
+data.
+
+Example @code{evaluate} implementation:
+
+@smallexample
+class MyBreakpoint (gdb.Breakpoint):
+ def evaluate (self):
+ inf_val = gdb.parse_and_eval("foo")
+ if inf_val == 3:
+ return True
+ return False
+@end smallexample
@defmethod Breakpoint __init__ spec @r{[}type@r{]} @r{[}wp_class@r{]} @r{[}internal@r{]}
Create a new breakpoint. @var{spec} is a string naming the
diff --git a/gdb/testsuite/gdb.python/py-breakpoint.exp b/gdb/testsuite/gdb.python/py-breakpoint.exp
index 093801e..0867acd 100644
--- a/gdb/testsuite/gdb.python/py-breakpoint.exp
+++ b/gdb/testsuite/gdb.python/py-breakpoint.exp
@@ -214,7 +214,9 @@ gdb_py_test_multiple "Sub-class a breakpoint" \
"python" "" \
"class bp_eval (gdb.Breakpoint):" "" \
" inf_i = 0" "" \
- " def eval (self):" "" \
+ " count = 0" "" \
+ " def evaluate (self):" "" \
+ " self.count = self.count + 1" "" \
" self.inf_i = gdb.parse_and_eval(\"i\")" "" \
" if self.inf_i == 3:" "" \
" return True" "" \
@@ -225,18 +227,38 @@ gdb_py_test_multiple "Sub-class a second breakpoint" \
"python" "" \
"class bp_also_eval (gdb.Breakpoint):" "" \
" count = 0" "" \
- " def eval (self):" "" \
+ " def evaluate (self):" "" \
+ " self.count = self.count + 1" "" \
" if self.count == 9:" "" \
" return True" "" \
- " self.count = self.count + 1" "" \
" return False" "" \
"end" ""
set bp_location2 [gdb_get_line_number "Break at multiply."]
+set end_location [gdb_get_line_number "Break at end."]
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_py_test_silent_cmd "python never_eval_bp1 = bp_also_eval(\"$end_location\")" "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."
+gdb_test "python print eval_bp1.count" "4" \
+ "Check non firing same-location breakpoint eval function was also called at each stop."
+
+gdb_py_test_multiple "Sub-class a watchpoint" \
+ "python" "" \
+ "class wp_eval (gdb.Breakpoint):" "" \
+ " def evaluate (self):" "" \
+ " self.result = gdb.parse_and_eval(\"result\")" "" \
+ " if self.result == 788:" "" \
+ " return True" "" \
+ " return False" "" \
+ "end" ""
+
+delete_breakpoints
+gdb_py_test_silent_cmd "python wp1 = wp_eval (\"result\", type=gdb.BP_WATCHPOINT, wp_class=gdb.WP_WRITE)" "Set watchpoint" 0
+gdb_test "continue" ".*\[Ww\]atchpoint.*result.*Old value =.*New value = 788.*" "Test watchpoint write"
+gdb_test "python print never_eval_bp1.count" "0" \
+ "Check that this unrelated breakpoints eval function was never called."
hooks/post-receive
--
Repository for Project Archer.
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2010-12-10 14:33 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-12-10 14:33 [SCM] archer-pmuldoon-python-breakpoints: Write documentation. Change eval to evaluate. Clean up code and prepare for submission 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).