cli-script.c: Simplify using std::string, eliminate cleanups
[deliverable/binutils-gdb.git] / gdb / breakpoint.c
index 6bb6bbfbef9ba573479b4fda575442026e9d3761..38262c1ce06b09637ed12537784a54811f19057f 100644 (file)
@@ -80,6 +80,7 @@
 
 #include "mi/mi-common.h"
 #include "extension.h"
+#include <algorithm>
 
 /* Enums for exception-handling support.  */
 enum exception_event_kind
@@ -101,8 +102,9 @@ static void disable_command (char *, int);
 
 static void enable_command (char *, int);
 
-static void map_breakpoint_numbers (char *, void (*) (struct breakpoint *,
-                                                     void *),
+static void map_breakpoint_numbers (const char *,
+                                   void (*) (struct breakpoint *,
+                                             void *),
                                    void *);
 
 static void ignore_command (char *, int);
@@ -1337,7 +1339,7 @@ struct commands_info
   int from_tty;
 
   /* The breakpoint range spec.  */
-  char *arg;
+  const char *arg;
 
   /* Non-NULL if the body of the commands are being read from this
      already-parsed command.  */
@@ -1398,7 +1400,7 @@ do_map_commands_command (struct breakpoint *b, void *data)
 }
 
 static void
-commands_command_1 (char *arg, int from_tty, 
+commands_command_1 (const char *arg, int from_tty,
                    struct command_line *control)
 {
   struct cleanup *cleanups;
@@ -1411,32 +1413,22 @@ commands_command_1 (char *arg, int from_tty,
      extra reference to the commands that we must clean up.  */
   cleanups = make_cleanup_decref_counted_command_line (&info.cmd);
 
+  std::string new_arg;
+
   if (arg == NULL || !*arg)
     {
       if (breakpoint_count - prev_breakpoint_count > 1)
-       arg = xstrprintf ("%d-%d", prev_breakpoint_count + 1, 
-                         breakpoint_count);
+       new_arg = string_printf ("%d-%d", prev_breakpoint_count + 1,
+                                breakpoint_count);
       else if (breakpoint_count > 0)
-       arg = xstrprintf ("%d", breakpoint_count);
-      else
-       {
-         /* So that we don't try to free the incoming non-NULL
-            argument in the cleanup below.  Mapping breakpoint
-            numbers will fail in this case.  */
-         arg = NULL;
-       }
+       new_arg = string_printf ("%d", breakpoint_count);
     }
   else
-    /* The command loop has some static state, so we need to preserve
-       our argument.  */
-    arg = xstrdup (arg);
-
-  if (arg != NULL)
-    make_cleanup (xfree, arg);
+    new_arg = arg;
 
-  info.arg = arg;
+  info.arg = new_arg.c_str ();
 
-  map_breakpoint_numbers (arg, do_map_commands_command, &info);
+  map_breakpoint_numbers (info.arg, do_map_commands_command, &info);
 
   if (info.cmd == NULL)
     error (_("No breakpoints specified."));
@@ -1456,7 +1448,7 @@ commands_command (char *arg, int from_tty)
    This is used by cli-script.c to DTRT with breakpoint commands
    that are part of if and while bodies.  */
 enum command_control_type
-commands_from_control_command (char *arg, struct command_line *cmd)
+commands_from_control_command (const char *arg, struct command_line *cmd)
 {
   commands_command_1 (arg, 0, cmd);
   return simple_control;
@@ -2602,6 +2594,28 @@ build_target_command_list (struct bp_location *bl)
     bl->target_info.persist = 1;
 }
 
+/* Return the kind of breakpoint on address *ADDR.  Get the kind
+   of breakpoint according to ADDR except single-step breakpoint.
+   Get the kind of single-step breakpoint according to the current
+   registers state.  */
+
+static int
+breakpoint_kind (struct bp_location *bl, CORE_ADDR *addr)
+{
+  if (bl->owner->type == bp_single_step)
+    {
+      struct thread_info *thr = find_thread_global_id (bl->owner->thread);
+      struct regcache *regcache;
+
+      regcache = get_thread_regcache (thr->ptid);
+
+      return gdbarch_breakpoint_kind_from_current_state (bl->gdbarch,
+                                                        regcache, addr);
+    }
+  else
+    return gdbarch_breakpoint_kind_from_pc (bl->gdbarch, addr);
+}
+
 /* Insert a low-level "breakpoint" of some type.  BL is the breakpoint
    location.  Any error messages are printed to TMP_ERROR_STREAM; and
    DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems.
@@ -2761,6 +2775,9 @@ insert_bp_location (struct bp_location *bl,
                    {
                      int val;
 
+                     bl->overlay_target_info.kind
+                       = breakpoint_kind (bl, &addr);
+                     bl->overlay_target_info.placed_address = addr;
                      val = target_insert_breakpoint (bl->gdbarch,
                                                      &bl->overlay_target_info);
                      if (val)
@@ -4435,8 +4452,8 @@ hardware_watchpoint_inserted_in_range (struct address_space *aspace,
            CORE_ADDR l, h;
 
            /* Check for intersection.  */
-           l = max (loc->address, addr);
-           h = min (loc->address + loc->length, addr + len);
+           l = std::max<CORE_ADDR> (loc->address, addr);
+           h = std::min<CORE_ADDR> (loc->address + loc->length, addr + len);
            if (l < h)
              return 1;
          }
@@ -5237,8 +5254,6 @@ watchpoint_check (void *p)
     }
   else
     {
-      struct switch_thru_all_uis state;
-
       /* This seems like the only logical thing to do because
          if we temporarily ignored the watchpoint, then when
          we reenter the block in which it is valid it contains
@@ -5253,7 +5268,7 @@ watchpoint_check (void *p)
         already.  So we have no choice but print the information
         here.  */
 
-      SWITCH_THRU_ALL_UIS (state)
+      SWITCH_THRU_ALL_UIS ()
         {
          struct ui_out *uiout = current_uiout;
 
@@ -5434,9 +5449,7 @@ bpstat_check_watchpoint (bpstat bs)
            case 0:
              /* Error from catch_errors.  */
              {
-               struct switch_thru_all_uis state;
-
-               SWITCH_THRU_ALL_UIS (state)
+               SWITCH_THRU_ALL_UIS ()
                  {
                    printf_filtered (_("Watchpoint %d deleted.\n"),
                                     b->base.number);
@@ -5996,7 +6009,7 @@ bpstat_what (bpstat bs_head)
                          _("bpstat_what: unhandled bptype %d"), (int) bptype);
        }
 
-      retval.main_action = max (retval.main_action, this_action);
+      retval.main_action = std::max (retval.main_action, this_action);
     }
 
   return retval;
@@ -9631,7 +9644,7 @@ check_fast_tracepoint_sals (struct gdbarch *gdbarch,
       old_chain = make_cleanup (xfree, msg);
 
       if (!rslt)
-       error (_("May not have a fast tracepoint at 0x%s%s"),
+       error (_("May not have a fast tracepoint at %s%s"),
               paddress (sarch, sal->pc), (msg ? msg : ""));
 
       do_cleanups (old_chain);
@@ -13116,6 +13129,11 @@ bkpt_re_set (struct breakpoint *b)
 static int
 bkpt_insert_location (struct bp_location *bl)
 {
+  CORE_ADDR addr = bl->target_info.reqstd_address;
+
+  bl->target_info.kind = breakpoint_kind (bl, &addr);
+  bl->target_info.placed_address = addr;
+
   if (bl->loc_type == bp_loc_hardware_breakpoint)
     return target_insert_hw_breakpoint (bl->gdbarch, &bl->target_info);
   else
@@ -14768,27 +14786,25 @@ ignore_command (char *args, int from_tty)
    whose numbers are given in ARGS.  */
 
 static void
-map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *,
-                                                     void *),
+map_breakpoint_numbers (const char *args,
+                       void (*function) (struct breakpoint *,
+                                         void *),
                        void *data)
 {
   int num;
   struct breakpoint *b, *tmp;
-  int match;
-  struct get_number_or_range_state state;
 
   if (args == 0 || *args == '\0')
     error_no_arg (_("one or more breakpoint numbers"));
 
-  init_number_or_range (&state, args);
+  number_or_range_parser parser (args);
 
-  while (!state.finished)
+  while (!parser.finished ())
     {
-      const char *p = state.string;
-
-      match = 0;
+      const char *p = parser.cur_tok ();
+      bool match = false;
 
-      num = get_number_or_range (&state);
+      num = parser.get_number ();
       if (num == 0)
        {
          warning (_("bad breakpoint number at or near '%s'"), p);
@@ -14798,11 +14814,11 @@ map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *,
          ALL_BREAKPOINTS_SAFE (b, tmp)
            if (b->number == num)
              {
-               match = 1;
+               match = true;
                function (b, data);
                break;
              }
-         if (match == 0)
+         if (!match)
            printf_unfiltered (_("No breakpoint number %d.\n"), num);
        }
     }
@@ -15208,6 +15224,33 @@ insert_single_step_breakpoint (struct gdbarch *gdbarch,
   update_global_location_list (UGLL_INSERT);
 }
 
+/* Insert single step breakpoints according to the current state.  */
+
+int
+insert_single_step_breakpoints (struct gdbarch *gdbarch)
+{
+  struct frame_info *frame = get_current_frame ();
+  VEC (CORE_ADDR) * next_pcs;
+
+  next_pcs = gdbarch_software_single_step (gdbarch, frame);
+
+  if (next_pcs != NULL)
+    {
+      int i;
+      CORE_ADDR pc;
+      struct address_space *aspace = get_frame_address_space (frame);
+
+      for (i = 0; VEC_iterate (CORE_ADDR, next_pcs, i, pc); i++)
+       insert_single_step_breakpoint (gdbarch, aspace, pc);
+
+      VEC_free (CORE_ADDR, next_pcs);
+
+      return 1;
+    }
+  else
+    return 0;
+}
+
 /* See breakpoint.h.  */
 
 int
@@ -15583,12 +15626,10 @@ trace_pass_command (char *args, int from_tty)
     }
   else
     {
-      struct get_number_or_range_state state;
-
-      init_number_or_range (&state, args);
-      while (!state.finished)
+      number_or_range_parser parser (args);
+      while (!parser.finished ())
        {
-         t1 = get_tracepoint_by_number (&args, &state);
+         t1 = get_tracepoint_by_number (&args, &parser);
          if (t1)
            trace_pass_set_count (t1, count, from_tty);
        }
@@ -15634,16 +15675,16 @@ get_tracepoint_by_number_on_target (int num)
 
 struct tracepoint *
 get_tracepoint_by_number (char **arg,
-                         struct get_number_or_range_state *state)
+                         number_or_range_parser *parser)
 {
   struct breakpoint *t;
   int tpnum;
   char *instring = arg == NULL ? NULL : *arg;
 
-  if (state)
+  if (parser != NULL)
     {
-      gdb_assert (!state->finished);
-      tpnum = get_number_or_range (state);
+      gdb_assert (!parser->finished ());
+      tpnum = parser->get_number ();
     }
   else if (arg == NULL || *arg == NULL || ! **arg)
     tpnum = tracepoint_count;
This page took 0.029733 seconds and 4 git commands to generate.