New common function "startswith"
[deliverable/binutils-gdb.git] / gdb / breakpoint.c
index 2804453060acb5f8d3a7da9086140cc00ab76429..d85f271e0486423889d28d1c7f7615d2feaf6672 100644 (file)
@@ -297,10 +297,6 @@ static struct bp_location **get_first_locp_gte_addr (CORE_ADDR address);
 
 static int strace_marker_p (struct breakpoint *b);
 
-/* The abstract base class all breakpoint_ops structures inherit
-   from.  */
-struct breakpoint_ops base_breakpoint_ops;
-
 /* The breakpoint_ops structure to be inherited by all breakpoint_ops
    that are implemented on top of software or hardware breakpoints
    (user breakpoints, internal and momentary breakpoints, etc.).  */
@@ -5456,6 +5452,18 @@ bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid)
     }  
 }
 
+/* Returns true if we need to track moribund locations of LOC's type
+   on the current target.  */
+
+static int
+need_moribund_for_location_type (struct bp_location *loc)
+{
+  return ((loc->loc_type == bp_loc_software_breakpoint
+          && !target_supports_stopped_by_sw_breakpoint ())
+         || (loc->loc_type == bp_loc_hardware_breakpoint
+             && !target_supports_stopped_by_hw_breakpoint ()));
+}
+
 
 /* Get a bpstat associated with having just stopped at address
    BP_ADDR in thread PTID.
@@ -5545,15 +5553,20 @@ bpstat_stop_status (struct address_space *aspace,
     }
 
   /* Check if a moribund breakpoint explains the stop.  */
-  for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
+  if (!target_supports_stopped_by_sw_breakpoint ()
+      || !target_supports_stopped_by_hw_breakpoint ())
     {
-      if (breakpoint_location_address_match (loc, aspace, bp_addr))
+      for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix)
        {
-         bs = bpstat_alloc (loc, &bs_link);
-         /* For hits of moribund locations, we should just proceed.  */
-         bs->stop = 0;
-         bs->print = 0;
-         bs->print_it = print_it_noop;
+         if (breakpoint_location_address_match (loc, aspace, bp_addr)
+             && need_moribund_for_location_type (loc))
+           {
+             bs = bpstat_alloc (loc, &bs_link);
+             /* For hits of moribund locations, we should just proceed.  */
+             bs->stop = 0;
+             bs->print = 0;
+             bs->print_it = print_it_noop;
+           }
        }
     }
 
@@ -9308,11 +9321,10 @@ add_location_to_breakpoint (struct breakpoint *b,
 }
 \f
 
-/* Return 1 if LOC is pointing to a permanent breakpoint, 
-   return 0 otherwise.  */
+/* See breakpoint.h.  */
 
-static int
-bp_loc_is_permanent (struct bp_location *loc)
+int
+program_breakpoint_here_p (struct gdbarch *gdbarch, CORE_ADDR address)
 {
   int len;
   CORE_ADDR addr;
@@ -9321,6 +9333,38 @@ bp_loc_is_permanent (struct bp_location *loc)
   struct cleanup *cleanup;
   int retval = 0;
 
+  addr = address;
+  bpoint = gdbarch_breakpoint_from_pc (gdbarch, &addr, &len);
+
+  /* Software breakpoints unsupported?  */
+  if (bpoint == NULL)
+    return 0;
+
+  target_mem = alloca (len);
+
+  /* Enable the automatic memory restoration from breakpoints while
+     we read the memory.  Otherwise we could say about our temporary
+     breakpoints they are permanent.  */
+  cleanup = make_show_memory_breakpoints_cleanup (0);
+
+  if (target_read_memory (address, target_mem, len) == 0
+      && memcmp (target_mem, bpoint, len) == 0)
+    retval = 1;
+
+  do_cleanups (cleanup);
+
+  return retval;
+}
+
+/* Return 1 if LOC is pointing to a permanent breakpoint,
+   return 0 otherwise.  */
+
+static int
+bp_loc_is_permanent (struct bp_location *loc)
+{
+  struct cleanup *cleanup;
+  int retval;
+
   gdb_assert (loc != NULL);
 
   /* bp_call_dummy breakpoint locations are usually memory locations
@@ -9337,26 +9381,10 @@ bp_loc_is_permanent (struct bp_location *loc)
   if (loc->owner->type == bp_call_dummy)
     return 0;
 
-  addr = loc->address;
-  bpoint = gdbarch_breakpoint_from_pc (loc->gdbarch, &addr, &len);
-
-  /* Software breakpoints unsupported?  */
-  if (bpoint == NULL)
-    return 0;
-
-  target_mem = alloca (len);
-
-  /* Enable the automatic memory restoration from breakpoints while
-     we read the memory.  Otherwise we could say about our temporary
-     breakpoints they are permanent.  */
   cleanup = save_current_space_and_thread ();
-
   switch_to_program_space_and_thread (loc->pspace);
-  make_show_memory_breakpoints_cleanup (0);
 
-  if (target_read_memory (loc->address, target_mem, len) == 0
-      && memcmp (target_mem, bpoint, len) == 0)
-    retval = 1;
+  retval = program_breakpoint_here_p (loc->gdbarch, loc->address);
 
   do_cleanups (cleanup);
 
@@ -9701,7 +9729,7 @@ parse_breakpoint_sals (char **address,
   /* If no arg given, or if first arg is 'if ', use the default
      breakpoint.  */
   if ((*address) == NULL
-      || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2])))
+      || (startswith ((*address), "if") && isspace ((*address)[2])))
     {
       /* The last displayed codepoint, if it's valid, is our default breakpoint
          address.  */
@@ -11373,7 +11401,7 @@ watch_command_1 (const char *arg, int accessflag, int from_tty,
          tok++;
          toklen = end_tok - tok + 1;
 
-         if (toklen == 6 && !strncmp (tok, "thread", 6))
+         if (toklen == 6 && startswith (tok, "thread"))
            {
              /* At this point we've found a "thread" token, which means
                 the user is trying to set a watchpoint that triggers
@@ -11395,7 +11423,7 @@ watch_command_1 (const char *arg, int accessflag, int from_tty,
              if (!valid_thread_id (thread))
                invalid_thread_id_error (thread);
            }
-         else if (toklen == 4 && !strncmp (tok, "mask", 4))
+         else if (toklen == 4 && startswith (tok, "mask"))
            {
              /* We've found a "mask" token, which means the user wants to
                 create a hardware watchpoint that is going to have the mask
@@ -12801,8 +12829,7 @@ update_global_location_list (enum ugll_insert_mode insert_mode)
       if (!found_object)
        {
          if (removed && non_stop
-             && breakpoint_address_is_meaningful (old_loc->owner)
-             && !is_hardware_watchpoint (old_loc->owner))
+             && need_moribund_for_location_type (old_loc))
            {
              /* This location was removed from the target.  In
                 non-stop mode, a race condition is possible where
@@ -15466,7 +15493,7 @@ strace_command (char *arg, int from_tty)
 
   /* Decide if we are dealing with a static tracepoint marker (`-m'),
      or with a normal static tracepoint.  */
-  if (arg && strncmp (arg, "-m", 2) == 0 && isspace (arg[2]))
+  if (arg && startswith (arg, "-m") && isspace (arg[2]))
     ops = &strace_marker_breakpoint_ops;
   else
     ops = &tracepoint_breakpoint_ops;
@@ -15980,7 +16007,8 @@ all_tracepoints (void)
 command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]\n\
 PROBE_MODIFIER shall be present if the command is to be placed in a\n\
 probe point.  Accepted values are `-probe' (for a generic, automatically\n\
-guessed probe type) or `-probe-stap' (for a SystemTap probe).\n\
+guessed probe type), `-probe-stap' (for a SystemTap probe) or \n\
+`-probe-dtrace' (for a DTrace probe).\n\
 LOCATION may be a line number, function name, or \"*\" and an address.\n\
 If a line number is specified, break at start of code for that line.\n\
 If a function is specified, break at start of code for that function.\n\
This page took 0.052772 seconds and 4 git commands to generate.