Per-inferior thread list, thread ranges/iterators, down with ALL_THREADS, etc.
[deliverable/binutils-gdb.git] / gdb / remote.c
index 297c198ed69012892f0eec53f7efa24648a0886b..90b5dabc8a4059b9813b3cea8fe4fe55ae10cb36 100644 (file)
@@ -1030,7 +1030,7 @@ static ptid_t read_ptid (const char *buf, const char **obuf);
 
 static void remote_async_inferior_event_handler (gdb_client_data);
 
-static int remote_read_description_p (struct target_ops *target);
+static bool remote_read_description_p (struct target_ops *target);
 
 static void remote_console_output (char *msg);
 
@@ -3785,8 +3785,6 @@ remote_target::update_thread_list ()
       || remote_get_threads_with_qthreadinfo (&context)
       || remote_get_threads_with_ql (&context))
     {
-      struct thread_info *tp, *tmp;
-
       got_list = 1;
 
       if (context.items.empty ()
@@ -3803,7 +3801,7 @@ remote_target::update_thread_list ()
       /* CONTEXT now holds the current thread list on the remote
         target end.  Delete GDB-side threads no longer found on the
         target.  */
-      ALL_THREADS_SAFE (tp, tmp)
+      for (thread_info *tp : all_threads_safe ())
        {
          if (!context.contains_thread (tp->ptid))
            {
@@ -4385,8 +4383,6 @@ void
 remote_target::process_initial_stop_replies (int from_tty)
 {
   int pending_stop_replies = stop_reply_queue_length ();
-  struct inferior *inf;
-  struct thread_info *thread;
   struct thread_info *selected = NULL;
   struct thread_info *lowest_stopped = NULL;
   struct thread_info *first = NULL;
@@ -4398,7 +4394,6 @@ remote_target::process_initial_stop_replies (int from_tty)
       ptid_t event_ptid;
       struct target_waitstatus ws;
       int ignore_event = 0;
-      struct thread_info *thread;
 
       memset (&ws, 0, sizeof (ws));
       event_ptid = target_wait (waiton_ptid, &ws, TARGET_WNOHANG);
@@ -4427,7 +4422,7 @@ remote_target::process_initial_stop_replies (int from_tty)
       if (ignore_event)
        continue;
 
-      thread = find_thread_ptid (event_ptid);
+      struct thread_info *evthread = find_thread_ptid (event_ptid);
 
       if (ws.kind == TARGET_WAITKIND_STOPPED)
        {
@@ -4437,33 +4432,30 @@ remote_target::process_initial_stop_replies (int from_tty)
             instead of signal 0.  Suppress it.  */
          if (sig == GDB_SIGNAL_TRAP)
            sig = GDB_SIGNAL_0;
-         thread->suspend.stop_signal = sig;
+         evthread->suspend.stop_signal = sig;
          ws.value.sig = sig;
        }
 
-      thread->suspend.waitstatus = ws;
+      evthread->suspend.waitstatus = ws;
 
       if (ws.kind != TARGET_WAITKIND_STOPPED
          || ws.value.sig != GDB_SIGNAL_0)
-       thread->suspend.waitstatus_pending_p = 1;
+       evthread->suspend.waitstatus_pending_p = 1;
 
       set_executing (event_ptid, 0);
       set_running (event_ptid, 0);
-      get_remote_thread_info (thread)->vcont_resumed = 0;
+      get_remote_thread_info (evthread)->vcont_resumed = 0;
     }
 
   /* "Notice" the new inferiors before anything related to
      registers/memory.  */
-  ALL_INFERIORS (inf)
+  for (inferior *inf : all_non_exited_inferiors ())
     {
-      if (inf->pid == 0)
-       continue;
-
       inf->needs_setup = 1;
 
       if (non_stop)
        {
-         thread = any_live_thread_of_inferior (inf);
+         thread_info *thread = any_live_thread_of_inferior (inf);
          notice_new_inferior (thread, thread->state == THREAD_RUNNING,
                               from_tty);
        }
@@ -4478,14 +4470,11 @@ remote_target::process_initial_stop_replies (int from_tty)
 
       /* If all threads of an inferior were already stopped, we
         haven't setup the inferior yet.  */
-      ALL_INFERIORS (inf)
+      for (inferior *inf : all_non_exited_inferiors ())
        {
-         if (inf->pid == 0)
-           continue;
-
          if (inf->needs_setup)
            {
-             thread = any_live_thread_of_inferior (inf);
+             thread_info *thread = any_live_thread_of_inferior (inf);
              switch_to_thread_no_regs (thread);
              setup_inferior (0);
            }
@@ -4495,7 +4484,7 @@ remote_target::process_initial_stop_replies (int from_tty)
   /* Now go over all threads that are stopped, and print their current
      frame.  If all-stop, then if there's a signalled thread, pick
      that as current.  */
-  ALL_NON_EXITED_THREADS (thread)
+  for (thread_info *thread : all_non_exited_threads ())
     {
       if (first == NULL)
        first = thread;
@@ -4522,7 +4511,7 @@ remote_target::process_initial_stop_replies (int from_tty)
      others with their status pending.  */
   if (!non_stop)
     {
-      thread = selected;
+      thread_info *thread = selected;
       if (thread == NULL)
        thread = lowest_stopped;
       if (thread == NULL)
@@ -4532,7 +4521,7 @@ remote_target::process_initial_stop_replies (int from_tty)
     }
 
   /* For "info program".  */
-  thread = inferior_thread ();
+  thread_info *thread = inferior_thread ();
   if (thread->state == THREAD_STOPPED)
     set_last_target_status (inferior_ptid, thread->suspend.waitstatus);
 }
@@ -4731,7 +4720,7 @@ remote_target::start_remote (int from_tty, int extended_p)
                                    "warning: couldn't determine remote "
                                    "current thread; picking first in list.\n");
 
-             inferior_ptid = thread_list->ptid;
+             inferior_ptid = inferior_list->thread_list->ptid;
            }
        }
 
@@ -5613,9 +5602,6 @@ remote_target::open_1 (const char *name, int from_tty, int extended_p)
   /* First delete any symbols previously loaded from shared libraries.  */
   no_shared_libraries (NULL, 0);
 
-  /* Start afresh.  */
-  init_thread_list ();
-
   /* Start the remote connection.  If error() or QUIT, discard this
      target (we'd otherwise be in an inconsistent state) and then
      propogate the error on up the exception chain.  This ensures that
@@ -5661,6 +5647,14 @@ remote_target::remote_detach_pid (int pid)
 {
   struct remote_state *rs = get_remote_state ();
 
+  /* This should not be necessary, but the handling for D;PID in
+     GDBserver versions prior to 8.2 incorrectly assumes that the
+     selected process points to the same process we're detaching,
+     leading to misbehavior (and possibly GDBserver crashing) when it
+     does not.  Since it's easy and cheap, work around it by forcing
+     GDBserver to select GDB's current process.  */
+  set_general_process ();
+
   if (remote_multi_process_p (rs))
     xsnprintf (rs->buf, get_remote_packet_size (), "D;%x", pid);
   else
@@ -6105,11 +6099,8 @@ char *
 remote_target::append_pending_thread_resumptions (char *p, char *endp,
                                                  ptid_t ptid)
 {
-  struct thread_info *thread;
-
-  ALL_NON_EXITED_THREADS (thread)
-    if (thread->ptid.matches (ptid)
-       && inferior_ptid != thread->ptid
+  for (thread_info *thread : all_non_exited_threads (ptid))
+    if (inferior_ptid != thread->ptid
        && thread->suspend.stop_signal != GDB_SIGNAL_0)
       {
        p = append_resumption (p, endp, thread->ptid,
@@ -6129,7 +6120,6 @@ remote_target::remote_resume_with_hc (ptid_t ptid, int step,
                                      gdb_signal siggnal)
 {
   struct remote_state *rs = get_remote_state ();
-  struct thread_info *thread;
   char *buf;
 
   rs->last_sent_signal = siggnal;
@@ -6142,7 +6132,7 @@ remote_target::remote_resume_with_hc (ptid_t ptid, int step,
   else
     set_continue_thread (ptid);
 
-  ALL_NON_EXITED_THREADS (thread)
+  for (thread_info *thread : all_non_exited_threads ())
     resume_clear_thread_private_info (thread);
 
   buf = rs->buf;
@@ -6450,8 +6440,6 @@ vcont_builder::push_action (ptid_t ptid, bool step, gdb_signal siggnal)
 void
 remote_target::commit_resume ()
 {
-  struct inferior *inf;
-  struct thread_info *tp;
   int any_process_wildcard;
   int may_global_wildcard_vcont;
 
@@ -6514,7 +6502,7 @@ remote_target::commit_resume ()
   may_global_wildcard_vcont = 1;
 
   /* And assume every process is individually wildcard-able too.  */
-  ALL_NON_EXITED_INFERIORS (inf)
+  for (inferior *inf : all_non_exited_inferiors ())
     {
       remote_inferior *priv = get_remote_inferior (inf);
 
@@ -6525,7 +6513,7 @@ remote_target::commit_resume ()
      disable process and global wildcard resumes appropriately.  */
   check_pending_events_prevent_wildcard_vcont (&may_global_wildcard_vcont);
 
-  ALL_NON_EXITED_THREADS (tp)
+  for (thread_info *tp : all_non_exited_threads ())
     {
       /* If a thread of a process is not meant to be resumed, then we
         can't wildcard that process.  */
@@ -6554,7 +6542,7 @@ remote_target::commit_resume ()
   struct vcont_builder vcont_builder (this);
 
   /* Threads first.  */
-  ALL_NON_EXITED_THREADS (tp)
+  for (thread_info *tp : all_non_exited_threads ())
     {
       remote_thread_info *remote_thr = get_remote_thread_info (tp);
 
@@ -6583,7 +6571,7 @@ remote_target::commit_resume ()
      supposed to be resumed.  */
   any_process_wildcard = 0;
 
-  ALL_NON_EXITED_INFERIORS (inf)
+  for (inferior *inf : all_non_exited_inferiors ())
     {
       if (get_remote_inferior (inf)->may_wildcard_vcont)
        {
@@ -6604,7 +6592,7 @@ remote_target::commit_resume ()
        }
       else
        {
-         ALL_NON_EXITED_INFERIORS (inf)
+         for (inferior *inf : all_non_exited_inferiors ())
            {
              if (get_remote_inferior (inf)->may_wildcard_vcont)
                {
@@ -7011,13 +6999,12 @@ is_pending_fork_parent_thread (struct thread_info *thread)
 void
 remote_target::remove_new_fork_children (threads_listing_context *context)
 {
-  struct thread_info * thread;
   int pid = -1;
   struct notif_client *notif = &notif_client_stop;
 
   /* For any threads stopped at a fork event, remove the corresponding
      fork child threads from the CONTEXT list.  */
-  ALL_NON_EXITED_THREADS (thread)
+  for (thread_info *thread : all_non_exited_threads ())
     {
       struct target_waitstatus *ws = thread_pending_fork_status (thread);
 
@@ -7501,7 +7488,6 @@ Packet: '%s'\n"),
       break;
     case 'w':          /* Thread exited.  */
       {
-       const char *p;
        ULONGEST value;
 
        event->ws.kind = TARGET_WAITKIND_THREAD_EXITED;
@@ -7515,7 +7501,6 @@ Packet: '%s'\n"),
     case 'W':          /* Target exited.  */
     case 'X':
       {
-       const char *p;
        int pid;
        ULONGEST value;
 
@@ -7856,8 +7841,6 @@ remote_target::wait_as (ptid_t ptid, target_waitstatus *status, int options)
       break;
     case 'N': case 'T': case 'S': case 'X': case 'W':
       {
-       struct stop_reply *stop_reply;
-
        /* There is a stop reply to handle.  */
        rs->waiting_for_stop_reply = 0;
 
@@ -8935,7 +8918,11 @@ remote_target::remote_send_printf (const char *format, ...)
   va_start (ap, format);
 
   rs->buf[0] = '\0';
-  if (vsnprintf (rs->buf, max_size, format, ap) >= max_size)
+  int size = vsnprintf (rs->buf, max_size, format, ap);
+
+  va_end (ap);
+
+  if (size >= max_size)
     internal_error (__FILE__, __LINE__, _("Too long remote packet."));
 
   if (putpkt (rs->buf) < 0)
@@ -9709,12 +9696,11 @@ void
 remote_target::kill_new_fork_children (int pid)
 {
   remote_state *rs = get_remote_state ();
-  struct thread_info *thread;
   struct notif_client *notif = &notif_client_stop;
 
   /* Kill the fork child threads of any threads in process PID
      that are stopped at a fork event.  */
-  ALL_NON_EXITED_THREADS (thread)
+  for (thread_info *thread : all_non_exited_threads ())
     {
       struct target_waitstatus *ws = &thread->pending_follow;
 
@@ -10150,21 +10136,12 @@ Remote replied unexpectedly while setting startup-with-shell: %s"),
       if (remote_exec_file[0])
        error (_("Remote target does not support \"set remote exec-file\""));
       if (!args.empty ())
-       error (_("Remote target does not support \"set args\" or run <ARGS>"));
+       error (_("Remote target does not support \"set args\" or run ARGS"));
 
       /* Fall back to "R".  */
       extended_remote_restart ();
     }
 
-  if (!have_inferiors ())
-    {
-      /* Clean up from the last time we ran, before we mark the target
-        running again.  This will mark breakpoints uninserted, and
-        get_offsets may insert breakpoints.  */
-      init_thread_list ();
-      init_wait_for_inferior ();
-    }
-
   /* vRun's success return is a stop reply.  */
   stop_reply = run_worked ? rs->buf : NULL;
   add_current_inferior_and_thread (stop_reply);
@@ -11542,10 +11519,10 @@ remote_target::get_thread_local_address (ptid_t ptid, CORE_ADDR lm,
                          &remote_protocol_packets[PACKET_qGetTLSAddr]);
       if (result == PACKET_OK)
        {
-         ULONGEST result;
+         ULONGEST addr;
 
-         unpack_varlen_hex (rs->buf, &result);
-         return result;
+         unpack_varlen_hex (rs->buf, &addr);
+         return addr;
        }
       else if (result == PACKET_UNKNOWN)
        throw_error (TLS_GENERIC_ERROR,
@@ -11585,11 +11562,10 @@ remote_target::get_tib_address (ptid_t ptid, CORE_ADDR *addr)
                          &remote_protocol_packets[PACKET_qGetTIBAddr]);
       if (result == PACKET_OK)
        {
-         ULONGEST result;
-
-         unpack_varlen_hex (rs->buf, &result);
+         ULONGEST val;
+         unpack_varlen_hex (rs->buf, &val);
          if (addr)
-           *addr = (CORE_ADDR) result;
+           *addr = (CORE_ADDR) val;
          return true;
        }
       else if (result == PACKET_UNKNOWN)
@@ -11611,15 +11587,19 @@ remote_target::get_tib_address (ptid_t ptid, CORE_ADDR *addr)
 
 struct remote_g_packet_guess
 {
+  remote_g_packet_guess (int bytes_, const struct target_desc *tdesc_)
+    : bytes (bytes_),
+      tdesc (tdesc_)
+  {
+  }
+
   int bytes;
   const struct target_desc *tdesc;
 };
-typedef struct remote_g_packet_guess remote_g_packet_guess_s;
-DEF_VEC_O(remote_g_packet_guess_s);
 
-struct remote_g_packet_data
+struct remote_g_packet_data : public allocate_on_obstack
 {
-  VEC(remote_g_packet_guess_s) *guesses;
+  std::vector<remote_g_packet_guess> guesses;
 };
 
 static struct gdbarch_data *remote_g_packet_data_handle;
@@ -11627,7 +11607,7 @@ static struct gdbarch_data *remote_g_packet_data_handle;
 static void *
 remote_g_packet_data_init (struct obstack *obstack)
 {
-  return OBSTACK_ZALLOC (obstack, struct remote_g_packet_data);
+  return new (obstack) remote_g_packet_data;
 }
 
 void
@@ -11637,38 +11617,29 @@ register_remote_g_packet_guess (struct gdbarch *gdbarch, int bytes,
   struct remote_g_packet_data *data
     = ((struct remote_g_packet_data *)
        gdbarch_data (gdbarch, remote_g_packet_data_handle));
-  struct remote_g_packet_guess new_guess, *guess;
-  int ix;
 
   gdb_assert (tdesc != NULL);
 
-  for (ix = 0;
-       VEC_iterate (remote_g_packet_guess_s, data->guesses, ix, guess);
-       ix++)
-    if (guess->bytes == bytes)
+  for (const remote_g_packet_guess &guess : data->guesses)
+    if (guess.bytes == bytes)
       internal_error (__FILE__, __LINE__,
                      _("Duplicate g packet description added for size %d"),
                      bytes);
 
-  new_guess.bytes = bytes;
-  new_guess.tdesc = tdesc;
-  VEC_safe_push (remote_g_packet_guess_s, data->guesses, &new_guess);
+  data->guesses.emplace_back (bytes, tdesc);
 }
 
-/* Return 1 if remote_read_description would do anything on this target
-   and architecture, 0 otherwise.  */
+/* Return true if remote_read_description would do anything on this target
+   and architecture, false otherwise.  */
 
-static int
+static bool
 remote_read_description_p (struct target_ops *target)
 {
   struct remote_g_packet_data *data
     = ((struct remote_g_packet_data *)
        gdbarch_data (target_gdbarch (), remote_g_packet_data_handle));
 
-  if (!VEC_empty (remote_g_packet_guess_s, data->guesses))
-    return 1;
-
-  return 0;
+  return !data->guesses.empty ();
 }
 
 const struct target_desc *
@@ -11683,17 +11654,13 @@ remote_target::read_description ()
   if (!target_has_execution || inferior_ptid == null_ptid)
     return beneath ()->read_description ();
 
-  if (!VEC_empty (remote_g_packet_guess_s, data->guesses))
+  if (!data->guesses.empty ())
     {
-      struct remote_g_packet_guess *guess;
-      int ix;
       int bytes = send_g_packet ();
 
-      for (ix = 0;
-          VEC_iterate (remote_g_packet_guess_s, data->guesses, ix, guess);
-          ix++)
-       if (guess->bytes == bytes)
-         return guess->tdesc;
+      for (const remote_g_packet_guess &guess : data->guesses)
+       if (guess.bytes == bytes)
+         return guess.tdesc;
 
       /* We discard the g packet.  A minor optimization would be to
         hold on to it, and fill the register cache once we have selected
@@ -12824,26 +12791,35 @@ remote_target::remote_download_command_source (int num, ULONGEST addr,
 void
 remote_target::download_tracepoint (struct bp_location *loc)
 {
-#define BUF_SIZE 2048
-
   CORE_ADDR tpaddr;
   char addrbuf[40];
-  char buf[BUF_SIZE];
   std::vector<std::string> tdp_actions;
   std::vector<std::string> stepping_actions;
   char *pkt;
   struct breakpoint *b = loc->owner;
   struct tracepoint *t = (struct tracepoint *) b;
   struct remote_state *rs = get_remote_state ();
+  int ret;
+  const char *err_msg = _("Tracepoint packet too large for target.");
+  size_t size_left;
+
+  /* We use a buffer other than rs->buf because we'll build strings
+     across multiple statements, and other statements in between could
+     modify rs->buf.  */
+  gdb::char_vector buf (get_remote_packet_size ());
 
   encode_actions_rsp (loc, &tdp_actions, &stepping_actions);
 
   tpaddr = loc->address;
   sprintf_vma (addrbuf, tpaddr);
-  xsnprintf (buf, BUF_SIZE, "QTDP:%x:%s:%c:%lx:%x", b->number,
-            addrbuf, /* address */
-            (b->enable_state == bp_enabled ? 'E' : 'D'),
-            t->step_count, t->pass_count);
+  ret = snprintf (buf.data (), buf.size (), "QTDP:%x:%s:%c:%lx:%x",
+                 b->number, addrbuf, /* address */
+                 (b->enable_state == bp_enabled ? 'E' : 'D'),
+                 t->step_count, t->pass_count);
+
+  if (ret < 0 || ret >= buf.size ())
+    error ("%s", err_msg);
+
   /* Fast tracepoints are mostly handled by the target, but we can
      tell the target how big of an instruction block should be moved
      around.  */
@@ -12855,8 +12831,15 @@ remote_target::download_tracepoint (struct bp_location *loc)
        {
          if (gdbarch_fast_tracepoint_valid_at (loc->gdbarch, tpaddr,
                                                NULL))
-           xsnprintf (buf + strlen (buf), BUF_SIZE - strlen (buf), ":F%x",
-                      gdb_insn_length (loc->gdbarch, tpaddr));
+           {
+             size_left = buf.size () - strlen (buf.data ());
+             ret = snprintf (buf.data () + strlen (buf.data ()),
+                             size_left, ":F%x",
+                             gdb_insn_length (loc->gdbarch, tpaddr));
+
+             if (ret < 0 || ret >= size_left)
+               error ("%s", err_msg);
+           }
          else
            /* If it passed validation at definition but fails now,
               something is very wrong.  */
@@ -12880,7 +12863,14 @@ remote_target::download_tracepoint (struct bp_location *loc)
          struct static_tracepoint_marker marker;
 
          if (target_static_tracepoint_marker_at (tpaddr, &marker))
-           strcat (buf, ":S");
+           {
+             size_left = buf.size () - strlen (buf.data ());
+             ret = snprintf (buf.data () + strlen (buf.data ()),
+                             size_left, ":S");
+
+             if (ret < 0 || ret >= size_left)
+               error ("%s", err_msg);
+           }
          else
            error (_("Static tracepoint not valid during download"));
        }
@@ -12898,10 +12888,26 @@ remote_target::download_tracepoint (struct bp_location *loc)
         capabilities at definition time.  */
       if (remote_supports_cond_tracepoints ())
        {
-         agent_expr_up aexpr = gen_eval_for_expr (tpaddr, loc->cond.get ());
-         xsnprintf (buf + strlen (buf), BUF_SIZE - strlen (buf), ":X%x,",
-                    aexpr->len);
-         pkt = buf + strlen (buf);
+         agent_expr_up aexpr = gen_eval_for_expr (tpaddr,
+                                                  loc->cond.get ());
+
+         size_left = buf.size () - strlen (buf.data ());
+
+         ret = snprintf (buf.data () + strlen (buf.data ()),
+                         size_left, ":X%x,", aexpr->len);
+
+         if (ret < 0 || ret >= size_left)
+           error ("%s", err_msg);
+
+         size_left = buf.size () - strlen (buf.data ());
+
+         /* Two bytes to encode each aexpr byte, plus the terminating
+            null byte.  */
+         if (aexpr->len * 2 + 1 > size_left)
+           error ("%s", err_msg);
+
+         pkt = buf.data () + strlen (buf.data ());
+
          for (int ndx = 0; ndx < aexpr->len; ++ndx)
            pkt = pack_hex_byte (pkt, aexpr->buf[ndx]);
          *pkt = '\0';
@@ -12912,8 +12918,17 @@ remote_target::download_tracepoint (struct bp_location *loc)
     }
 
   if (b->commands || *default_collect)
-    strcat (buf, "-");
-  putpkt (buf);
+    {
+      size_left = buf.size () - strlen (buf.data ());
+
+      ret = snprintf (buf.data () + strlen (buf.data ()),
+                     size_left, "-");
+
+      if (ret < 0 || ret >= size_left)
+       error ("%s", err_msg);
+    }
+
+  putpkt (buf.data ());
   remote_get_noisy_reply ();
   if (strcmp (rs->buf, "OK"))
     error (_("Target does not support tracepoints."));
@@ -12924,58 +12939,76 @@ remote_target::download_tracepoint (struct bp_location *loc)
     {
       QUIT;    /* Allow user to bail out with ^C.  */
 
-      bool has_more = (action_it != tdp_actions.end ()
+      bool has_more = ((action_it + 1) != tdp_actions.end ()
                       || !stepping_actions.empty ());
 
-      xsnprintf (buf, BUF_SIZE, "QTDP:-%x:%s:%s%c",
-                b->number, addrbuf, /* address */
-                action_it->c_str (),
-                has_more ? '-' : 0);
-      putpkt (buf);
+      ret = snprintf (buf.data (), buf.size (), "QTDP:-%x:%s:%s%c",
+                     b->number, addrbuf, /* address */
+                     action_it->c_str (),
+                     has_more ? '-' : 0);
+
+      if (ret < 0 || ret >= buf.size ())
+       error ("%s", err_msg);
+
+      putpkt (buf.data ());
       remote_get_noisy_reply ();
       if (strcmp (rs->buf, "OK"))
        error (_("Error on target while setting tracepoints."));
     }
 
-    for (auto action_it = stepping_actions.begin ();
-        action_it != stepping_actions.end (); action_it++)
-      {
-       QUIT;   /* Allow user to bail out with ^C.  */
-
-       bool is_first = action_it == stepping_actions.begin ();
-       bool has_more = action_it != stepping_actions.end ();
-
-       xsnprintf (buf, BUF_SIZE, "QTDP:-%x:%s:%s%s%s",
-                  b->number, addrbuf, /* address */
-                  is_first ? "S" : "",
-                  action_it->c_str (),
-                  has_more ? "-" : "");
-       putpkt (buf);
-       remote_get_noisy_reply ();
-       if (strcmp (rs->buf, "OK"))
-         error (_("Error on target while setting tracepoints."));
-      }
+  for (auto action_it = stepping_actions.begin ();
+       action_it != stepping_actions.end (); action_it++)
+    {
+      QUIT;    /* Allow user to bail out with ^C.  */
+
+      bool is_first = action_it == stepping_actions.begin ();
+      bool has_more = (action_it + 1) != stepping_actions.end ();
+
+      ret = snprintf (buf.data (), buf.size (), "QTDP:-%x:%s:%s%s%s",
+                     b->number, addrbuf, /* address */
+                     is_first ? "S" : "",
+                     action_it->c_str (),
+                     has_more ? "-" : "");
+
+      if (ret < 0 || ret >= buf.size ())
+       error ("%s", err_msg);
+
+      putpkt (buf.data ());
+      remote_get_noisy_reply ();
+      if (strcmp (rs->buf, "OK"))
+       error (_("Error on target while setting tracepoints."));
+    }
 
   if (packet_support (PACKET_TracepointSource) == PACKET_ENABLE)
     {
       if (b->location != NULL)
        {
-         strcpy (buf, "QTDPsrc:");
+         ret = snprintf (buf.data (), buf.size (), "QTDPsrc:");
+
+         if (ret < 0 || ret >= buf.size ())
+           error ("%s", err_msg);
+
          encode_source_string (b->number, loc->address, "at",
                                event_location_to_string (b->location.get ()),
-                               buf + strlen (buf), 2048 - strlen (buf));
-         putpkt (buf);
+                               buf.data () + strlen (buf.data ()),
+                               buf.size () - strlen (buf.data ()));
+         putpkt (buf.data ());
          remote_get_noisy_reply ();
          if (strcmp (rs->buf, "OK"))
            warning (_("Target does not support source download."));
        }
       if (b->cond_string)
        {
-         strcpy (buf, "QTDPsrc:");
+         ret = snprintf (buf.data (), buf.size (), "QTDPsrc:");
+
+         if (ret < 0 || ret >= buf.size ())
+           error ("%s", err_msg);
+
          encode_source_string (b->number, loc->address,
-                               "cond", b->cond_string, buf + strlen (buf),
-                               2048 - strlen (buf));
-         putpkt (buf);
+                               "cond", b->cond_string,
+                               buf.data () + strlen (buf.data ()),
+                               buf.size () - strlen (buf.data ()));
+         putpkt (buf.data ());
          remote_get_noisy_reply ();
          if (strcmp (rs->buf, "OK"))
            warning (_("Target does not support source download."));
@@ -13707,13 +13740,14 @@ void
 remote_target::remote_btrace_maybe_reopen ()
 {
   struct remote_state *rs = get_remote_state ();
-  struct thread_info *tp;
   int btrace_target_pushed = 0;
+#if !defined (HAVE_LIBIPT)
   int warned = 0;
+#endif
 
   scoped_restore_current_thread restore_thread;
 
-  ALL_NON_EXITED_THREADS (tp)
+  for (thread_info *tp : all_non_exited_threads ())
     {
       set_general_thread (tp->ptid);
 
@@ -13997,9 +14031,7 @@ remote_target::thread_handle_to_thread_info (const gdb_byte *thread_handle,
                                             int handle_len,
                                             inferior *inf)
 {
-  struct thread_info *tp;
-
-  ALL_NON_EXITED_THREADS (tp)
+  for (thread_info *tp : all_non_exited_threads ())
     {
       remote_thread_info *priv = get_remote_thread_info (tp);
 
This page took 0.035101 seconds and 4 git commands to generate.