This is the mail archive of the gdb-patches@sources.redhat.com 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]

RFA: Breakpoint infrastructure cleanups [8/8] - convert remove_breakpoints


This converts remove_breakpoint similarly to insert_breakpoints.  It also
fixes a typo involving overlays and hardware breakpoints (!= vs ==).  Other
than that it's mechanical.

That's it for now.  Most of what's left involves the question of how to
print breakpoints with multiple addresses.

-- 
Daniel Jacobowitz
MontaVista Software                         Debian GNU/Linux Developer

2003-10-08  Daniel Jacobowitz  <drow@mvista.com>

	* breakpoint.c (remove_breakpoint): Take an impl_breakpoint
	instead of a breakpoint argument.  Check the impl_breakpoint's type.
	Fix a reversed condition for hardware breakpoints.

	(insert_impl_breakpoint): Update call to remove_breakpoint.
	(remove_breakpoints): Likewise.  Use ALL_IMPL_BREAKPOINTS.
	(remove_hw_watchpoints): Likewise.
	(reattach_breakpoints): Likewise.
	(detach_breakpoints): Likewise.
	(delete_breakpoint): Likewise.

%patch
Index: gdb/breakpoint.c
===================================================================
--- gdb.orig/breakpoint.c	2003-10-08 12:42:12.000000000 -0400
+++ gdb/breakpoint.c	2003-10-08 12:42:13.000000000 -0400
@@ -124,7 +124,7 @@ typedef enum
   }
 insertion_state_t;
 
-static int remove_breakpoint (struct breakpoint *, insertion_state_t);
+static int remove_breakpoint (struct impl_breakpoint *, insertion_state_t);
 
 static enum print_stop_action print_it_typical (bpstat);
 
@@ -972,7 +972,7 @@ insert_impl_breakpoint (struct impl_brea
 	     value chain brings us here.  */
 	  if (!bpt->inserted)
 	    {
-	      remove_breakpoint (bpt->owner, mark_uninserted);
+	      remove_breakpoint (bpt, mark_uninserted);
 	      *hw_breakpoint_error = 1;
 	      fprintf_unfiltered (tmp_error_stream,
 				  "Could not insert hardware watchpoint %d.\n", 
@@ -1146,12 +1146,12 @@ You may have requested too many hardware
 int
 remove_breakpoints (void)
 {
-  struct breakpoint *b;
+  struct impl_breakpoint *b;
   int val;
 
-  ALL_BREAKPOINTS (b)
+  ALL_IMPL_BREAKPOINTS (b)
   {
-    if (b->impl->inserted)
+    if (b->inserted)
       {
 	val = remove_breakpoint (b, mark_uninserted);
 	if (val != 0)
@@ -1164,15 +1164,12 @@ remove_breakpoints (void)
 int
 remove_hw_watchpoints (void)
 {
-  struct breakpoint *b;
+  struct impl_breakpoint *b;
   int val;
 
-  ALL_BREAKPOINTS (b)
+  ALL_IMPL_BREAKPOINTS (b)
   {
-    if (b->impl->inserted
-	&& (b->type == bp_hardware_watchpoint
-	    || b->type == bp_read_watchpoint
-	    || b->type == bp_access_watchpoint))
+    if (b->inserted && b->type == impl_bp_hardware_watchpoint)
       {
 	val = remove_breakpoint (b, mark_uninserted);
 	if (val != 0)
@@ -1185,21 +1182,23 @@ remove_hw_watchpoints (void)
 int
 reattach_breakpoints (int pid)
 {
-  struct breakpoint *b;
+  struct impl_breakpoint *b;
   int val;
   struct cleanup *old_chain = save_inferior_ptid ();
 
   /* Set inferior_ptid; remove_breakpoint uses this global.  */
   inferior_ptid = pid_to_ptid (pid);
-  ALL_BREAKPOINTS (b)
+  ALL_IMPL_BREAKPOINTS (b)
   {
-    if (b->impl->inserted)
+    if (b->inserted)
       {
 	remove_breakpoint (b, mark_inserted);
-	if (b->type == bp_hardware_breakpoint)
-	  val = target_insert_hw_breakpoint (b->impl->address, b->impl->shadow_contents);
+	if (b->type == impl_bp_hardware_breakpoint)
+	  val = target_insert_hw_breakpoint (b->address, b->shadow_contents);
 	else
-	  val = target_insert_breakpoint (b->impl->address, b->impl->shadow_contents);
+	  val = target_insert_breakpoint (b->address, b->shadow_contents);
+	/* FIXME drow/2003-10-07: This doesn't handle any other kinds of
+	   breakpoints.  It's wrong for watchpoints, for example.  */
 	if (val != 0)
 	  {
 	    do_cleanups (old_chain);
@@ -1348,7 +1347,7 @@ update_breakpoints_after_exec (void)
 int
 detach_breakpoints (int pid)
 {
-  struct breakpoint *b;
+  struct impl_breakpoint *b;
   int val;
   struct cleanup *old_chain = save_inferior_ptid ();
 
@@ -1357,9 +1356,9 @@ detach_breakpoints (int pid)
 
   /* Set inferior_ptid; remove_breakpoint uses this global.  */
   inferior_ptid = pid_to_ptid (pid);
-  ALL_BREAKPOINTS (b)
+  ALL_IMPL_BREAKPOINTS (b)
   {
-    if (b->impl->inserted)
+    if (b->inserted)
       {
 	val = remove_breakpoint (b, mark_inserted);
 	if (val != 0)
@@ -1374,27 +1373,20 @@ detach_breakpoints (int pid)
 }
 
 static int
-remove_breakpoint (struct breakpoint *b, insertion_state_t is)
+remove_breakpoint (struct impl_breakpoint *b, insertion_state_t is)
 {
   int val;
 
-  if (b->enable_state == bp_permanent)
+  if (b->owner->enable_state == bp_permanent)
     /* Permanent breakpoints cannot be inserted or removed.  */
     return 0;
 
-  if (b->type == bp_none)
+  if (b->owner->type == bp_none)
     warning ("attempted to remove apparently deleted breakpoint #%d?", 
-	     b->number);
+	     b->owner->number);
 
-  if (b->type != bp_watchpoint
-      && b->type != bp_hardware_watchpoint
-      && b->type != bp_read_watchpoint
-      && b->type != bp_access_watchpoint
-      && b->type != bp_catch_fork
-      && b->type != bp_catch_vfork
-      && b->type != bp_catch_exec
-      && b->type != bp_catch_catch
-      && b->type != bp_catch_throw)
+  if (b->type == impl_bp_software_breakpoint
+      || b->type == impl_bp_hardware_breakpoint)
     {
       /* "Normal" instruction breakpoint: either the standard
 	 trap-instruction bp (bp_breakpoint), or a
@@ -1402,16 +1394,16 @@ remove_breakpoint (struct breakpoint *b,
 
       /* First check to see if we have to handle an overlay.  */
       if (overlay_debugging == ovly_off
-	  || b->impl->section == NULL
-	  || !(section_is_overlay (b->impl->section)))
+	  || b->section == NULL
+	  || !(section_is_overlay (b->section)))
 	{
 	  /* No overlay handling: just remove the breakpoint.  */
 
-	  if (b->type == bp_hardware_breakpoint)
-	    val = target_remove_hw_breakpoint (b->impl->address, 
-					       b->impl->shadow_contents);
+	  if (b->type == impl_bp_hardware_breakpoint)
+	    val = target_remove_hw_breakpoint (b->address, 
+					       b->shadow_contents);
 	  else
-	    val = target_remove_breakpoint (b->impl->address, b->impl->shadow_contents);
+	    val = target_remove_breakpoint (b->address, b->shadow_contents);
 	}
       else
 	{
@@ -1422,29 +1414,29 @@ remove_breakpoint (struct breakpoint *b,
 		/* Yes -- overlay event support is not active, so we
 		   should have set a breakpoint at the LMA.  Remove it.  
 		*/
-		CORE_ADDR addr = overlay_unmapped_address (b->impl->address, 
-							   b->impl->section);
+		CORE_ADDR addr = overlay_unmapped_address (b->address, 
+							   b->section);
 		/* Ignore any failures: if the LMA is in ROM, we will
 		   have already warned when we failed to insert it.  */
-		if (b->type != bp_hardware_breakpoint)
-		  target_remove_hw_breakpoint (addr, b->impl->shadow_contents);
+		if (b->type == impl_bp_hardware_breakpoint)
+		  target_remove_hw_breakpoint (addr, b->shadow_contents);
 		else
-		  target_remove_breakpoint (addr, b->impl->shadow_contents);
+		  target_remove_breakpoint (addr, b->shadow_contents);
 	      }
 	  /* Did we set a breakpoint at the VMA? 
 	     If so, we will have marked the breakpoint 'inserted'.  */
-	  if (b->impl->inserted)
+	  if (b->inserted)
 	    {
 	      /* Yes -- remove it.  Previously we did not bother to
 		 remove the breakpoint if the section had been
 		 unmapped, but let's not rely on that being safe.  We
 		 don't know what the overlay manager might do.  */
-	      if (b->type == bp_hardware_breakpoint)
-		val = target_remove_hw_breakpoint (b->impl->address, 
-						   b->impl->shadow_contents);
+	      if (b->type == impl_bp_hardware_breakpoint)
+		val = target_remove_hw_breakpoint (b->address, 
+						   b->shadow_contents);
 	      else
-		val = target_remove_breakpoint (b->impl->address,
-						b->impl->shadow_contents);
+		val = target_remove_breakpoint (b->address,
+						b->shadow_contents);
 	    }
 	  else
 	    {
@@ -1454,20 +1446,18 @@ remove_breakpoint (struct breakpoint *b,
 	}
       if (val)
 	return val;
-      b->impl->inserted = (is == mark_inserted);
+      b->inserted = (is == mark_inserted);
     }
-  else if ((b->type == bp_hardware_watchpoint ||
-	    b->type == bp_read_watchpoint ||
-	    b->type == bp_access_watchpoint)
-	   && b->enable_state == bp_enabled
-	   && !b->impl->duplicate)
+  else if (b->type == impl_bp_hardware_watchpoint
+	   && b->owner->enable_state == bp_enabled
+	   && !b->duplicate)
     {
       struct value *v;
       struct value *n;
 
-      b->impl->inserted = (is == mark_inserted);
+      b->inserted = (is == mark_inserted);
       /* Walk down the saved value chain.  */
-      for (v = b->val_chain; v; v = v->next)
+      for (v = b->owner->val_chain; v; v = v->next)
 	{
 	  /* For each memory reference remove the watchpoint
 	     at that address.  */
@@ -1476,7 +1466,7 @@ remove_breakpoint (struct breakpoint *b,
 	    {
 	      struct type *vtype = check_typedef (VALUE_TYPE (v));
 
-	      if (v == b->val_chain
+	      if (v == b->owner->val_chain
 		  || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
 		      && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
 		{
@@ -1486,40 +1476,40 @@ remove_breakpoint (struct breakpoint *b,
 		  addr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
 		  len = TYPE_LENGTH (VALUE_TYPE (v));
 		  type   = hw_write;
-		  if (b->type == bp_read_watchpoint)
+		  if (b->owner->type == bp_read_watchpoint)
 		    type = hw_read;
-		  else if (b->type == bp_access_watchpoint)
+		  else if (b->owner->type == bp_access_watchpoint)
 		    type = hw_access;
 
 		  val = target_remove_watchpoint (addr, len, type);
 		  if (val == -1)
-		    b->impl->inserted = 1;
+		    b->inserted = 1;
 		  val = 0;
 		}
 	    }
 	}
       /* Failure to remove any of the hardware watchpoints comes here.  */
-      if ((is == mark_uninserted) && (b->impl->inserted))
+      if ((is == mark_uninserted) && (b->inserted))
 	warning ("Could not remove hardware watchpoint %d.",
-		 b->number);
+		 b->owner->number);
 
       /* Free the saved value chain.  We will construct a new one
          the next time the watchpoint is inserted.  */
-      for (v = b->val_chain; v; v = n)
+      for (v = b->owner->val_chain; v; v = n)
 	{
 	  n = v->next;
 	  value_free (v);
 	}
-      b->val_chain = NULL;
+      b->owner->val_chain = NULL;
     }
-  else if ((b->type == bp_catch_fork ||
-	    b->type == bp_catch_vfork ||
-	    b->type == bp_catch_exec)
-	   && b->enable_state == bp_enabled
-	   && !b->impl->duplicate)
+  else if ((b->owner->type == bp_catch_fork ||
+	    b->owner->type == bp_catch_vfork ||
+	    b->owner->type == bp_catch_exec)
+	   && b->owner->enable_state == bp_enabled
+	   && !b->duplicate)
     {
       val = -1;
-      switch (b->type)
+      switch (b->owner->type)
 	{
 	case bp_catch_fork:
 	  val = target_remove_fork_catchpoint (PIDGET (inferior_ptid));
@@ -1536,30 +1526,30 @@ remove_breakpoint (struct breakpoint *b,
 	}
       if (val)
 	return val;
-      b->impl->inserted = (is == mark_inserted);
+      b->inserted = (is == mark_inserted);
     }
-  else if ((b->type == bp_catch_catch ||
-	    b->type == bp_catch_throw)
-	   && b->enable_state == bp_enabled
-	   && !b->impl->duplicate)
+  else if ((b->owner->type == bp_catch_catch ||
+	    b->owner->type == bp_catch_throw)
+	   && b->owner->enable_state == bp_enabled
+	   && !b->duplicate)
     {
 
-      val = target_remove_breakpoint (b->impl->address, b->impl->shadow_contents);
+      val = target_remove_breakpoint (b->address, b->shadow_contents);
       if (val)
 	return val;
-      b->impl->inserted = (is == mark_inserted);
+      b->inserted = (is == mark_inserted);
     }
-  else if (ep_is_exception_catchpoint (b)
-	   && b->impl->inserted	/* sometimes previous insert doesn't happen */
-	   && b->enable_state == bp_enabled
-	   && !b->impl->duplicate)
+  else if (ep_is_exception_catchpoint (b->owner)
+	   && b->inserted	/* sometimes previous insert doesn't happen */
+	   && b->owner->enable_state == bp_enabled
+	   && !b->duplicate)
     {
 
-      val = target_remove_breakpoint (b->impl->address, b->impl->shadow_contents);
+      val = target_remove_breakpoint (b->address, b->shadow_contents);
       if (val)
 	return val;
 
-      b->impl->inserted = (is == mark_inserted);
+      b->inserted = (is == mark_inserted);
     }
 
   return 0;
@@ -6647,7 +6637,7 @@ delete_breakpoint (struct breakpoint *bp
   breakpoint_delete_event (bpt->number);
 
   if (bpt->impl->inserted)
-    remove_breakpoint (bpt, mark_inserted);
+    remove_breakpoint (bpt->impl, mark_inserted);
 
   if (breakpoint_chain == bpt)
     breakpoint_chain = bpt->next;

%diffstat
 breakpoint.c |  162 +++++++++++++++++++++++++++--------------------------------
 1 files changed, 76 insertions(+), 86 deletions(-)


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