public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [python][patch] PR python/19151 Hardware breakpoints in GDB Python.
@ 2018-04-30 11:47 Phil Muldoon
  2018-04-30 12:37 ` Phil Muldoon
  2018-04-30 14:31 ` Eli Zaretskii
  0 siblings, 2 replies; 5+ messages in thread
From: Phil Muldoon @ 2018-04-30 11:47 UTC (permalink / raw)
  To: gdb-patches


This patch adds hardware breakpoint support for code based breakpoints
to the Python API.

Cheers,

Phil

2018-04-30  Phil Muldoon  <pmuldoon@redhat.com>

	PR python/19151
	* python/py-breakpoint.c: Add hardware breakpoint constant
	gdb.BP_HARDWARE_BREAKPOINT.
	(bppy_init): Add bp_hardware_breakpoint case. Use the enum bptype
	variable

2018-04-30  Phil Muldoon  <pmuldoon@redhat.com>

	* gdb.python/py-breakpoint.exp: Call test_hardware_breakpoints.
	(test_hardware_breakpoints): New function.

2018-04-30  Phil Muldoon  <pmuldoon@redhat.com>

	* python.texi (Breakpoints In Python): Mention
	gdb.BP_HARDWARE_BREAKPOINT.

--

diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi
index 28a7a1a9f5..9ca8f489bf 100644
--- a/gdb/doc/python.texi
+++ b/gdb/doc/python.texi
@@ -1,4 +1,4 @@
-@c Copyright (C) 2008-2017 Free Software Foundation, Inc.
+@c Copyright (C) 2008-2018 Free Software Foundation, Inc.
 @c Permission is granted to copy, distribute and/or modify this document
 @c under the terms of the GNU Free Documentation License, Version 1.3 or
 @c any later version published by the Free Software Foundation; with the
@@ -4888,20 +4888,20 @@ breakpoint (@pxref{Explicit Locations}) according to the
 specifications contained in the key words @var{source},
 @var{function}, @var{label} and @var{line}.  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}; it 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.
+chapter.  This argument can be either @code{gdb.BP_BREAKPOINT},
+@code{gdb.BP_HARDWARE_BREAKPOINT} or @code{gdb.BP_WATCHPOINT}; it
+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
 
 The available types are represented by constants defined in the @code{gdb}
@@ -4912,6 +4912,10 @@ module:
 @item gdb.BP_BREAKPOINT
 Normal code breakpoint.
 
+@vindex BP_BREAKPOINT
+@item gdb.BP_HARDWARE_BREAKPOINT
+Hardware assisted code breakpoint.
+
 @vindex BP_WATCHPOINT
 @item gdb.BP_WATCHPOINT
 Watchpoint breakpoint.
diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c
index f865317ab3..76a06898e9 100644
--- a/gdb/python/py-breakpoint.c
+++ b/gdb/python/py-breakpoint.c
@@ -1,6 +1,6 @@
 /* Python interface to breakpoints
 
-   Copyright (C) 2008-2017 Free Software Foundation, Inc.
+   Copyright (C) 2008-2018 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -58,6 +58,7 @@ static struct pybp_code pybp_codes[] =
 {
   { "BP_NONE", bp_none},
   { "BP_BREAKPOINT", bp_breakpoint},
+  { "BP_HARDWARE_BREAKPOINT", bp_hardware_breakpoint},
   { "BP_WATCHPOINT", bp_watchpoint},
   { "BP_HARDWARE_WATCHPOINT", bp_hardware_watchpoint},
   { "BP_READ_WATCHPOINT", bp_read_watchpoint},
@@ -757,6 +758,7 @@ bppy_init (PyObject *self, PyObject *args, PyObject *kwargs)
       switch (type)
 	{
 	case bp_breakpoint:
+	case bp_hardware_breakpoint:
 	  {
 	    event_location_up location;
 
@@ -788,7 +790,7 @@ bppy_init (PyObject *self, PyObject *args, PyObject *kwargs)
 	    create_breakpoint (python_gdbarch,
 			       location.get (), NULL, -1, NULL,
 			       0,
-			       temporary_bp, bp_breakpoint,
+			       temporary_bp, type,
 			       0,
 			       AUTO_BOOLEAN_TRUE,
 			       &bkpt_breakpoint_ops,
@@ -963,6 +965,7 @@ gdbpy_breakpoint_created (struct breakpoint *bp)
     return;
 
   if (bp->type != bp_breakpoint
+      && bp->type != bp_hardware_breakpoint
       && bp->type != bp_watchpoint
       && bp->type != bp_hardware_watchpoint
       && bp->type != bp_read_watchpoint
diff --git a/gdb/testsuite/gdb.python/py-breakpoint.exp b/gdb/testsuite/gdb.python/py-breakpoint.exp
index e89b9b8446..fdce60839a 100644
--- a/gdb/testsuite/gdb.python/py-breakpoint.exp
+++ b/gdb/testsuite/gdb.python/py-breakpoint.exp
@@ -1,4 +1,4 @@
-# Copyright (C) 2010-2017 Free Software Foundation, Inc.
+# Copyright (C) 2010-2018 Free Software Foundation, Inc.
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -610,6 +610,33 @@ proc test_bkpt_explicit_loc {} {
     }
 }
 
+# Test hardware assisted breakpoints
+proc_with_prefix test_hardware_breakpoints { } {
+    global srcfile testfile decimal
+
+    # Start with a fresh gdb.
+    clean_restart ${testfile}
+
+    if {[skip_hw_breakpoint_tests]} {
+	unsupported "Hardware breakpoints."
+    }
+
+    if ![runto_main] then {
+	fail "cannot run to main."
+	return 0
+    }
+
+    set hardware_location [gdb_get_line_number "Break at multiply."]
+    gdb_test  "python hbp = gdb.Breakpoint (\"$hardware_location\", type=gdb.BP_HARDWARE_BREAKPOINT)" \
+	".*Hardware assisted breakpoint ($decimal)+ at .*$srcfile, line ($decimal)+\." \
+	"Set hardware breakpoint"
+    gdb_continue_to_breakpoint "Break at multiply." \
+	".*$srcfile:$hardware_location.*"
+    gdb_test "info breakpoints" \
+	"2.*hw breakpoint.*$srcfile:$hardware_location.*" \
+	"Check info breakpoints shows a hardware breakpoint"
+}
+
 test_bkpt_basic
 test_bkpt_deletion
 test_bkpt_cond_and_cmds
@@ -622,3 +649,4 @@ test_bkpt_address
 test_bkpt_pending
 test_bkpt_events
 test_bkpt_explicit_loc
+test_hardware_breakpoints

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

* Re: [python][patch] PR python/19151 Hardware breakpoints in GDB Python.
  2018-04-30 11:47 [python][patch] PR python/19151 Hardware breakpoints in GDB Python Phil Muldoon
@ 2018-04-30 12:37 ` Phil Muldoon
  2018-04-30 14:33   ` Eli Zaretskii
  2018-05-09 14:31   ` Pedro Alves
  2018-04-30 14:31 ` Eli Zaretskii
  1 sibling, 2 replies; 5+ messages in thread
From: Phil Muldoon @ 2018-04-30 12:37 UTC (permalink / raw)
  To: gdb-patches

On 30/04/18 12:46, Phil Muldoon wrote:
> 
> This patch adds hardware breakpoint support for code based breakpoints
> to the Python API.
> 
> Cheers,

My apologies but I mistakenly applied this patch to a much older
version of GDB HEAD (I did not realize the git pull master had
failed.) The following patch is the correct patch and has been
re-flowed and adjusted to current HEAD.

2018-04-30  Phil Muldoon  <pmuldoon@redhat.com>
 
 	PR python/19151
 	* python/py-breakpoint.c: Add hardware breakpoint constant
 	gdb.BP_HARDWARE_BREAKPOINT.
 	(bppy_init): Add bp_hardware_breakpoint case. Use the enum bptype
 	variable
 
2018-04-30  Phil Muldoon  <pmuldoon@redhat.com>
 
	* gdb.python/py-breakpoint.exp: Call test_hardware_breakpoints.
 	(test_hardware_breakpoints): New function.
 
2018-04-30  Phil Muldoon  <pmuldoon@redhat.com>
 
 	* python.texi (Breakpoints In Python): Mention
 	gdb.BP_HARDWARE_BREAKPOINT.

--

diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi
index ebd48fffe7..dd1fd101f1 100644
--- a/gdb/doc/python.texi
+++ b/gdb/doc/python.texi
@@ -4937,6 +4937,10 @@ module:
 @item gdb.BP_BREAKPOINT
 Normal code breakpoint.
 
+@vindex BP_BREAKPOINT
+@item gdb.BP_HARDWARE_BREAKPOINT
+Hardware assisted code breakpoint.
+
 @vindex BP_WATCHPOINT
 @item gdb.BP_WATCHPOINT
 Watchpoint breakpoint.
diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c
index d654b92a8c..049d8d6d11 100644
--- a/gdb/python/py-breakpoint.c
+++ b/gdb/python/py-breakpoint.c
@@ -58,6 +58,7 @@ static struct pybp_code pybp_codes[] =
 {
   { "BP_NONE", bp_none},
   { "BP_BREAKPOINT", bp_breakpoint},
+  { "BP_HARDWARE_BREAKPOINT", bp_hardware_breakpoint},
   { "BP_WATCHPOINT", bp_watchpoint},
   { "BP_HARDWARE_WATCHPOINT", bp_hardware_watchpoint},
   { "BP_READ_WATCHPOINT", bp_read_watchpoint},
@@ -759,6 +760,7 @@ bppy_init (PyObject *self, PyObject *args, PyObject *kwargs)
       switch (type)
 	{
 	case bp_breakpoint:
+	case bp_hardware_breakpoint:
 	  {
 	    event_location_up location;
 	    symbol_name_match_type func_name_match_type
@@ -797,7 +799,7 @@ bppy_init (PyObject *self, PyObject *args, PyObject *kwargs)
 	    create_breakpoint (python_gdbarch,
 			       location.get (), NULL, -1, NULL,
 			       0,
-			       temporary_bp, bp_breakpoint,
+			       temporary_bp, type,
 			       0,
 			       AUTO_BOOLEAN_TRUE,
 			       &bkpt_breakpoint_ops,
@@ -972,6 +974,7 @@ gdbpy_breakpoint_created (struct breakpoint *bp)
     return;
 
   if (bp->type != bp_breakpoint
+      && bp->type != bp_hardware_breakpoint
       && bp->type != bp_watchpoint
       && bp->type != bp_hardware_watchpoint
       && bp->type != bp_read_watchpoint
diff --git a/gdb/testsuite/gdb.python/py-breakpoint.exp b/gdb/testsuite/gdb.python/py-breakpoint.exp
index 6e0ff88f87..156dcbfa9a 100644
--- a/gdb/testsuite/gdb.python/py-breakpoint.exp
+++ b/gdb/testsuite/gdb.python/py-breakpoint.exp
@@ -681,6 +681,33 @@ proc_with_prefix test_bkpt_qualified {} {
 	"-q in spec string and qualified false"
 }
 
+# Test hardware assisted breakpoints
+proc_with_prefix test_hardware_breakpoints { } {
+    global srcfile testfile decimal
+
+    # Start with a fresh gdb.
+    clean_restart ${testfile}
+
+    if {[skip_hw_breakpoint_tests]} {
+	unsupported "Hardware breakpoints."
+    }
+
+    if ![runto_main] then {
+	fail "cannot run to main."
+	return 0
+    }
+
+    set hardware_location [gdb_get_line_number "Break at multiply."]
+    gdb_test  "python hbp = gdb.Breakpoint (\"$hardware_location\", type=gdb.BP_HARDWARE_BREAKPOINT)" \
+	".*Hardware assisted breakpoint ($decimal)+ at .*$srcfile, line ($decimal)+\." \
+	"Set hardware breakpoint"
+    gdb_continue_to_breakpoint "Break at multiply." \
+	".*$srcfile:$hardware_location.*"
+    gdb_test "info breakpoints" \
+	"2.*hw breakpoint.*$srcfile:$hardware_location.*" \
+	"Check info breakpoints shows a hardware breakpoint"
+}
+
 test_bkpt_basic
 test_bkpt_deletion
 test_bkpt_cond_and_cmds
@@ -694,3 +721,4 @@ test_bkpt_pending
 test_bkpt_events
 test_bkpt_explicit_loc
 test_bkpt_qualified
+test_hardware_breakpoints

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

* Re: [python][patch] PR python/19151 Hardware breakpoints in GDB Python.
  2018-04-30 11:47 [python][patch] PR python/19151 Hardware breakpoints in GDB Python Phil Muldoon
  2018-04-30 12:37 ` Phil Muldoon
@ 2018-04-30 14:31 ` Eli Zaretskii
  1 sibling, 0 replies; 5+ messages in thread
From: Eli Zaretskii @ 2018-04-30 14:31 UTC (permalink / raw)
  To: Phil Muldoon; +Cc: gdb-patches

> From: Phil Muldoon <pmuldoon@redhat.com>
> Date: Mon, 30 Apr 2018 12:46:57 +0100
> 
> 2018-04-30  Phil Muldoon  <pmuldoon@redhat.com>
> 
> 	* python.texi (Breakpoints In Python): Mention
> 	gdb.BP_HARDWARE_BREAKPOINT.

OK for this part.

(Is this NEWS-worthy?)

Thanks.

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

* Re: [python][patch] PR python/19151 Hardware breakpoints in GDB Python.
  2018-04-30 12:37 ` Phil Muldoon
@ 2018-04-30 14:33   ` Eli Zaretskii
  2018-05-09 14:31   ` Pedro Alves
  1 sibling, 0 replies; 5+ messages in thread
From: Eli Zaretskii @ 2018-04-30 14:33 UTC (permalink / raw)
  To: Phil Muldoon; +Cc: gdb-patches

> From: Phil Muldoon <pmuldoon@redhat.com>
> Date: Mon, 30 Apr 2018 13:37:36 +0100
> 
> 2018-04-30  Phil Muldoon  <pmuldoon@redhat.com>
>  
>  	* python.texi (Breakpoints In Python): Mention
>  	gdb.BP_HARDWARE_BREAKPOINT.

OK for this part.  Same question regarding NEWS.

Thanks.

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

* Re: [python][patch] PR python/19151 Hardware breakpoints in GDB Python.
  2018-04-30 12:37 ` Phil Muldoon
  2018-04-30 14:33   ` Eli Zaretskii
@ 2018-05-09 14:31   ` Pedro Alves
  1 sibling, 0 replies; 5+ messages in thread
From: Pedro Alves @ 2018-05-09 14:31 UTC (permalink / raw)
  To: Phil Muldoon, gdb-patches

Hi Phil,

I agree with Eli, this should be mentioned in NEWS, as all
Python API additions/changes do.

Some nits below, but otherwise looks fine.

Please post a v2 with a NEWS entry, including the proposed
git commit log, and it should be good to go.

On 04/30/2018 01:37 PM, Phil Muldoon wrote:
> 
> 2018-04-30  Phil Muldoon  <pmuldoon@redhat.com>
>  
>  	PR python/19151
>  	* python/py-breakpoint.c: Add hardware breakpoint constant
>  	gdb.BP_HARDWARE_BREAKPOINT.

Mention "(pybp_codes)":

  	* python/py-breakpoint.c (pybp_codes): Add hardware
        breakpoint constant gdb.BP_HARDWARE_BREAKPOINT.

>  	(bppy_init): Add bp_hardware_breakpoint case. Use the enum bptype
>  	variable

Double space after '.' and missing '.' at end of second sentence.

> --- a/gdb/testsuite/gdb.python/py-breakpoint.exp
> +++ b/gdb/testsuite/gdb.python/py-breakpoint.exp
> @@ -681,6 +681,33 @@ proc_with_prefix test_bkpt_qualified {} {
>  	"-q in spec string and qualified false"
>  }
>  
> +# Test hardware assisted breakpoints
> +proc_with_prefix test_hardware_breakpoints { } {
> +    global srcfile testfile decimal
> +
> +    # Start with a fresh gdb.
> +    clean_restart ${testfile}
> +
> +    if {[skip_hw_breakpoint_tests]} {
> +	unsupported "Hardware breakpoints."

Missing "return"

> +    }

> +
> +    if ![runto_main] then {
> +	fail "cannot run to main."
> +	return 0
> +    }
> +
> +    set hardware_location [gdb_get_line_number "Break at multiply."]
> +    gdb_test  "python hbp = gdb.Breakpoint (\"$hardware_location\", type=gdb.BP_HARDWARE_BREAKPOINT)" \

               ^^ spurious double space.

> +	".*Hardware assisted breakpoint ($decimal)+ at .*$srcfile, line ($decimal)+\." \

Leading ".*" not necessary, it's implied.

> +	"Set hardware breakpoint"

Lowercase "Set".

> +    gdb_continue_to_breakpoint "Break at multiply." \
> +	".*$srcfile:$hardware_location.*"

Leading ".*" not necessary, it's implied.

> +    gdb_test "info breakpoints" \
> +	"2.*hw breakpoint.*$srcfile:$hardware_location.*" \
> +	"Check info breakpoints shows a hardware breakpoint"

Lowercase "Check".  I'd remove "check, even, since all tests
are checking something:

	"info breakpoints shows a hardware breakpoint"

Thanks,
Pedro Alves

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

end of thread, other threads:[~2018-05-09 14:31 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-30 11:47 [python][patch] PR python/19151 Hardware breakpoints in GDB Python Phil Muldoon
2018-04-30 12:37 ` Phil Muldoon
2018-04-30 14:33   ` Eli Zaretskii
2018-05-09 14:31   ` Pedro Alves
2018-04-30 14:31 ` Eli Zaretskii

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