Simple -Wshadow=local fixes
[deliverable/binutils-gdb.git] / gdb / remote.c
index a61680d242c64fd8397d99b9a12463ec6301a9b2..724f41cf71e291ebf0badf33982713e29c75cc87 100644 (file)
@@ -3830,7 +3830,7 @@ remote_target::update_thread_list ()
 
              remote_notice_new_inferior (item.ptid, executing);
 
-             thread_info *tp = find_thread_ptid (item.ptid);
+             tp = find_thread_ptid (item.ptid);
              remote_thread_info *info = get_remote_thread_info (tp);
              info->core = item.core;
              info->extra = std::move (item.extra);
@@ -4398,7 +4398,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 +4426,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,19 +4436,19 @@ 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
@@ -7509,7 +7508,6 @@ Packet: '%s'\n"),
       break;
     case 'w':          /* Thread exited.  */
       {
-       const char *p;
        ULONGEST value;
 
        event->ws.kind = TARGET_WAITKIND_THREAD_EXITED;
@@ -7523,7 +7521,6 @@ Packet: '%s'\n"),
     case 'W':          /* Target exited.  */
     case 'X':
       {
-       const char *p;
        int pid;
        ULONGEST value;
 
@@ -7864,8 +7861,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;
 
@@ -10158,7 +10153,7 @@ 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 ();
@@ -11550,10 +11545,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,
@@ -11593,11 +11588,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)
@@ -12832,26 +12826,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.  */
@@ -12863,8 +12866,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.  */
@@ -12888,7 +12898,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"));
        }
@@ -12906,10 +12923,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';
@@ -12920,8 +12953,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."));
@@ -12932,58 +12974,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."));
This page took 0.031076 seconds and 4 git commands to generate.