public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [python][patch] Add temporary breakpoint features to Python breakpoints.
@ 2013-09-09 10:05 Phil Muldoon
  2013-09-09 16:29 ` Eli Zaretskii
  2013-09-09 18:47 ` Tom Tromey
  0 siblings, 2 replies; 12+ messages in thread
From: Phil Muldoon @ 2013-09-09 10:05 UTC (permalink / raw)
  To: gdb-patches

This patch allows Python breakpoints to be made temporary on
creation.  It adds an optional argument, and keyword: "temporary".

OK?

Cheers,

Phil


2013-09-09  Phil Muldoon  <pmuldoon@redhat.com>

	* python/py-breakpoint.c (bppy_get_temporary): New function.
	(bppy_init): New keyword: temporary. Parse it and set breakpoint
	to temporary if True.

2013-09-09  Phil Muldoon  <pmuldoon@redhat.com>

	* gdb.python/py-breakpoint.exp: Add temporary breakpoint tests.

2013-09-09  Phil Muldoon  <pmuldoon@redhat.com>

	* gdb.texinfo (Breakpoints In Python): Document temporary
	option in breakpoint constructor, and add documentation to the
	temporary attribute.

--

diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 21250fe..627d65e 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -26799,22 +26799,27 @@ Return the static block of the underlying symbol table.
 Python code can manipulate breakpoints via the @code{gdb.Breakpoint}
 class.
 
-@defun Breakpoint.__init__ (spec @r{[}, type @r{[}, wp_class @r{[},internal@r{]]]})
-Create a new breakpoint.  @var{spec} is a string naming the
-location of the breakpoint, or an expression that defines a
-watchpoint.  The contents can be any location recognized by the
-@code{break} command, or in the case of a watchpoint, by the @code{watch}
-command.  The optional @var{type} denotes the breakpoint to create
-from the types defined later in this chapter.  This argument can be
-either: @code{gdb.BP_BREAKPOINT} or @code{gdb.BP_WATCHPOINT}.  @var{type}
-defaults to @code{gdb.BP_BREAKPOINT}.  The optional @var{internal} argument
-allows the breakpoint to become invisible to the user.  The breakpoint
-will neither be reported when created, nor will it be listed in the
-output from @code{info breakpoints} (but will be listed with the
-@code{maint info breakpoints} command).  The optional @var{wp_class}
-argument defines the class of watchpoint to create, if @var{type} is
-@code{gdb.BP_WATCHPOINT}.  If a watchpoint class is not provided, it is
-assumed to be a @code{gdb.WP_WRITE} class.
+@defun Breakpoint.__init__ (spec @r{[}, type @r{[}, wp_class @r{[},internal @r{[},temporary@r{]]]]})
+Create a new breakpoint.  @var{spec} is a string naming the location
+of the breakpoint, or an expression that defines a watchpoint.  The
+contents can be any location recognized by the @code{break} command,
+or in the case of a watchpoint, by the @code{watch} command.  The
+optional @var{type} denotes the breakpoint to create from the types
+defined later in this chapter.  This argument can be either:
+@code{gdb.BP_BREAKPOINT} or @code{gdb.BP_WATCHPOINT}.  @var{type}
+defaults to @code{gdb.BP_BREAKPOINT}.  The optional @var{internal}
+argument allows the breakpoint to become invisible to the user.  The
+breakpoint will neither be reported when created, nor will it be
+listed in the output from @code{info breakpoints} (but will be listed
+with the @code{maint info breakpoints} command).  The optional
+@var{temporary} argument makes the breakpoint a temporary breakpoint.
+Temporary breakpoints are deleted after they have been hit.  Any
+further access to the Python breakpoint after it has been hit will
+result in a runtime error (as that breakpoint has now been
+automatically deleted).  The optional @var{wp_class} argument defines
+the class of watchpoint to create, if @var{type} is
+@code{gdb.BP_WATCHPOINT}.  If a watchpoint class is not provided, it
+is assumed to be a @code{gdb.WP_WRITE} class.
 @end defun
 
 @defun Breakpoint.stop (self)
@@ -26935,6 +26940,16 @@ when set, or when the @samp{info breakpoints} command is run.  This
 attribute is not writable.
 @end defvar
 
+@defvar Breakpoint.temporary
+This attribute indicates whether the breakpoint was created as a
+temporary breakpoint.  Temporary breakpoints are automatically deleted
+after that breakpoint has been hit.  Access to this attribute, and all
+other attributes and functions other than the @code{is_valid}
+function, will result in an error after the breakpoint has been hit
+(as it has been automatically deleted).  This attribute is not
+writable.
+@end defvar
+
 The available types are represented by constants defined in the @code{gdb}
 module:
 
diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c
index 87f1fdc..766ae56 100644
--- a/gdb/python/py-breakpoint.c
+++ b/gdb/python/py-breakpoint.c
@@ -529,6 +529,23 @@ bppy_get_visibility (PyObject *self, void *closure)
   Py_RETURN_TRUE;
 }
 
+/* Python function to determine if the breakpoint is a temporary
+   breakpoint.  */
+
+static PyObject *
+bppy_get_temporary (PyObject *self, void *closure)
+{
+  breakpoint_object *self_bp = (breakpoint_object *) self;
+
+  BPPY_REQUIRE_VALID (self_bp);
+
+  if (self_bp->bp->disposition == disp_del ||
+      self_bp->bp->disposition == disp_del_at_next_stop)
+    Py_RETURN_TRUE;
+
+  Py_RETURN_FALSE;
+}
+
 /* Python function to get the breakpoint's number.  */
 static PyObject *
 bppy_get_number (PyObject *self, void *closure)
@@ -594,16 +611,19 @@ bppy_get_ignore_count (PyObject *self, void *closure)
 static int
 bppy_init (PyObject *self, PyObject *args, PyObject *kwargs)
 {
-  static char *keywords[] = { "spec", "type", "wp_class", "internal", NULL };
+  static char *keywords[] = { "spec", "type", "wp_class", "internal", "temporary", NULL };
   const char *spec;
   int type = bp_breakpoint;
   int access_type = hw_write;
   PyObject *internal = NULL;
+  PyObject *temporary = NULL;
   int internal_bp = 0;
+  int temporary_bp = 0;
   volatile struct gdb_exception except;
 
-  if (! PyArg_ParseTupleAndKeywords (args, kwargs, "s|iiO", keywords,
-				     &spec, &type, &access_type, &internal))
+  if (! PyArg_ParseTupleAndKeywords (args, kwargs, "s|iiOO", keywords,
+				     &spec, &type, &access_type,
+				     &internal, &temporary))
     return -1;
 
   if (internal)
@@ -613,6 +633,13 @@ bppy_init (PyObject *self, PyObject *args, PyObject *kwargs)
 	return -1;
     }
 
+  if (temporary)
+    {
+      temporary_bp = PyObject_IsTrue (temporary);
+      if (temporary_bp == -1)
+	return -1;
+    }
+
   bppy_pending_object = (breakpoint_object *) self;
   bppy_pending_object->number = -1;
   bppy_pending_object->bp = NULL;
@@ -629,7 +656,7 @@ bppy_init (PyObject *self, PyObject *args, PyObject *kwargs)
 	    create_breakpoint (python_gdbarch,
 			       copy, NULL, -1, NULL,
 			       0,
-			       0, bp_breakpoint,
+			       temporary_bp, bp_breakpoint,
 			       0,
 			       AUTO_BOOLEAN_TRUE,
 			       &bkpt_breakpoint_ops,
@@ -973,6 +1000,8 @@ or None if no condition set."},
     "Type of breakpoint."},
   { "visible", bppy_get_visibility, NULL,
     "Whether the breakpoint is visible to the user."},
+  { "temporary", bppy_get_temporary, NULL,
+    "Whether this breakpoint is a temporary breakpoint."},
   { NULL }  /* Sentinel.  */
 };
 
diff --git a/gdb/testsuite/gdb.python/py-breakpoint.exp b/gdb/testsuite/gdb.python/py-breakpoint.exp
index 687182d..8464cec 100644
--- a/gdb/testsuite/gdb.python/py-breakpoint.exp
+++ b/gdb/testsuite/gdb.python/py-breakpoint.exp
@@ -300,3 +300,28 @@ gdb_py_test_silent_cmd  "python wp1 = wp_eval (\"result\", type=gdb.BP_WATCHPOIN
 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."
+
+# Test temporary breakpoint
+
+# Start with a fresh gdb.
+clean_restart ${testfile}
+
+if ![runto_main] then {
+    fail "Cannot run to main."
+    return 0
+}
+delete_breakpoints
+gdb_py_test_silent_cmd  "python ibp =  gdb.Breakpoint(\"$ibp_location\", temporary=True)" \
+    "Set temporary breakpoint" 0
+
+gdb_test "info breakpoints" "2.*breakpoint.*del.*py-breakpoint\.c:$ibp_location.*" \
+    "Check info breakpoints shows breakpoint with temporary status"
+gdb_test "python print (ibp.location)" "py-breakpoint\.c:$ibp_location*" \
+    "Check temporary breakpoint location"
+gdb_test "python print (ibp.temporary)" "True" \
+    "Check breakpoint temporary status"
+gdb_continue_to_breakpoint "Break at multiply." ".*/$srcfile:$ibp_location.*"
+gdb_test "python print (ibp.temporary)" "RuntimeError: Breakpoint 2 is invalid.*" \
+    "Check temporary breakpoint is deleted after being hit"
+gdb_test "info breakpoints" "No breakpoints or watchpoints.*" \
+    "Check info breakpoints shows temporary breakpoint is deleted"

	

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [python][patch] Add temporary breakpoint features to Python breakpoints.
  2013-09-09 10:05 [python][patch] Add temporary breakpoint features to Python breakpoints Phil Muldoon
@ 2013-09-09 16:29 ` Eli Zaretskii
  2013-09-09 18:47 ` Tom Tromey
  1 sibling, 0 replies; 12+ messages in thread
From: Eli Zaretskii @ 2013-09-09 16:29 UTC (permalink / raw)
  To: Phil Muldoon; +Cc: gdb-patches

> Date: Mon, 09 Sep 2013 11:05:11 +0100
> From: Phil Muldoon <pmuldoon@redhat.com>
> 
> This patch allows Python breakpoints to be made temporary on
> creation.  It adds an optional argument, and keyword: "temporary".
> 
> OK?

OK for the documentation part.

Thanks.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [python][patch] Add temporary breakpoint features to Python breakpoints.
  2013-09-09 10:05 [python][patch] Add temporary breakpoint features to Python breakpoints Phil Muldoon
  2013-09-09 16:29 ` Eli Zaretskii
@ 2013-09-09 18:47 ` Tom Tromey
  2013-09-09 19:01   ` Phil Muldoon
  2013-09-18  9:09   ` Phil Muldoon
  1 sibling, 2 replies; 12+ messages in thread
From: Tom Tromey @ 2013-09-09 18:47 UTC (permalink / raw)
  To: Phil Muldoon; +Cc: gdb-patches

>>>>> "Phil" == Phil Muldoon <pmuldoon@redhat.com> writes:

Phil> This patch allows Python breakpoints to be made temporary on
Phil> creation.  It adds an optional argument, and keyword: "temporary".

Phil> OK?

Thanks, Phil.

Phil> 2013-09-09  Phil Muldoon  <pmuldoon@redhat.com>

Phil> 	* python/py-breakpoint.c (bppy_get_temporary): New function.
Phil> 	(bppy_init): New keyword: temporary. Parse it and set breakpoint
Phil> 	to temporary if True.

Is there a PR associated with this?
I thought there was, but I didn't check.

Phil> +@defvar Breakpoint.temporary
Phil> +This attribute indicates whether the breakpoint was created as a
Phil> +temporary breakpoint.  Temporary breakpoints are automatically deleted
Phil> +after that breakpoint has been hit.  Access to this attribute, and all
Phil> +other attributes and functions other than the @code{is_valid}
Phil> +function, will result in an error after the breakpoint has been hit
Phil> +(as it has been automatically deleted).  This attribute is not
Phil> +writable.

I think it is worth spelling out what "hit" means.
In particular I was wondering how it interacts with the "stop" method.

Phil> +  if (self_bp->bp->disposition == disp_del ||
Phil> +      self_bp->bp->disposition == disp_del_at_next_stop)

"||" at the wrong spot.

Phil> +  static char *keywords[] = { "spec", "type", "wp_class", "internal", "temporary", NULL };

This line is too long.

Phil> +  if (temporary)

temporary != NULL

Tom

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [python][patch] Add temporary breakpoint features to Python breakpoints.
  2013-09-09 18:47 ` Tom Tromey
@ 2013-09-09 19:01   ` Phil Muldoon
  2013-09-09 19:15     ` Tom Tromey
  2013-09-18  9:09   ` Phil Muldoon
  1 sibling, 1 reply; 12+ messages in thread
From: Phil Muldoon @ 2013-09-09 19:01 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches

On 09/09/13 19:47, Tom Tromey wrote:
>>>>>> "Phil" == Phil Muldoon <pmuldoon@redhat.com> writes:
> 
> Phil> This patch allows Python breakpoints to be made temporary on
> Phil> creation.  It adds an optional argument, and keyword: "temporary".
> 
> Phil> OK?
> 
> Thanks, Phil.
> 
> Phil> 2013-09-09  Phil Muldoon  <pmuldoon@redhat.com>
> 
> Phil> 	* python/py-breakpoint.c (bppy_get_temporary): New function.
> Phil> 	(bppy_init): New keyword: temporary. Parse it and set breakpoint
> Phil> 	to temporary if True.
> 
> Is there a PR associated with this?
> I thought there was, but I didn't check.

I will double-check.

 
> Phil> +@defvar Breakpoint.temporary
> Phil> +This attribute indicates whether the breakpoint was created as a
> Phil> +temporary breakpoint.  Temporary breakpoints are automatically deleted
> Phil> +after that breakpoint has been hit.  Access to this attribute, and all
> Phil> +other attributes and functions other than the @code{is_valid}
> Phil> +function, will result in an error after the breakpoint has been hit
> Phil> +(as it has been automatically deleted).  This attribute is not
> Phil> +writable.

I ended up rewriting this paragraph several times to try to explain
hit ;) In the end I deleted as we already use "hit" as a verb in the
API (and in the documentation).  (IE, hit_count).  I could not come up
with a good turn of phrase without turning the paragraph of the
constructor for breakpoints into a mess of technical discussion with
how GDB handles stop events for breakpoints.  What do you think we
should use here?

Breakpoints with a disposition of del, or del_at_next_stop are deleted
when the when the inferior stops.  But good point, there could
possibly be a case where the "stop" and disposition may conflict. (When
the stop callbacks are executed, the inferior is stopped by the
kernel, but the state has not yet changed in the GDB record keeping).
I will double check.

 
> I think it is worth spelling out what "hit" means.
> In particular I was wondering how it interacts with the "stop" method.
> 
> Phil> +  if (self_bp->bp->disposition == disp_del ||
> Phil> +      self_bp->bp->disposition == disp_del_at_next_stop)
> 
> "||" at the wrong spot.
> 
> Phil> +  static char *keywords[] = { "spec", "type", "wp_class", "internal", "temporary", NULL };
> 
> This line is too long.
> 
> Phil> +  if (temporary)
> 
> temporary != NULL

OK thanks for catching these.

Cheers,

Phil

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [python][patch] Add temporary breakpoint features to Python breakpoints.
  2013-09-09 19:01   ` Phil Muldoon
@ 2013-09-09 19:15     ` Tom Tromey
  0 siblings, 0 replies; 12+ messages in thread
From: Tom Tromey @ 2013-09-09 19:15 UTC (permalink / raw)
  To: Phil Muldoon; +Cc: gdb-patches

>>>>> "Phil" == Phil Muldoon <pmuldoon@redhat.com> writes:

Phil> I ended up rewriting this paragraph several times to try to explain
Phil> hit ;) In the end I deleted as we already use "hit" as a verb in the
Phil> API (and in the documentation).  (IE, hit_count).

Ok, thanks.

Tom

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [python][patch] Add temporary breakpoint features to Python breakpoints.
  2013-09-09 18:47 ` Tom Tromey
  2013-09-09 19:01   ` Phil Muldoon
@ 2013-09-18  9:09   ` Phil Muldoon
  2013-10-01 11:32     ` Phil Muldoon
                       ` (2 more replies)
  1 sibling, 3 replies; 12+ messages in thread
From: Phil Muldoon @ 2013-09-18  9:09 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches

On 09/09/13 19:47, Tom Tromey wrote:
>>>>>> "Phil" == Phil Muldoon <pmuldoon@redhat.com> writes:

> Phil> 2013-09-09  Phil Muldoon  <pmuldoon@redhat.com>
> 
> Phil> 	* python/py-breakpoint.c (bppy_get_temporary): New function.
> Phil> 	(bppy_init): New keyword: temporary. Parse it and set breakpoint
> Phil> 	to temporary if True.
> 
> Is there a PR associated with this?
> I thought there was, but I didn't check.

I did a search and I could not find one.

> In particular I was wondering how it interacts with the "stop" method.

I added a test to make sure the "stop" method is executing before
deletion.  I think the docs are approved by both you and Eli?

Other nits fixed up too.  ChangeLog remains the same.

OK?

Cheers,

Phil

--

diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 21250fe..627d65e 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -26799,22 +26799,27 @@ Return the static block of the underlying symbol table.
 Python code can manipulate breakpoints via the @code{gdb.Breakpoint}
 class.
 
-@defun Breakpoint.__init__ (spec @r{[}, type @r{[}, wp_class @r{[},internal@r{]]]})
-Create a new breakpoint.  @var{spec} is a string naming the
-location of the breakpoint, or an expression that defines a
-watchpoint.  The contents can be any location recognized by the
-@code{break} command, or in the case of a watchpoint, by the @code{watch}
-command.  The optional @var{type} denotes the breakpoint to create
-from the types defined later in this chapter.  This argument can be
-either: @code{gdb.BP_BREAKPOINT} or @code{gdb.BP_WATCHPOINT}.  @var{type}
-defaults to @code{gdb.BP_BREAKPOINT}.  The optional @var{internal} argument
-allows the breakpoint to become invisible to the user.  The breakpoint
-will neither be reported when created, nor will it be listed in the
-output from @code{info breakpoints} (but will be listed with the
-@code{maint info breakpoints} command).  The optional @var{wp_class}
-argument defines the class of watchpoint to create, if @var{type} is
-@code{gdb.BP_WATCHPOINT}.  If a watchpoint class is not provided, it is
-assumed to be a @code{gdb.WP_WRITE} class.
+@defun Breakpoint.__init__ (spec @r{[}, type @r{[}, wp_class @r{[},internal @r{[},temporary@r{]]]]})
+Create a new breakpoint.  @var{spec} is a string naming the location
+of the breakpoint, or an expression that defines a watchpoint.  The
+contents can be any location recognized by the @code{break} command,
+or in the case of a watchpoint, by the @code{watch} command.  The
+optional @var{type} denotes the breakpoint to create from the types
+defined later in this chapter.  This argument can be either:
+@code{gdb.BP_BREAKPOINT} or @code{gdb.BP_WATCHPOINT}.  @var{type}
+defaults to @code{gdb.BP_BREAKPOINT}.  The optional @var{internal}
+argument allows the breakpoint to become invisible to the user.  The
+breakpoint will neither be reported when created, nor will it be
+listed in the output from @code{info breakpoints} (but will be listed
+with the @code{maint info breakpoints} command).  The optional
+@var{temporary} argument makes the breakpoint a temporary breakpoint.
+Temporary breakpoints are deleted after they have been hit.  Any
+further access to the Python breakpoint after it has been hit will
+result in a runtime error (as that breakpoint has now been
+automatically deleted).  The optional @var{wp_class} argument defines
+the class of watchpoint to create, if @var{type} is
+@code{gdb.BP_WATCHPOINT}.  If a watchpoint class is not provided, it
+is assumed to be a @code{gdb.WP_WRITE} class.
 @end defun
 
 @defun Breakpoint.stop (self)
@@ -26935,6 +26940,16 @@ when set, or when the @samp{info breakpoints} command is run.  This
 attribute is not writable.
 @end defvar
 
+@defvar Breakpoint.temporary
+This attribute indicates whether the breakpoint was created as a
+temporary breakpoint.  Temporary breakpoints are automatically deleted
+after that breakpoint has been hit.  Access to this attribute, and all
+other attributes and functions other than the @code{is_valid}
+function, will result in an error after the breakpoint has been hit
+(as it has been automatically deleted).  This attribute is not
+writable.
+@end defvar
+
 The available types are represented by constants defined in the @code{gdb}
 module:
 
diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c
index 87f1fdc..e83471e 100644
--- a/gdb/python/py-breakpoint.c
+++ b/gdb/python/py-breakpoint.c
@@ -529,6 +529,23 @@ bppy_get_visibility (PyObject *self, void *closure)
   Py_RETURN_TRUE;
 }
 
+/* Python function to determine if the breakpoint is a temporary
+   breakpoint.  */
+
+static PyObject *
+bppy_get_temporary (PyObject *self, void *closure)
+{
+  breakpoint_object *self_bp = (breakpoint_object *) self;
+
+  BPPY_REQUIRE_VALID (self_bp);
+
+  if (self_bp->bp->disposition == disp_del
+      || self_bp->bp->disposition == disp_del_at_next_stop)
+    Py_RETURN_TRUE;
+
+  Py_RETURN_FALSE;
+}
+
 /* Python function to get the breakpoint's number.  */
 static PyObject *
 bppy_get_number (PyObject *self, void *closure)
@@ -594,16 +611,20 @@ bppy_get_ignore_count (PyObject *self, void *closure)
 static int
 bppy_init (PyObject *self, PyObject *args, PyObject *kwargs)
 {
-  static char *keywords[] = { "spec", "type", "wp_class", "internal", NULL };
+  static char *keywords[] = { "spec", "type", "wp_class", "internal",
+			      "temporary", NULL };
   const char *spec;
   int type = bp_breakpoint;
   int access_type = hw_write;
   PyObject *internal = NULL;
+  PyObject *temporary = NULL;
   int internal_bp = 0;
+  int temporary_bp = 0;
   volatile struct gdb_exception except;
 
-  if (! PyArg_ParseTupleAndKeywords (args, kwargs, "s|iiO", keywords,
-				     &spec, &type, &access_type, &internal))
+  if (! PyArg_ParseTupleAndKeywords (args, kwargs, "s|iiOO", keywords,
+				     &spec, &type, &access_type,
+				     &internal, &temporary))
     return -1;
 
   if (internal)
@@ -613,6 +634,13 @@ bppy_init (PyObject *self, PyObject *args, PyObject *kwargs)
 	return -1;
     }
 
+  if (temporary != NULL)
+    {
+      temporary_bp = PyObject_IsTrue (temporary);
+      if (temporary_bp == -1)
+	return -1;
+    }
+
   bppy_pending_object = (breakpoint_object *) self;
   bppy_pending_object->number = -1;
   bppy_pending_object->bp = NULL;
@@ -629,7 +657,7 @@ bppy_init (PyObject *self, PyObject *args, PyObject *kwargs)
 	    create_breakpoint (python_gdbarch,
 			       copy, NULL, -1, NULL,
 			       0,
-			       0, bp_breakpoint,
+			       temporary_bp, bp_breakpoint,
 			       0,
 			       AUTO_BOOLEAN_TRUE,
 			       &bkpt_breakpoint_ops,
@@ -973,6 +1001,8 @@ or None if no condition set."},
     "Type of breakpoint."},
   { "visible", bppy_get_visibility, NULL,
     "Whether the breakpoint is visible to the user."},
+  { "temporary", bppy_get_temporary, NULL,
+    "Whether this breakpoint is a temporary breakpoint."},
   { NULL }  /* Sentinel.  */
 };
 
diff --git a/gdb/testsuite/gdb.python/py-breakpoint.exp b/gdb/testsuite/gdb.python/py-breakpoint.exp
index 687182d..e2a169b 100644
--- a/gdb/testsuite/gdb.python/py-breakpoint.exp
+++ b/gdb/testsuite/gdb.python/py-breakpoint.exp
@@ -300,3 +300,37 @@ gdb_py_test_silent_cmd  "python wp1 = wp_eval (\"result\", type=gdb.BP_WATCHPOIN
 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."
+
+# Test temporary breakpoint
+
+# 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 and check temporary breakpoint" \
+  "python" "" \
+  "class temp_bp (gdb.Breakpoint):" "" \
+  "   count = 0" "" \
+  "   def stop (self):" "" \
+  "      self.count = self.count + 1" "" \
+  "      return True" "" \
+  "end" ""
+gdb_py_test_silent_cmd  "python ibp =  temp_bp(\"$ibp_location\", temporary=True)" \
+    "Set temporary breakpoint" 0
+gdb_test "info breakpoints" "2.*breakpoint.*del.*py-breakpoint\.c:$ibp_location.*" \
+    "Check info breakpoints shows breakpoint with temporary status"
+gdb_test "python print (ibp.location)" "py-breakpoint\.c:$ibp_location*" \
+    "Check temporary breakpoint location"
+gdb_test "python print (ibp.temporary)" "True" \
+    "Check breakpoint temporary status"
+gdb_continue_to_breakpoint "Break at multiply." ".*/$srcfile:$ibp_location.*"
+gdb_test "python print (ibp.count)" "1" \
+    "Check temporary stop callback executed before deletion."
+gdb_test "python print (ibp.temporary)" "RuntimeError: Breakpoint 2 is invalid.*" \
+    "Check temporary breakpoint is deleted after being hit"
+gdb_test "info breakpoints" "No breakpoints or watchpoints.*" \
+    "Check info breakpoints shows temporary breakpoint is deleted"


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [python][patch] Add temporary breakpoint features to Python breakpoints.
  2013-09-18  9:09   ` Phil Muldoon
@ 2013-10-01 11:32     ` Phil Muldoon
  2013-10-10 19:49     ` Tom Tromey
  2013-10-10 19:49     ` Tom Tromey
  2 siblings, 0 replies; 12+ messages in thread
From: Phil Muldoon @ 2013-10-01 11:32 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches

On 18/09/13 10:09, Phil Muldoon wrote:
> On 09/09/13 19:47, Tom Tromey wrote:
>>>>>>> "Phil" == Phil Muldoon <pmuldoon@redhat.com> writes:
> 
>> Phil> 2013-09-09  Phil Muldoon  <pmuldoon@redhat.com>
>>
>> Phil> 	* python/py-breakpoint.c (bppy_get_temporary): New function.
>> Phil> 	(bppy_init): New keyword: temporary. Parse it and set breakpoint
>> Phil> 	to temporary if True.
>>
>> Is there a PR associated with this?
>> I thought there was, but I didn't check.
> 
> I did a search and I could not find one.
> 
>> In particular I was wondering how it interacts with the "stop" method.
> 
> I added a test to make sure the "stop" method is executing before
> deletion.  I think the docs are approved by both you and Eli?
> 
> Other nits fixed up too.  ChangeLog remains the same.
> 
> OK?
> 
> Cheers,
> 
> Phil


Ping

Cheers,

Phil

> --
> 
> diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
> index 21250fe..627d65e 100644
> --- a/gdb/doc/gdb.texinfo
> +++ b/gdb/doc/gdb.texinfo
> @@ -26799,22 +26799,27 @@ Return the static block of the underlying symbol table.
>  Python code can manipulate breakpoints via the @code{gdb.Breakpoint}
>  class.
>  
> -@defun Breakpoint.__init__ (spec @r{[}, type @r{[}, wp_class @r{[},internal@r{]]]})
> -Create a new breakpoint.  @var{spec} is a string naming the
> -location of the breakpoint, or an expression that defines a
> -watchpoint.  The contents can be any location recognized by the
> -@code{break} command, or in the case of a watchpoint, by the @code{watch}
> -command.  The optional @var{type} denotes the breakpoint to create
> -from the types defined later in this chapter.  This argument can be
> -either: @code{gdb.BP_BREAKPOINT} or @code{gdb.BP_WATCHPOINT}.  @var{type}
> -defaults to @code{gdb.BP_BREAKPOINT}.  The optional @var{internal} argument
> -allows the breakpoint to become invisible to the user.  The breakpoint
> -will neither be reported when created, nor will it be listed in the
> -output from @code{info breakpoints} (but will be listed with the
> -@code{maint info breakpoints} command).  The optional @var{wp_class}
> -argument defines the class of watchpoint to create, if @var{type} is
> -@code{gdb.BP_WATCHPOINT}.  If a watchpoint class is not provided, it is
> -assumed to be a @code{gdb.WP_WRITE} class.
> +@defun Breakpoint.__init__ (spec @r{[}, type @r{[}, wp_class @r{[},internal @r{[},temporary@r{]]]]})
> +Create a new breakpoint.  @var{spec} is a string naming the location
> +of the breakpoint, or an expression that defines a watchpoint.  The
> +contents can be any location recognized by the @code{break} command,
> +or in the case of a watchpoint, by the @code{watch} command.  The
> +optional @var{type} denotes the breakpoint to create from the types
> +defined later in this chapter.  This argument can be either:
> +@code{gdb.BP_BREAKPOINT} or @code{gdb.BP_WATCHPOINT}.  @var{type}
> +defaults to @code{gdb.BP_BREAKPOINT}.  The optional @var{internal}
> +argument allows the breakpoint to become invisible to the user.  The
> +breakpoint will neither be reported when created, nor will it be
> +listed in the output from @code{info breakpoints} (but will be listed
> +with the @code{maint info breakpoints} command).  The optional
> +@var{temporary} argument makes the breakpoint a temporary breakpoint.
> +Temporary breakpoints are deleted after they have been hit.  Any
> +further access to the Python breakpoint after it has been hit will
> +result in a runtime error (as that breakpoint has now been
> +automatically deleted).  The optional @var{wp_class} argument defines
> +the class of watchpoint to create, if @var{type} is
> +@code{gdb.BP_WATCHPOINT}.  If a watchpoint class is not provided, it
> +is assumed to be a @code{gdb.WP_WRITE} class.
>  @end defun
>  
>  @defun Breakpoint.stop (self)
> @@ -26935,6 +26940,16 @@ when set, or when the @samp{info breakpoints} command is run.  This
>  attribute is not writable.
>  @end defvar
>  
> +@defvar Breakpoint.temporary
> +This attribute indicates whether the breakpoint was created as a
> +temporary breakpoint.  Temporary breakpoints are automatically deleted
> +after that breakpoint has been hit.  Access to this attribute, and all
> +other attributes and functions other than the @code{is_valid}
> +function, will result in an error after the breakpoint has been hit
> +(as it has been automatically deleted).  This attribute is not
> +writable.
> +@end defvar
> +
>  The available types are represented by constants defined in the @code{gdb}
>  module:
>  
> diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c
> index 87f1fdc..e83471e 100644
> --- a/gdb/python/py-breakpoint.c
> +++ b/gdb/python/py-breakpoint.c
> @@ -529,6 +529,23 @@ bppy_get_visibility (PyObject *self, void *closure)
>    Py_RETURN_TRUE;
>  }
>  
> +/* Python function to determine if the breakpoint is a temporary
> +   breakpoint.  */
> +
> +static PyObject *
> +bppy_get_temporary (PyObject *self, void *closure)
> +{
> +  breakpoint_object *self_bp = (breakpoint_object *) self;
> +
> +  BPPY_REQUIRE_VALID (self_bp);
> +
> +  if (self_bp->bp->disposition == disp_del
> +      || self_bp->bp->disposition == disp_del_at_next_stop)
> +    Py_RETURN_TRUE;
> +
> +  Py_RETURN_FALSE;
> +}
> +
>  /* Python function to get the breakpoint's number.  */
>  static PyObject *
>  bppy_get_number (PyObject *self, void *closure)
> @@ -594,16 +611,20 @@ bppy_get_ignore_count (PyObject *self, void *closure)
>  static int
>  bppy_init (PyObject *self, PyObject *args, PyObject *kwargs)
>  {
> -  static char *keywords[] = { "spec", "type", "wp_class", "internal", NULL };
> +  static char *keywords[] = { "spec", "type", "wp_class", "internal",
> +			      "temporary", NULL };
>    const char *spec;
>    int type = bp_breakpoint;
>    int access_type = hw_write;
>    PyObject *internal = NULL;
> +  PyObject *temporary = NULL;
>    int internal_bp = 0;
> +  int temporary_bp = 0;
>    volatile struct gdb_exception except;
>  
> -  if (! PyArg_ParseTupleAndKeywords (args, kwargs, "s|iiO", keywords,
> -				     &spec, &type, &access_type, &internal))
> +  if (! PyArg_ParseTupleAndKeywords (args, kwargs, "s|iiOO", keywords,
> +				     &spec, &type, &access_type,
> +				     &internal, &temporary))
>      return -1;
>  
>    if (internal)
> @@ -613,6 +634,13 @@ bppy_init (PyObject *self, PyObject *args, PyObject *kwargs)
>  	return -1;
>      }
>  
> +  if (temporary != NULL)
> +    {
> +      temporary_bp = PyObject_IsTrue (temporary);
> +      if (temporary_bp == -1)
> +	return -1;
> +    }
> +
>    bppy_pending_object = (breakpoint_object *) self;
>    bppy_pending_object->number = -1;
>    bppy_pending_object->bp = Tom Tromey <tromey@redhat.com>NULL;
> @@ -629,7 +657,7 @@ bppy_init (PyObject *self, PyObject *args, PyObject *kwargs)
>  	    create_breakpoint (python_gdbarch,
>  			       copy, NULL, -1, NULL,
>  			       0,
> -			       0, bp_breakpoint,
> +			       temporary_bp, bp_breakpoint,
>  			       0,
>  			       AUTO_BOOLEAN_TRUE,
>  			       &bkpt_breakpoint_ops,
> @@ -973,6 +1001,8 @@ or None if no condition set."},
>      "Type of breakpoint."},
>    { "visible", bppy_get_visibility, NULL,
>      "Whether the breakpoint is visible to the user."},
> +  { "temporary", bppy_get_temporary, NULL,
> +    "Whether this breakpoint is a temporary breakpoint."},
>    { NULL }  /* Sentinel.  */
>  };
>  
> diff --git a/gdb/testsuite/gdb.python/py-breakpoint.exp b/gdb/testsuite/gdb.python/py-breakpoint.exp
> index 687182d..e2a169b 100644
> --- a/gdb/testsuite/gdb.python/py-breakpoint.exp
> +++ b/gdb/testsuite/gdb.python/py-breakpoint.exp
> @@ -300,3 +300,37 @@ gdb_py_test_silent_cmd  "python wp1 = wp_eval (\"result\", type=gdb.BP_WATCHPOIN
>  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."
> +
> +# Test temporary breakpoint
> +
> +# 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 and check temporary breakpoint" \
> +  "python" "" \
> +  "class temp_bp (gdb.Breakpoint):" "" \
> +  "   count = 0" "" \
> +  "   def stop (self):" "" \
> +  "      self.count = self.count + 1" "" \
> +  "      return True" "" \
> +  "end" ""
> +gdb_py_test_silent_cmd  "python ibp =  temp_bp(\"$ibp_location\", temporary=True)" \
> +    "Set temporary breakpoint" 0
> +gdb_test "info breakpoints" "2.*breakpoint.*del.*py-breakpoint\.c:$ibp_location.*" \
> +    "Check info breakpoints shows breakpoint with temporary status"
> +gdb_test "python print (ibp.location)" "py-breakpoint\.c:$ibp_location*" \
> +    "Check temporary breakpoint location"
> +gdb_test "python print (ibp.temporary)" "True" \
> +    "Check breakpoint temporary status"
> +gdb_continue_to_breakpoint "Break at multiply." ".*/$srcfile:$ibp_location.*"
> +gdb_test "python print (ibp.count)" "1" \
> +    "Check temporary stop callback executed before deletion."
> +gdb_test "python print (ibp.temporary)" "RuntimeError: Breakpoint 2 is invalid.*" \
> +    "Check temporary breakpoint is deleted after being hit"
> +gdb_test "info breakpoints" "No breakpoints or watchpoints.*" \
> +    "Check info breakpoints shows temporary breakpoint is deleted"
> 
> 

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [python][patch] Add temporary breakpoint features to Python breakpoints.
  2013-09-18  9:09   ` Phil Muldoon
  2013-10-01 11:32     ` Phil Muldoon
  2013-10-10 19:49     ` Tom Tromey
@ 2013-10-10 19:49     ` Tom Tromey
  2 siblings, 0 replies; 12+ messages in thread
From: Tom Tromey @ 2013-10-10 19:49 UTC (permalink / raw)
  To: Phil Muldoon; +Cc: gdb-patches

Tom> Is there a PR associated with this?
Tom> I thought there was, but I didn't check.

Phil> I did a search and I could not find one.

Thanks.  I was thinking of the pending support.

Phil> Other nits fixed up too.  ChangeLog remains the same.

Phil> OK?

This is ok.  Thanks.

Tom

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [python][patch] Add temporary breakpoint features to Python breakpoints.
  2013-09-18  9:09   ` Phil Muldoon
  2013-10-01 11:32     ` Phil Muldoon
@ 2013-10-10 19:49     ` Tom Tromey
  2013-11-04 10:09       ` Phil Muldoon
  2013-10-10 19:49     ` Tom Tromey
  2 siblings, 1 reply; 12+ messages in thread
From: Tom Tromey @ 2013-10-10 19:49 UTC (permalink / raw)
  To: Phil Muldoon; +Cc: gdb-patches

Phil> * python/py-breakpoint.c (bppy_get_temporary): New function.
Phil> (bppy_init): New keyword: temporary. Parse it and set breakpoint
Phil> to temporary if True.

It occurs to me that this could use a NEWS entry.

Tom

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [python][patch] Add temporary breakpoint features to Python breakpoints.
  2013-10-10 19:49     ` Tom Tromey
@ 2013-11-04 10:09       ` Phil Muldoon
  2013-11-04 16:09         ` Eli Zaretskii
  0 siblings, 1 reply; 12+ messages in thread
From: Phil Muldoon @ 2013-11-04 10:09 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches, eliz

On 10/10/13 20:49, Tom Tromey wrote:
> Phil> * python/py-breakpoint.c (bppy_get_temporary): New function.
> Phil> (bppy_init): New keyword: temporary. Parse it and set breakpoint
> Phil> to temporary if True.
> 
> It occurs to me that this could use a NEWS entry.
> 
> Tom

Here you go.  OK?

Cheers,

Phil

2013-11-04  Phil Muldoon  <pmuldoon@redhat.com>

	* NEWS: Add note about temporary breakpoints in Python.

--

diff --git a/gdb/NEWS b/gdb/NEWS
index efeda68..d199e95 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -35,7 +35,8 @@
 * Python scripting
 
   ** Frame filters and frame decorators have been added.
-
+  ** Temporary breakpoints are now supported.
+  
 * New targets
 
 Nios II ELF                    nios2*-*-elf


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [python][patch] Add temporary breakpoint features to Python breakpoints.
  2013-11-04 10:09       ` Phil Muldoon
@ 2013-11-04 16:09         ` Eli Zaretskii
  2013-11-07 12:35           ` Phil Muldoon
  0 siblings, 1 reply; 12+ messages in thread
From: Eli Zaretskii @ 2013-11-04 16:09 UTC (permalink / raw)
  To: Phil Muldoon; +Cc: tromey, gdb-patches

> Date: Mon, 04 Nov 2013 10:09:15 +0000
> From: Phil Muldoon <pmuldoon@redhat.com>
> CC: gdb-patches@sourceware.org, "eliz@gnu.org" <eliz@gnu.org>
> 
> On 10/10/13 20:49, Tom Tromey wrote:
> > Phil> * python/py-breakpoint.c (bppy_get_temporary): New function.
> > Phil> (bppy_init): New keyword: temporary. Parse it and set breakpoint
> > Phil> to temporary if True.
> > 
> > It occurs to me that this could use a NEWS entry.
> > 
> > Tom
> 
> Here you go.  OK?

Yes, thanks.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [python][patch] Add temporary breakpoint features to Python breakpoints.
  2013-11-04 16:09         ` Eli Zaretskii
@ 2013-11-07 12:35           ` Phil Muldoon
  0 siblings, 0 replies; 12+ messages in thread
From: Phil Muldoon @ 2013-11-07 12:35 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: tromey, gdb-patches

On 04/11/13 16:05, Eli Zaretskii wrote:
>> Date: Mon, 04 Nov 2013 10:09:15 +0000
>> From: Phil Muldoon <pmuldoon@redhat.com>
>> CC: gdb-patches@sourceware.org, "eliz@gnu.org" <eliz@gnu.org>
>>
>> On 10/10/13 20:49, Tom Tromey wrote:
>>> Phil> * python/py-breakpoint.c (bppy_get_temporary): New function.
>>> Phil> (bppy_init): New keyword: temporary. Parse it and set breakpoint
>>> Phil> to temporary if True.
>>>
>>> It occurs to me that this could use a NEWS entry.
>>>
>>> Tom
>>
>> Here you go.  OK?
> 
> Yes, thanks.

So committed, thanks

Cheers,

Phil

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2013-11-07 12:21 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-09-09 10:05 [python][patch] Add temporary breakpoint features to Python breakpoints Phil Muldoon
2013-09-09 16:29 ` Eli Zaretskii
2013-09-09 18:47 ` Tom Tromey
2013-09-09 19:01   ` Phil Muldoon
2013-09-09 19:15     ` Tom Tromey
2013-09-18  9:09   ` Phil Muldoon
2013-10-01 11:32     ` Phil Muldoon
2013-10-10 19:49     ` Tom Tromey
2013-11-04 10:09       ` Phil Muldoon
2013-11-04 16:09         ` Eli Zaretskii
2013-11-07 12:35           ` Phil Muldoon
2013-10-10 19:49     ` Tom Tromey

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).