2004-07-17 Andrew Cagney <cagney@gnu.org>
[deliverable/binutils-gdb.git] / gdb / breakpoint.c
index a4cfa461b3cfbb69e401454c4cd77c962c320d91..018f464653177adc762117c1d3e9c63e0b0df2b6 100644 (file)
@@ -99,7 +99,8 @@ static void check_duplicates (struct breakpoint *);
 
 static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int);
 
-static CORE_ADDR adjust_breakpoint_address (CORE_ADDR bpaddr);
+static CORE_ADDR adjust_breakpoint_address (CORE_ADDR bpaddr,
+                                            enum bptype bptype);
 
 static void describe_other_breakpoints (CORE_ADDR, asection *);
 
@@ -212,6 +213,12 @@ static void ep_skip_leading_whitespace (char **s);
    if such is available. */
 static int can_use_hw_watchpoints;
 
+/* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
+   If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
+   for unrecognized breakpoint locations.  
+   If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized.  */
+static enum auto_boolean pending_break_support;
+
 void _initialize_breakpoint (void);
 
 extern int addressprint;       /* Print machine addresses? */
@@ -259,13 +266,13 @@ int breakpoint_count;
 /* Pointer to current exception event record */
 static struct exception_event_record *current_exception_event;
 
-/* Indicator of whether exception catchpoints should be nuked
-   between runs of a program */
-int exception_catchpoints_are_fragile = 0;
+/* Indicator of whether exception catchpoints should be nuked between
+   runs of a program.  */
+int deprecated_exception_catchpoints_are_fragile = 0;
 
 /* Indicator of when exception catchpoints set-up should be
-   reinitialized -- e.g. when program is re-run */
-int exception_support_initialized = 0;
+   reinitialized -- e.g. when program is re-run */
+int deprecated_exception_support_initialized = 0;
 
 /* This function returns a pointer to the string representation of the
    pathname of the dynamically-linked library that has just been
@@ -739,6 +746,23 @@ insert_catchpoint (struct ui_out *uo, void *args)
   return 0;
 }
 
+/* Helper routine: free the value chain for a breakpoint (watchpoint).  */
+
+static void free_valchain (struct bp_location *b)
+{
+  struct value *v;
+  struct value *n;
+
+  /* Free the saved value chain.  We will construct a new one
+     the next time the watchpoint is inserted.  */
+  for (v = b->owner->val_chain; v; v = n)
+    {
+      n = v->next;
+      value_free (v);
+    }
+  b->owner->val_chain = NULL;
+}
+
 /* Insert a low-level "breakpoint" of some type.  BPT is the breakpoint.
    Any error messages are printed to TMP_ERROR_STREAM; and DISABLED_BREAKS,
    PROCESS_WARNING, and HW_BREAKPOINT_ERROR are used to report problems.
@@ -886,18 +910,17 @@ insert_bp_location (struct bp_location *bpt,
         must watch.  As soon as a many-to-one mapping is available I'll
         convert this.  */
 
-      struct frame_info *saved_frame;
-      int saved_level, within_current_scope;
+      int within_current_scope;
       struct value *mark = value_mark ();
       struct value *v;
+      struct frame_id saved_frame_id;
 
-      /* Save the current frame and level so we can restore it after
+      /* Save the current frame's ID so we can restore it after
         evaluating the watchpoint expression on its own frame.  */
       /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
         took a frame parameter, so that we didn't have to change the
         selected frame.  */
-      saved_frame = deprecated_selected_frame;
-      saved_level = frame_relative_level (deprecated_selected_frame);
+      saved_frame_id = get_frame_id (deprecated_selected_frame);
 
       /* Determine if the watchpoint is within scope.  */
       if (bpt->owner->exp_valid_block == NULL)
@@ -913,6 +936,8 @@ insert_bp_location (struct bp_location *bpt,
 
       if (within_current_scope)
        {
+         free_valchain (bpt);
+
          /* Evaluate the expression and cut the chain of values
             produced off from the value chain.
 
@@ -992,10 +1017,8 @@ insert_bp_location (struct bp_location *bpt,
          bpt->owner->disposition = disp_del_at_next_stop;
        }
 
-      /* Restore the frame and level.  */
-      if (saved_frame != deprecated_selected_frame
-         || saved_level != frame_relative_level (deprecated_selected_frame))
-       select_frame (saved_frame);
+      /* Restore the selected frame.  */
+      select_frame (frame_find_by_id (saved_frame_id));
 
       return val;
     }
@@ -1498,15 +1521,6 @@ remove_breakpoint (struct bp_location *b, insertion_state_t is)
       if ((is == mark_uninserted) && (b->inserted))
        warning ("Could not remove hardware watchpoint %d.",
                 b->owner->number);
-
-      /* Free the saved value chain.  We will construct a new one
-         the next time the watchpoint is inserted.  */
-      for (v = b->owner->val_chain; v; v = n)
-       {
-         n = v->next;
-         value_free (v);
-       }
-      b->owner->val_chain = NULL;
     }
   else if ((b->owner->type == bp_catch_fork ||
            b->owner->type == bp_catch_vfork ||
@@ -1629,8 +1643,8 @@ breakpoint_init_inferior (enum inf_context context)
       default:
        /* Likewise for exception catchpoints in dynamic-linked
           executables where required */
-       if (ep_is_exception_catchpoint (b) &&
-           exception_catchpoints_are_fragile)
+       if (ep_is_exception_catchpoint (b)
+           && deprecated_exception_catchpoints_are_fragile)
          {
            warning_needed = 1;
            delete_breakpoint (b);
@@ -1639,8 +1653,8 @@ breakpoint_init_inferior (enum inf_context context)
       }
   }
 
-  if (exception_catchpoints_are_fragile)
-    exception_support_initialized = 0;
+  if (deprecated_exception_catchpoints_are_fragile)
+    deprecated_exception_support_initialized = 0;
 
   /* Don't issue the warning unless it's really needed... */
   if (warning_needed && (context != inf_exited))
@@ -1753,37 +1767,6 @@ software_breakpoint_inserted_here_p (CORE_ADDR pc)
   return 0;
 }
 
-/* Return nonzero if FRAME is a dummy frame.  We can't use
-   DEPRECATED_PC_IN_CALL_DUMMY because figuring out the saved SP would
-   take too much time, at least using frame_register() on the 68k.
-   This means that for this function to work right a port must use the
-   bp_call_dummy breakpoint.  */
-
-int
-deprecated_frame_in_dummy (struct frame_info *frame)
-{
-  struct breakpoint *b;
-
-  /* This function is used by two files: get_frame_type(), after first
-     checking that !DEPRECATED_USE_GENERIC_DUMMY_FRAMES; and
-     sparc-tdep.c, which doesn't yet use generic dummy frames anyway.  */
-  gdb_assert (!DEPRECATED_USE_GENERIC_DUMMY_FRAMES);
-
-  ALL_BREAKPOINTS (b)
-  {
-    if (b->type == bp_call_dummy
-       && frame_id_eq (b->frame_id, get_frame_id (frame))
-    /* We need to check the PC as well as the frame on the sparc,
-       for signals.exp in the testsuite.  */
-       && (get_frame_pc (frame)
-           >= (b->loc->address
-               - DEPRECATED_SIZEOF_CALL_DUMMY_WORDS / sizeof (LONGEST) * DEPRECATED_REGISTER_SIZE))
-       && get_frame_pc (frame) <= b->loc->address)
-      return 1;
-  }
-  return 0;
-}
-
 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
    PC is valid for process/thread PTID.  */
 
@@ -2576,7 +2559,9 @@ which its expression is valid.\n");
 }
 
 /* Get a bpstat associated with having just stopped at address
-   BP_ADDR.  */
+   BP_ADDR in thread PTID.  STOPPED_BY_WATCHPOINT is 1 if the
+   target thinks we stopped due to a hardware watchpoint, 0 if we
+   know we did not trigger a hardware watchpoint, and -1 if we do not know.  */
 
 /* Determine whether we stopped at a breakpoint, etc, or whether we
    don't understand this stop.  Result is a chain of bpstat's such that:
@@ -2593,7 +2578,7 @@ which its expression is valid.\n");
    commands, FIXME??? fields.  */
 
 bpstat
-bpstat_stop_status (CORE_ADDR bp_addr, ptid_t ptid)
+bpstat_stop_status (CORE_ADDR bp_addr, ptid_t ptid, int stopped_by_watchpoint)
 {
   struct breakpoint *b, *temp;
   /* True if we've hit a breakpoint (as opposed to a watchpoint).  */
@@ -2628,6 +2613,18 @@ bpstat_stop_status (CORE_ADDR bp_addr, ptid_t ptid)
          continue;
       }
 
+    /* Continuable hardware watchpoints are treated as non-existent if the 
+       reason we stopped wasn't a hardware watchpoint (we didn't stop on 
+       some data address).  Otherwise gdb won't stop on a break instruction 
+       in the code (not from a breakpoint) when a hardware watchpoint has 
+       been defined.  */
+
+    if ((b->type == bp_hardware_watchpoint
+        || b->type == bp_read_watchpoint
+        || b->type == bp_access_watchpoint)
+       && !stopped_by_watchpoint)
+      continue;
+
     if (b->type == bp_hardware_breakpoint)
       {
        if (b->loc->address != bp_addr)
@@ -3010,7 +3007,7 @@ bpstat_what (bpstat bs)
 
   /* step_resume entries: a step resume breakpoint overrides another
      breakpoint of signal handling (see comment in wait_for_inferior
-     at first PC_IN_SIGTRAMP where we set the step_resume breakpoint).  */
+     at where we set the step_resume breakpoint).  */
   /* We handle the through_sigtramp_breakpoint the same way; having both
      one of those and a step_resume_breakpoint is probably very rare (?).  */
 
@@ -3471,13 +3468,7 @@ print_one_breakpoint (struct breakpoint *b,
          {
            annotate_field (4);
            if (b->pending)
-             {
-               ui_out_field_string (uiout, "addr", "<PENDING>");
-               if (TARGET_ADDR_BIT <= 32)
-                 ui_out_spaces (uiout, 2);
-               else
-                 ui_out_spaces (uiout, 8);
-             }
+             ui_out_field_string (uiout, "addr", "<PENDING>");
            else
              ui_out_field_core_addr (uiout, "addr", b->loc->address);
          }
@@ -3947,13 +3938,25 @@ breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr,
    this function is simply the identity function.  */
 
 static CORE_ADDR
-adjust_breakpoint_address (CORE_ADDR bpaddr)
+adjust_breakpoint_address (CORE_ADDR bpaddr, enum bptype bptype)
 {
   if (!gdbarch_adjust_breakpoint_address_p (current_gdbarch))
     {
       /* Very few targets need any kind of breakpoint adjustment.  */
       return bpaddr;
     }
+  else if (bptype == bp_watchpoint
+           || bptype == bp_hardware_watchpoint
+           || bptype == bp_read_watchpoint
+           || bptype == bp_access_watchpoint
+           || bptype == bp_catch_fork
+           || bptype == bp_catch_vfork
+           || bptype == bp_catch_exec)
+    {
+      /* Watchpoints and the various bp_catch_* eventpoints should not
+         have their addresses modified.  */
+      return bpaddr;
+    }
   else
     {
       CORE_ADDR adjusted_bpaddr;
@@ -4062,7 +4065,8 @@ set_raw_breakpoint (struct symtab_and_line sal, enum bptype bptype)
   memset (b, 0, sizeof (*b));
   b->loc = allocate_bp_location (b, bptype);
   b->loc->requested_address = sal.pc;
-  b->loc->address = adjust_breakpoint_address (b->loc->requested_address);
+  b->loc->address = adjust_breakpoint_address (b->loc->requested_address,
+                                               bptype);
   if (sal.symtab == NULL)
     b->source_file = NULL;
   else
@@ -4254,7 +4258,7 @@ create_thread_event_breakpoint (CORE_ADDR address)
   
   b->enable_state = bp_enabled;
   /* addr_string has to be used or breakpoint_re_set will delete me.  */
-  xasprintf (&b->addr_string, "*0x%s", paddr (b->loc->address));
+  b->addr_string = xstrprintf ("*0x%s", paddr (b->loc->address));
 
   return b;
 }
@@ -4622,7 +4626,8 @@ set_longjmp_resume_breakpoint (CORE_ADDR pc, struct frame_id frame_id)
     if (b->type == bp_longjmp_resume)
     {
       b->loc->requested_address = pc;
-      b->loc->address = adjust_breakpoint_address (b->loc->requested_address);
+      b->loc->address = adjust_breakpoint_address (b->loc->requested_address,
+                                                   b->type);
       b->enable_state = bp_enabled;
       b->frame_id = frame_id;
       check_duplicates (b);
@@ -4707,13 +4712,13 @@ mention (struct breakpoint *b)
   stb = ui_out_stream_new (uiout);
   old_chain = make_cleanup_ui_out_stream_delete (stb);
 
-  /* FIXME: This is misplaced; mention() is called by things (like hitting a
-     watchpoint) other than breakpoint creation.  It should be possible to
-     clean this up and at the same time replace the random calls to
-     breakpoint_changed with this hook, as has already been done for
-     delete_breakpoint_hook and so on.  */
-  if (create_breakpoint_hook)
-    create_breakpoint_hook (b);
+  /* FIXME: This is misplaced; mention() is called by things (like
+     hitting a watchpoint) other than breakpoint creation.  It should
+     be possible to clean this up and at the same time replace the
+     random calls to breakpoint_changed with this hook, as has already
+     been done for deprecated_delete_breakpoint_hook and so on.  */
+  if (deprecated_create_breakpoint_hook)
+    deprecated_create_breakpoint_hook (b);
   breakpoint_create_event (b->number);
 
   if (b->ops != NULL && b->ops->print_mention != NULL)
@@ -4897,7 +4902,7 @@ create_breakpoints (struct symtabs_and_lines sals, char **addr_string,
        else
          /* addr_string has to be used or breakpoint_re_set will delete
             me.  */
-         xasprintf (&b->addr_string, "*0x%s", paddr (b->loc->address));
+         b->addr_string = xstrprintf ("*0x%s", paddr (b->loc->address));
        b->cond_string = cond_string[i];
        b->ignore_count = ignore_count;
        b->enable_state = bp_enabled;
@@ -4921,6 +4926,10 @@ create_breakpoints (struct symtabs_and_lines sals, char **addr_string,
               be copied too.  */
            if (pending_bp->commands)
              b->commands = copy_command_lines (pending_bp->commands);
+           
+           /* We have to copy over the ignore_count and thread as well.  */
+           b->ignore_count = pending_bp->ignore_count;
+           b->thread = pending_bp->thread;
          }
        mention (b);
       }
@@ -5024,7 +5033,8 @@ breakpoint_sals_to_pc (struct symtabs_and_lines *sals,
 
          Give the target a chance to bless sals.sals[i].pc before we
          try to make a breakpoint for it. */
-      if (PC_REQUIRES_RUN_BEFORE_USE (sals->sals[i].pc))
+#ifdef DEPRECATED_PC_REQUIRES_RUN_BEFORE_USE
+      if (DEPRECATED_PC_REQUIRES_RUN_BEFORE_USE (sals->sals[i].pc))
        {
          if (address == NULL)
            error ("Cannot break without a running program.");
@@ -5032,6 +5042,7 @@ breakpoint_sals_to_pc (struct symtabs_and_lines *sals,
            error ("Cannot break on %s without a running program.", 
                   address);
        }
+#endif
     }
 }
 
@@ -5103,8 +5114,22 @@ break_command_1 (char *arg, int flag, int from_tty, struct breakpoint *pending_b
 
          error_output_message (NULL, err_msg);
          xfree (err_msg);
-         if (!query ("Make breakpoint pending on future shared library load? "))
+
+         /* If pending breakpoint support is turned off, throw error.  */
+
+         if (pending_break_support == AUTO_BOOLEAN_FALSE)
+           throw_exception (RETURN_ERROR);
+
+          /* If pending breakpoint support is auto query and the user selects 
+            no, then simply return the error code.  */
+         if (pending_break_support == AUTO_BOOLEAN_AUTO && 
+             !nquery ("Make breakpoint pending on future shared library load? "))
            return rc;
+
+         /* At this point, either the user was queried about setting a 
+            pending breakpoint and selected yes, or pending breakpoint 
+            behavior is on and thus a pending breakpoint is defaulted 
+            on behalf of the user.  */
          copy_arg = xstrdup (addr_start);
          addr_string = &copy_arg;
          sals.nelts = 1;
@@ -5865,7 +5890,8 @@ watch_command_1 (char *arg, int accessflag, int from_tty)
          scope_breakpoint->loc->requested_address
            = get_frame_pc (prev_frame);
          scope_breakpoint->loc->address
-           = adjust_breakpoint_address (scope_breakpoint->loc->requested_address);
+           = adjust_breakpoint_address (scope_breakpoint->loc->requested_address,
+                                        scope_breakpoint->type);
 
          /* The scope breakpoint is related to the watchpoint.  We
             will need to act on them together.  */
@@ -5880,11 +5906,6 @@ watch_command_1 (char *arg, int accessflag, int from_tty)
    in hardware.  If the watchpoint can not be handled
    in hardware return zero.  */
 
-#if !defined(TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT)
-#define TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT(BYTE_SIZE) \
-    ((BYTE_SIZE) <= (DEPRECATED_REGISTER_SIZE))
-#endif
-
 #if !defined(TARGET_REGION_OK_FOR_HW_WATCHPOINT)
 #define TARGET_REGION_OK_FOR_HW_WATCHPOINT(ADDR,LEN) \
      (TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT(LEN))
@@ -6848,13 +6869,15 @@ delete_breakpoint (struct breakpoint *bpt)
   if (bpt->type == bp_none)
     return;
 
-  if (delete_breakpoint_hook)
-    delete_breakpoint_hook (bpt);
+  if (deprecated_delete_breakpoint_hook)
+    deprecated_delete_breakpoint_hook (bpt);
   breakpoint_delete_event (bpt->number);
 
   if (bpt->loc->inserted)
     remove_breakpoint (bpt->loc, mark_inserted);
 
+  free_valchain (bpt->loc);
+
   if (breakpoint_chain == bpt)
     breakpoint_chain = bpt->next;
 
@@ -7176,7 +7199,8 @@ breakpoint_re_set_one (void *bint)
              b->line_number = sals.sals[i].line;
              b->loc->requested_address = sals.sals[i].pc;
              b->loc->address
-               = adjust_breakpoint_address (b->loc->requested_address);
+               = adjust_breakpoint_address (b->loc->requested_address,
+                                            b->type);
 
              /* Used to check for duplicates here, but that can
                 cause trouble, as it doesn't check for disabled
@@ -7480,8 +7504,8 @@ disable_breakpoint (struct breakpoint *bpt)
 
   check_duplicates (bpt);
 
-  if (modify_breakpoint_hook)
-    modify_breakpoint_hook (bpt);
+  if (deprecated_modify_breakpoint_hook)
+    deprecated_modify_breakpoint_hook (bpt);
   breakpoint_modify_event (bpt->number);
 }
 
@@ -7521,8 +7545,6 @@ disable_command (char *args, int from_tty)
 static void
 do_enable_breakpoint (struct breakpoint *bpt, enum bpdisp disposition)
 {
-  struct frame_info *save_selected_frame = NULL;
-  int save_selected_frame_level = -1;
   int target_resources_ok, other_type_used;
   struct value *mark;
 
@@ -7569,6 +7591,9 @@ do_enable_breakpoint (struct breakpoint *bpt, enum bpdisp disposition)
          bpt->type == bp_read_watchpoint || 
          bpt->type == bp_access_watchpoint)
        {
+         struct frame_id saved_frame_id;
+
+         saved_frame_id = get_frame_id (get_selected_frame ());
          if (bpt->exp_valid_block != NULL)
            {
              struct frame_info *fr =
@@ -7581,9 +7606,6 @@ is valid is not currently in scope.\n", bpt->number);
                  bpt->enable_state = bp_disabled;
                  return;
                }
-             
-             save_selected_frame = deprecated_selected_frame;
-             save_selected_frame_level = frame_relative_level (deprecated_selected_frame);
              select_frame (fr);
            }
          
@@ -7618,14 +7640,13 @@ have been allocated for other watchpoints.\n", bpt->number);
                }
            }
          
-         if (save_selected_frame_level >= 0)
-           select_frame (save_selected_frame);
+         select_frame (frame_find_by_id (saved_frame_id));
          value_free_to_mark (mark);
        }
     }
 
-  if (modify_breakpoint_hook)
-    modify_breakpoint_hook (bpt);
+  if (deprecated_modify_breakpoint_hook)
+    deprecated_modify_breakpoint_hook (bpt);
   breakpoint_modify_event (bpt->number);
 }
 
@@ -7696,6 +7717,16 @@ enable_delete_command (char *args, int from_tty)
   map_breakpoint_numbers (args, enable_delete_breakpoint);
 }
 \f
+static void
+set_breakpoint_cmd (char *args, int from_tty)
+{
+}
+
+static void
+show_breakpoint_cmd (char *args, int from_tty)
+{
+}
+
 /* Use default_breakpoint_'s, or nothing if they aren't valid.  */
 
 struct symtabs_and_lines
@@ -7720,6 +7751,8 @@ decode_line_spec_1 (char *string, int funfirstline)
 void
 _initialize_breakpoint (void)
 {
+  static struct cmd_list_element *breakpoint_set_cmdlist;
+  static struct cmd_list_element *breakpoint_show_cmdlist;
   struct cmd_list_element *c;
 
   breakpoint_chain = 0;
@@ -8038,4 +8071,34 @@ hardware.)",
   add_show_from_set (c, &showlist);
 
   can_use_hw_watchpoints = 1;
+
+  add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, "\
+Breakpoint specific settings\n\
+Configure various breakpoint-specific variables such as\n\
+pending breakpoint behavior",
+                 &breakpoint_set_cmdlist, "set breakpoint ",
+                 0/*allow-unknown*/, &setlist);
+  add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, "\
+Breakpoint specific settings\n\
+Configure various breakpoint-specific variables such as\n\
+pending breakpoint behavior",
+                 &breakpoint_show_cmdlist, "show breakpoint ",
+                 0/*allow-unknown*/, &showlist);
+
+  add_setshow_auto_boolean_cmd ("pending", no_class, &pending_break_support, "\
+Set debugger's behavior regarding pending breakpoints.\n\
+If on, an unrecognized breakpoint location will cause gdb to create a\n\
+pending breakpoint.  If off, an unrecognized breakpoint location results in\n\
+an error.  If auto, an unrecognized breakpoint location results in a\n\
+user-query to see if a pending breakpoint should be created.","\
+Show debugger's behavior regarding pending breakpoints.\n\
+If on, an unrecognized breakpoint location will cause gdb to create a\n\
+pending breakpoint.  If off, an unrecognized breakpoint location results in\n\
+an error.  If auto, an unrecognized breakpoint location results in a\n\
+user-query to see if a pending breakpoint should be created.",
+                               NULL, NULL,
+                               &breakpoint_set_cmdlist,
+                               &breakpoint_show_cmdlist);
+
+  pending_break_support = AUTO_BOOLEAN_AUTO;
 }
This page took 0.069781 seconds and 4 git commands to generate.