This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch] Check watchpoint resources before enabling a watchpoint.


Hi,

Attached is a patch to delay enabling until after checking watchpoint
resources.

Without this patch, testing on ColdFire ELF shows:

FAIL: gdb.base/watchpoint.exp: enable watchpoint
FAIL: gdb.base/watchpoint.exp: watchpoints found in watchpoint/breakpoint table
FAIL: gdb.base/watchpoint.exp: watchpoint enabled

The problem is that we enable a watchpoint before checking its
resources.

The patch fixes the problem by changing the order.

The patch also teaches do_enable_breakpoint to free bpt->val only when
it is non-NULL.  It could be NULL if the value being watched has never
been read before.

Tested on m68k-elf.  OK to apply?

Kazu Hirata

2007-09-27  Daniel Jacobowitz  <dan@codesourcery.com>
	    Kazu Hirata  <kazu@codesourcery.com>

	* breakpoint.c (do_enable_breakpoint): Delay enabling until after
	checking watchpoint resources.

Index: gdb/breakpoint.c
===================================================================
RCS file: /cvs/src/src/gdb/breakpoint.c,v
retrieving revision 1.270
diff -u -d -p -r1.270 breakpoint.c
--- gdb/breakpoint.c	26 Sep 2007 18:44:55 -0000	1.270
+++ gdb/breakpoint.c	27 Sep 2007 14:45:23 -0000
@@ -8036,12 +8036,6 @@ do_enable_breakpoint (struct breakpoint 
 	error (_("Hardware breakpoints used exceeds limit."));
     }
 
-  if (bpt->enable_state != bp_permanent)
-    bpt->enable_state = bp_enabled;
-  bpt->disposition = disposition;
-  check_duplicates (bpt);
-  breakpoints_changed ();
-  
   if (bpt->type == bp_watchpoint || 
       bpt->type == bp_hardware_watchpoint ||
       bpt->type == bp_read_watchpoint || 
@@ -8059,13 +8053,13 @@ do_enable_breakpoint (struct breakpoint 
 	      printf_filtered (_("\
 Cannot enable watchpoint %d because the block in which its expression\n\
 is valid is not currently in scope.\n"), bpt->number);
-	      bpt->enable_state = bp_disabled;
 	      return;
 	    }
 	  select_frame (fr);
 	}
       
-      value_free (bpt->val);
+      if (bpt->val)
+	value_free (bpt->val);
       mark = value_mark ();
       bpt->val = evaluate_expression (bpt->exp);
       release_value (bpt->val);
@@ -8090,7 +8084,6 @@ is valid is not currently in scope.\n"),
 	      printf_filtered (_("\
 Cannot enable watchpoint %d because target watch resources\n\
 have been allocated for other watchpoints.\n"), bpt->number);
-	      bpt->enable_state = bp_disabled;
 	      value_free_to_mark (mark);
 	      return;
 	    }
@@ -8100,6 +8093,12 @@ have been allocated for other watchpoint
       value_free_to_mark (mark);
     }
 
+  if (bpt->enable_state != bp_permanent)
+    bpt->enable_state = bp_enabled;
+  bpt->disposition = disposition;
+  check_duplicates (bpt);
+  breakpoints_changed ();
+  
   if (deprecated_modify_breakpoint_hook)
     deprecated_modify_breakpoint_hook (bpt);
   breakpoint_modify_event (bpt->number);


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]