* config/obj-aout.h: Fix comment typos.
[deliverable/binutils-gdb.git] / gdb / breakpoint.c
index 35d9fa943967e6d36f17fb3d6ef2e6ff05d924c3..02874bcf290d66ea755791d1a2ef81685937bf91 100644 (file)
@@ -128,7 +128,7 @@ typedef enum
   }
 insertion_state_t;
 
-static int remove_breakpoint (struct breakpoint *, insertion_state_t);
+static int remove_breakpoint (struct bp_location *, insertion_state_t);
 
 static enum print_stop_action print_it_typical (bpstat);
 
@@ -747,11 +747,11 @@ insert_catchpoint (struct ui_out *uo, void *args)
 
    NOTE drow/2003-09-09: This routine could be broken down to an object-style
    method for each breakpoint or catchpoint type.  */
-int
+static int
 insert_bp_location (struct bp_location *bpt,
-                       struct ui_file *tmp_error_stream,
-                       int *disabled_breaks, int *process_warning,
-                       int *hw_breakpoint_error)
+                   struct ui_file *tmp_error_stream,
+                   int *disabled_breaks, int *process_warning,
+                   int *hw_breakpoint_error)
 {
   int val = 0;
 
@@ -976,7 +976,7 @@ insert_bp_location (struct bp_location *bpt,
             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", 
@@ -1071,7 +1071,11 @@ insert_bp_location (struct bp_location *bpt,
        bpt->owner->enable_state = bp_disabled;
       else
        bpt->inserted = 1;
-      return val;
+
+      /* We've already printed an error message if there was a problem
+        inserting this catchpoint, and we've disabled the catchpoint,
+        so just return success.  */
+      return 0;
     }
 
   return 0;
@@ -1150,12 +1154,12 @@ You may have requested too many hardware breakpoints/watchpoints.\n");
 int
 remove_breakpoints (void)
 {
-  struct breakpoint *b;
+  struct bp_location *b;
   int val;
 
-  ALL_BREAKPOINTS (b)
+  ALL_BP_LOCATIONS (b)
   {
-    if (b->loc->inserted)
+    if (b->inserted)
       {
        val = remove_breakpoint (b, mark_uninserted);
        if (val != 0)
@@ -1168,15 +1172,12 @@ remove_breakpoints (void)
 int
 remove_hw_watchpoints (void)
 {
-  struct breakpoint *b;
+  struct bp_location *b;
   int val;
 
-  ALL_BREAKPOINTS (b)
+  ALL_BP_LOCATIONS (b)
   {
-    if (b->loc->inserted
-       && (b->type == bp_hardware_watchpoint
-           || b->type == bp_read_watchpoint
-           || b->type == bp_access_watchpoint))
+    if (b->inserted && b->loc_type == bp_loc_hardware_watchpoint)
       {
        val = remove_breakpoint (b, mark_uninserted);
        if (val != 0)
@@ -1189,21 +1190,23 @@ remove_hw_watchpoints (void)
 int
 reattach_breakpoints (int pid)
 {
-  struct breakpoint *b;
+  struct bp_location *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_BP_LOCATIONS (b)
   {
-    if (b->loc->inserted)
+    if (b->inserted)
       {
        remove_breakpoint (b, mark_inserted);
-       if (b->type == bp_hardware_breakpoint)
-         val = target_insert_hw_breakpoint (b->loc->address, b->loc->shadow_contents);
+       if (b->loc_type == bp_loc_hardware_breakpoint)
+         val = target_insert_hw_breakpoint (b->address, b->shadow_contents);
        else
-         val = target_insert_breakpoint (b->loc->address, b->loc->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);
@@ -1352,7 +1355,7 @@ update_breakpoints_after_exec (void)
 int
 detach_breakpoints (int pid)
 {
-  struct breakpoint *b;
+  struct bp_location *b;
   int val;
   struct cleanup *old_chain = save_inferior_ptid ();
 
@@ -1361,9 +1364,9 @@ detach_breakpoints (int pid)
 
   /* Set inferior_ptid; remove_breakpoint uses this global.  */
   inferior_ptid = pid_to_ptid (pid);
-  ALL_BREAKPOINTS (b)
+  ALL_BP_LOCATIONS (b)
   {
-    if (b->loc->inserted)
+    if (b->inserted)
       {
        val = remove_breakpoint (b, mark_inserted);
        if (val != 0)
@@ -1378,27 +1381,20 @@ detach_breakpoints (int pid)
 }
 
 static int
-remove_breakpoint (struct breakpoint *b, insertion_state_t is)
+remove_breakpoint (struct bp_location *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);
-
-  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)
+            b->owner->number);
+
+  if (b->loc_type == bp_loc_software_breakpoint
+      || b->loc_type == bp_loc_hardware_breakpoint)
     {
       /* "Normal" instruction breakpoint: either the standard
         trap-instruction bp (bp_breakpoint), or a
@@ -1406,16 +1402,16 @@ remove_breakpoint (struct breakpoint *b, insertion_state_t is)
 
       /* First check to see if we have to handle an overlay.  */
       if (overlay_debugging == ovly_off
-         || b->loc->section == NULL
-         || !(section_is_overlay (b->loc->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->loc->address, 
-                                              b->loc->shadow_contents);
+         if (b->loc_type == bp_loc_hardware_breakpoint)
+           val = target_remove_hw_breakpoint (b->address, 
+                                              b->shadow_contents);
          else
-           val = target_remove_breakpoint (b->loc->address, b->loc->shadow_contents);
+           val = target_remove_breakpoint (b->address, b->shadow_contents);
        }
       else
        {
@@ -1426,29 +1422,29 @@ remove_breakpoint (struct breakpoint *b, insertion_state_t is)
                /* 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->loc->address, 
-                                                          b->loc->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->loc->shadow_contents);
+               if (b->loc_type == bp_loc_hardware_breakpoint)
+                 target_remove_hw_breakpoint (addr, b->shadow_contents);
                else
-                 target_remove_breakpoint (addr, b->loc->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->loc->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->loc->address, 
-                                                  b->loc->shadow_contents);
+             if (b->loc_type == bp_loc_hardware_breakpoint)
+               val = target_remove_hw_breakpoint (b->address, 
+                                                  b->shadow_contents);
              else
-               val = target_remove_breakpoint (b->loc->address,
-                                               b->loc->shadow_contents);
+               val = target_remove_breakpoint (b->address,
+                                               b->shadow_contents);
            }
          else
            {
@@ -1458,20 +1454,18 @@ remove_breakpoint (struct breakpoint *b, insertion_state_t is)
        }
       if (val)
        return val;
-      b->loc->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->loc->duplicate)
+  else if (b->loc_type == bp_loc_hardware_watchpoint
+          && b->owner->enable_state == bp_enabled
+          && !b->duplicate)
     {
       struct value *v;
       struct value *n;
 
-      b->loc->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.  */
@@ -1480,7 +1474,7 @@ remove_breakpoint (struct breakpoint *b, insertion_state_t is)
            {
              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))
                {
@@ -1490,40 +1484,40 @@ remove_breakpoint (struct breakpoint *b, insertion_state_t is)
                  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->loc->inserted = 1;
+                   b->inserted = 1;
                  val = 0;
                }
            }
        }
       /* Failure to remove any of the hardware watchpoints comes here.  */
-      if ((is == mark_uninserted) && (b->loc->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->loc->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));
@@ -1540,30 +1534,30 @@ remove_breakpoint (struct breakpoint *b, insertion_state_t is)
        }
       if (val)
        return val;
-      b->loc->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->loc->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->loc->address, b->loc->shadow_contents);
+      val = target_remove_breakpoint (b->address, b->shadow_contents);
       if (val)
        return val;
-      b->loc->inserted = (is == mark_inserted);
+      b->inserted = (is == mark_inserted);
     }
-  else if (ep_is_exception_catchpoint (b)
-          && b->loc->inserted  /* sometimes previous insert doesn't happen */
-          && b->enable_state == bp_enabled
-          && !b->loc->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->loc->address, b->loc->shadow_contents);
+      val = target_remove_breakpoint (b->address, b->shadow_contents);
       if (val)
        return val;
 
-      b->loc->inserted = (is == mark_inserted);
+      b->inserted = (is == mark_inserted);
     }
 
   return 0;
@@ -2847,8 +2841,8 @@ bpstat_stop_status (CORE_ADDR *pc, int not_a_sw_breakpoint)
              bs->print = 0;
            bs->commands = b->commands;
            if (bs->commands &&
-               (STREQ ("silent", bs->commands->line) ||
-                (xdb_commands && STREQ ("Q", bs->commands->line))))
+               (strcmp ("silent", bs->commands->line) == 0
+                || (xdb_commands && strcmp ("Q", bs->commands->line) == 0)))
              {
                bs->commands = bs->commands->next;
                bs->print = 0;
@@ -3946,7 +3940,7 @@ adjust_breakpoint_address (CORE_ADDR bpaddr)
 
 /* Allocate a struct bp_location.  */
 
-struct bp_location *
+static struct bp_location *
 allocate_bp_location (struct breakpoint *bpt, enum bptype bp_type)
 {
   struct bp_location *loc, *loc_p;
@@ -4303,11 +4297,12 @@ re_enable_breakpoints_in_shlibs (void)
   ALL_BREAKPOINTS (b)
     if (b->enable_state == bp_shlib_disabled)
     {
-      char buf[1];
+      char buf[1], *lib;
 
       /* Do not reenable the breakpoint if the shared library
          is still not mapped in.  */
-      if (target_read_memory (b->loc->address, buf, 1) == 0)
+      lib = PC_SOLIB (b->loc->address);
+      if (lib != NULL && target_read_memory (b->loc->address, buf, 1) == 0)
        b->enable_state = bp_enabled;
     }
 }
@@ -6601,7 +6596,7 @@ clear_command (char *arg, int from_tty)
                  || ((default_match || (0 == sal.pc))
                      && b->source_file != NULL
                      && sal.symtab != NULL
-                     && STREQ (b->source_file, sal.symtab->filename)
+                     && strcmp (b->source_file, sal.symtab->filename) == 0
                      && b->line_number == sal.line)))
            /* Yes, if sal source file and line matches b.  */
            {
@@ -6708,7 +6703,7 @@ delete_breakpoint (struct breakpoint *bpt)
   breakpoint_delete_event (bpt->number);
 
   if (bpt->loc->inserted)
-    remove_breakpoint (bpt, mark_inserted);
+    remove_breakpoint (bpt->loc, mark_inserted);
 
   if (breakpoint_chain == bpt)
     breakpoint_chain = bpt->next;
@@ -7002,7 +6997,7 @@ breakpoint_re_set_one (void *bint)
             the source file name or the line number changes...  */
              || (b->source_file != NULL
                  && sals.sals[i].symtab != NULL
-                 && (!STREQ (b->source_file, sals.sals[i].symtab->filename)
+                 && (strcmp (b->source_file, sals.sals[i].symtab->filename) != 0
                      || b->line_number != sals.sals[i].line)
              )
          /* ...or we switch between having a source file and not having
This page took 0.030611 seconds and 4 git commands to generate.