Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* Re: [PATCH] hardware watchpoints turned off, inferior not yet started
@ 2013-11-07 12:21 Jose E. Marchesi
  2013-11-08 12:03 ` Pedro Alves
  0 siblings, 1 reply; 12+ messages in thread
From: Jose E. Marchesi @ 2013-11-07 12:21 UTC (permalink / raw)
  To: gdb-patches


[Following https://sourceware.org/ml/gdb-patches/2013-10/msg00563.html]

Hi.

The patch posted above introduced a regression in sparc64-*-linux-gnu,
and possibly in other targets not supporting hardware watchpoints at
all.

Today I was surprised to find this in a sparc64-*-linux-gnu target:

 $ gdb foo
 ... intro text ...
 (gdb) watch global_var
 Hardware watchpoint 1: global_var

The cause for this regression is this code in update_watchpoint
(breakpoint.c):

+  if (!target_has_execution)
     {
       /* Without execution, memory can't change.  No use to try and
         set watchpoint locations.  The watchpoint will be reset when
         the target gains execution, through breakpoint_re_set.  */
+      if (!can_use_hw_watchpoints)
+       {
+         if (b->base.ops->works_in_software_mode (&b->base))
+           b->base.type = bp_watchpoint;
+         else
+           error (_("Software read/access watchpoints not supported."));
+       }

The watchpoint must be downgraded to a software watchpoint if the target
does not support hw watchpoints, even if can_use_hw_watchpoints is 1.

The following patch fixes this and also adds an additional test to
testsuite/watchpoints.exp to catch this problem.

2013-11-07  Jose E. Marchesi  <jose.marchesi@oracle.com>

	* breakpoint.c (update_watchpoint): Downgrade hw watchpoints to sw
	watchpoints in targets not supporting them, when the inferior is
        not running.

2013-11-07  Jose E. Marchesi  <jose.marchesi@oracle.com>

	* gdb.base/watchpoints.exp: Add a test to ensure that a watchpoint
	is not created as a hw watchpoint in targets not supporting them,
	even if can-use-hw-watchpoints is 1 when the inferior is not
        running.

diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index ffe73fd..597e6f9 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -1800,7 +1800,10 @@ update_watchpoint (struct watchpoint *b, int reparse)
       /* Without execution, memory can't change.  No use to try and
 	 set watchpoint locations.  The watchpoint will be reset when
 	 the target gains execution, through breakpoint_re_set.  */
-      if (!can_use_hw_watchpoints)
+      int i = hw_breakpoint_used_count ();
+      int target_supports_hw_watchpoints =
+	target_can_use_hardware_watchpoint (bp_hardware_watchpoint, i + 1, 0);
+      if (!target_supports_hw_watchpoints || !can_use_hw_watchpoints)
 	{
 	  if (b->base.ops->works_in_software_mode (&b->base))
 	    b->base.type = bp_watchpoint;
--- a/gdb/testsuite/gdb.base/watchpoints.exp
+++ b/gdb/testsuite/gdb.base/watchpoints.exp
@@ -30,6 +30,15 @@ if {[prepare_for_testing $testfile.exp $testfile $srcfile debug]} {
 }
 
 with_test_prefix "before inferior start" {
+    if [target_info exists gdb,no_hardware_watchpoints] {
+	# Ensure that a watchpoint is not created as a hw watchpoint
+	# even if can-use-hw-watchpoints is 1 when the inferior is not
+	# running.
+	gdb_test_no_output "set can-use-hw-watchpoints 1"
+	gdb_test "watch ival1" "Watchpoint \[0-9\]+: ival1" \
+	    "create sw watchpoint"
+    }
+
     # Ensure that if we turn off hardware watchpoints and set a watch point
     # before starting the inferior the watchpoint created will not be a
     # hardware watchpoint.



^ permalink raw reply	[flat|nested] 12+ messages in thread
* [PATCH] hardware watchpoints turned off, inferior not yet started
@ 2013-10-16  9:39 Andrew Burgess
  2013-10-16 12:32 ` Pedro Alves
  0 siblings, 1 reply; 12+ messages in thread
From: Andrew Burgess @ 2013-10-16  9:39 UTC (permalink / raw)
  To: gdb-patches

The following seems confusing to me:

$ gdb -q watch.x
Reading symbols from /some/path/to/watch.x...done.
(gdb) set can-use-hw-watchpoints 0
(gdb) watch -l my_var 
Hardware watchpoint 1: -location my_var
(gdb) 

Notice that despite turning hardware watchpoints off
the watchpoint created is reported to be a hardware
watchpoint.  Once I actually start the inferior the
watchpoint is downgraded to a software watchpoint,
but still, this feels like it might cause confusion,
and is pretty easy to fix.

OK to apply?

Thanks,
Andrew


gdb/ChangeLog

2013-10-16  Andrew Burgess  <aburgess@broadcom.com>

	* breakpoint.c (update_watchpoint): Create software watchpoints if
	the inferior has not yet started and hardware watchpoints are
	turned off.

gdb/testsuite/ChangeLog

2013-10-16  Andrew Burgess  <aburgess@broadcom.com>

	* gdb.base/watchpoints.exp: Add test for setting software
	watchpoint before starting the inferior.


diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index 5ce50de..2902dc1 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -1800,6 +1800,8 @@ update_watchpoint (struct watchpoint *b, int reparse)
       /* Without execution, memory can't change.  No use to try and
 	 set watchpoint locations.  The watchpoint will be reset when
 	 the target gains execution, through breakpoint_re_set.  */
+      if (!can_use_hw_watchpoints)
+	b->base.type = bp_watchpoint;
     }
   else if (within_current_scope && b->exp)
     {
diff --git a/gdb/testsuite/gdb.base/watchpoints.exp b/gdb/testsuite/gdb.base/watchpoints.exp
index 7c10d81..2442bcd 100644
--- a/gdb/testsuite/gdb.base/watchpoints.exp
+++ b/gdb/testsuite/gdb.base/watchpoints.exp
@@ -29,6 +29,17 @@ if {[prepare_for_testing $testfile.exp $testfile $srcfile debug]} {
     return -1
 }
 
+    # Ensure that if we turn off hardware watchpoints and set a watch point
+    # before starting the inferior the watchpoint created will not be a
+    # hardware watchpoint.
+    gdb_test_no_output "set can-use-hw-watchpoints 0" ""
+    gdb_test "watch ival1" "Watchpoint \[0-9\]+: ival1" \
+        "Set software watchpoint before starting the inferior"
+
+    # This will turn hardware watchpoints back on and delete the watchpoint
+    # we just created.
+    clean_restart ${binfile}
+
     # Disable hardware watchpoints if necessary.
     if [target_info exists gdb,no_hardware_watchpoints] {
         gdb_test_no_output "set can-use-hw-watchpoints 0" ""



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

end of thread, other threads:[~2013-11-08 11:43 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-11-07 12:21 [PATCH] hardware watchpoints turned off, inferior not yet started Jose E. Marchesi
2013-11-08 12:03 ` Pedro Alves
  -- strict thread matches above, loose matches on Subject: below --
2013-10-16  9:39 Andrew Burgess
2013-10-16 12:32 ` Pedro Alves
2013-10-16 15:43   ` Andrew Burgess
2013-10-16 16:28     ` Pedro Alves
2013-10-18  9:14       ` Andrew Burgess
2013-10-18 14:37         ` Andrew Burgess
2013-10-18 15:33           ` Pedro Alves
2013-10-18 16:26             ` Andrew Burgess
2013-10-18 15:26         ` Pedro Alves
2013-10-18 15:43           ` Andrew Burgess

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox