* linux-thread-db.c (thread_db_mourn_inferior): Remove breakpoints
[deliverable/binutils-gdb.git] / gdb / remote.c
index bc12efd26c37e520c07e2039843dcb2fb9cb864d..a162d32642c6a5738acf0326e888debc7a8cda17 100644 (file)
@@ -1,7 +1,7 @@
 /* Remote target communications for serial-line targets in custom GDB protocol
 
-   Copyright 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996,
-   1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
+   Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996,
+   1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006
    Free Software Foundation, Inc.
 
    This file is part of GDB.
@@ -18,8 +18,8 @@
 
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
-   Foundation, Inc., 59 Temple Place - Suite 330,
-   Boston, MA 02111-1307, USA.  */
+   Foundation, Inc., 51 Franklin Street, Fifth Floor,
+   Boston, MA 02110-1301, USA.  */
 
 /* See the GDB User Guide for details of the GDB remote protocol.  */
 
@@ -172,9 +172,9 @@ static void record_currthread (int currthread);
 
 static int fromhex (int a);
 
-static int hex2bin (const char *hex, char *bin, int count);
+static int hex2bin (const char *hex, gdb_byte *bin, int count);
 
-static int bin2hex (const char *bin, char *hex, int count);
+static int bin2hex (const gdb_byte *bin, char *hex, int count);
 
 static int putpkt_binary (char *buf, int cnt);
 
@@ -377,9 +377,9 @@ static int remote_async_terminal_ours_p;
 
 \f
 /* User configurable variables for the number of characters in a
-   memory read/write packet.  MIN ((rs->remote_packet_size),
+   memory read/write packet.  MIN (rs->remote_packet_size,
    rs->sizeof_g_packet) is the default.  Some targets need smaller
-   values (fifo overruns, et.al.)  and some users need larger values
+   values (fifo overruns, et.al.) and some users need larger values
    (speed up transfers).  The variables ``preferred_*'' (the user
    request), ``current_*'' (what was actually set) and ``forced_*''
    (Positive - a soft limit, negative - a hard limit).  */
@@ -420,7 +420,7 @@ get_memory_packet_size (struct memory_packet_config *config)
     }
   else
     {
-      what_they_get = (rs->remote_packet_size);
+      what_they_get = rs->remote_packet_size;
       /* Limit the packet to the size specified by the user.  */
       if (config->size > 0
          && what_they_get > config->size)
@@ -540,9 +540,9 @@ get_memory_read_packet_size (void)
   long size = get_memory_packet_size (&memory_read_packet_config);
   /* FIXME: cagney/1999-11-07: Functions like getpkt() need to get an
      extra buffer size argument before the memory read size can be
-     increased beyond (rs->remote_packet_size).  */
-  if (size > (rs->remote_packet_size))
-    size = (rs->remote_packet_size);
+     increased beyond RS->remote_packet_size.  */
+  if (size > rs->remote_packet_size)
+    size = rs->remote_packet_size;
   return size;
 }
 
@@ -1056,11 +1056,11 @@ set_thread (int th, int gen)
       buf[3] = '\0';
     }
   else if (th < 0)
-    sprintf (&buf[2], "-%x", -th);
+    xsnprintf (&buf[2], rs->remote_packet_size - 2, "-%x", -th);
   else
-    sprintf (&buf[2], "%x", th);
+    xsnprintf (&buf[2], rs->remote_packet_size - 2, "%x", th);
   putpkt (buf);
-  getpkt (buf, (rs->remote_packet_size), 0);
+  getpkt (buf, rs->remote_packet_size, 0);
   if (gen)
     general_thread = th;
   else
@@ -1076,9 +1076,9 @@ remote_thread_alive (ptid_t ptid)
   char buf[16];
 
   if (tid < 0)
-    sprintf (buf, "T-%08x", -tid);
+    xsnprintf (buf, sizeof (buf), "T-%08x", -tid);
   else
-    sprintf (buf, "T%08x", tid);
+    xsnprintf (buf, sizeof (buf), "T%08x", tid);
   putpkt (buf);
   getpkt (buf, sizeof (buf), 0);
   return (buf[0] == 'O' && buf[1] == 'K');
@@ -1114,7 +1114,7 @@ struct gdb_ext_thread_info
     int active;                        /* Has state interesting to GDB? 
                                   regs, stack.  */
     char display[256];         /* Brief state display, name, 
-                                  blocked/syspended.  */
+                                  blocked/suspended.  */
     char shortname[32];                /* To be used to name threads.  */
     char more_display[256];    /* Long info, statistics, queue depth, 
                                   whatever.  */
@@ -1409,7 +1409,7 @@ threadref_to_int (threadref *ref)
   int i, value = 0;
   unsigned char *scan;
 
-  scan = (char *) ref;
+  scan = *ref;
   scan += 4;
   i = 4;
   while (i-- > 0)
@@ -1487,9 +1487,9 @@ remote_unpack_thread_info_response (char *pkt, threadref *expectedref,
 {
   struct remote_state *rs = get_remote_state ();
   int mask, length;
-  unsigned int tag;
+  int tag;
   threadref ref;
-  char *limit = pkt + (rs->remote_packet_size);        /* plausable parsing limit */
+  char *limit = pkt + rs->remote_packet_size; /* Plausible parsing limit.  */
   int retval = 1;
 
   /* info->threadid = 0; FIXME: implement zero_threadref.  */
@@ -1584,7 +1584,7 @@ remote_get_threadinfo (threadref *threadid, int fieldset, /* TAG mask */
 
   pack_threadinfo_request (threadinfo_pkt, fieldset, threadid);
   putpkt (threadinfo_pkt);
-  getpkt (threadinfo_pkt, (rs->remote_packet_size), 0);
+  getpkt (threadinfo_pkt, rs->remote_packet_size, 0);
   result = remote_unpack_thread_info_response (threadinfo_pkt + 2,
                                               threadid, info);
   return result;
@@ -1618,7 +1618,7 @@ parse_threadlist_response (char *pkt, int result_limit,
 
   resultcount = 0;
   /* Assume the 'q' and 'M chars have been stripped.  */
-  limit = pkt + ((rs->remote_packet_size) - BUF_THREAD_ID_SIZE);
+  limit = pkt + (rs->remote_packet_size - BUF_THREAD_ID_SIZE);
   /* done parse past here */
   pkt = unpack_byte (pkt, &count);     /* count field */
   pkt = unpack_nibble (pkt, &done);
@@ -1646,13 +1646,13 @@ remote_get_threadlist (int startflag, threadref *nextthread, int result_limit,
   int result = 1;
 
   /* Trancate result limit to be smaller than the packet size.  */
-  if ((((result_limit + 1) * BUF_THREAD_ID_SIZE) + 10) >= (rs->remote_packet_size))
-    result_limit = ((rs->remote_packet_size) / BUF_THREAD_ID_SIZE) - 2;
+  if ((((result_limit + 1) * BUF_THREAD_ID_SIZE) + 10) >= rs->remote_packet_size)
+    result_limit = (rs->remote_packet_size / BUF_THREAD_ID_SIZE) - 2;
 
   pack_threadlist_request (threadlist_packet,
                           startflag, result_limit, nextthread);
   putpkt (threadlist_packet);
-  getpkt (t_response, (rs->remote_packet_size), 0);
+  getpkt (t_response, rs->remote_packet_size, 0);
 
   *result_count =
     parse_threadlist_response (t_response + 2, result_limit, &echo_nextthread,
@@ -1763,7 +1763,7 @@ remote_current_thread (ptid_t oldpid)
   char *buf = alloca (rs->remote_packet_size);
 
   putpkt ("qC");
-  getpkt (buf, (rs->remote_packet_size), 0);
+  getpkt (buf, rs->remote_packet_size, 0);
   if (buf[0] == 'Q' && buf[1] == 'C')
     /* Use strtoul here, so we'll correctly parse values whose highest
        bit is set.  The protocol carries them as a simple series of
@@ -1810,7 +1810,7 @@ remote_threads_info (void)
     {
       putpkt ("qfThreadInfo");
       bufp = buf;
-      getpkt (bufp, (rs->remote_packet_size), 0);
+      getpkt (bufp, rs->remote_packet_size, 0);
       if (bufp[0] != '\0')             /* q packet recognized */
        {
          while (*bufp++ == 'm')        /* reply contains one or more TID */
@@ -1830,7 +1830,7 @@ remote_threads_info (void)
              while (*bufp++ == ',');   /* comma-separated list */
              putpkt ("qsThreadInfo");
              bufp = buf;
-             getpkt (bufp, (rs->remote_packet_size), 0);
+             getpkt (bufp, rs->remote_packet_size, 0);
            }
          return;       /* done */
        }
@@ -1869,13 +1869,14 @@ remote_threads_extra_info (struct thread_info *tp)
 
   if (use_threadextra_query)
     {
-      sprintf (bufp, "qThreadExtraInfo,%x", PIDGET (tp->ptid));
+      xsnprintf (bufp, rs->remote_packet_size, "qThreadExtraInfo,%x", 
+                PIDGET (tp->ptid));
       putpkt (bufp);
-      getpkt (bufp, (rs->remote_packet_size), 0);
+      getpkt (bufp, rs->remote_packet_size, 0);
       if (bufp[0] != 0)
        {
          n = min (strlen (bufp) / 2, sizeof (display_buf));
-         result = hex2bin (bufp, display_buf, n);
+         result = hex2bin (bufp, (gdb_byte *) display_buf, n);
          display_buf [result] = '\0';
          return display_buf;
        }
@@ -1890,12 +1891,14 @@ remote_threads_extra_info (struct thread_info *tp)
     if (threadinfo.active)
       {
        if (*threadinfo.shortname)
-         n += sprintf(&display_buf[0], " Name: %s,", threadinfo.shortname);
+         n += xsnprintf (&display_buf[0], sizeof (display_buf) - n, 
+                         " Name: %s,", threadinfo.shortname);
        if (*threadinfo.display)
-         n += sprintf(&display_buf[n], " State: %s,", threadinfo.display);
+         n += xsnprintf (&display_buf[n], sizeof (display_buf) - n, 
+                         " State: %s,", threadinfo.display);
        if (*threadinfo.more_display)
-         n += sprintf(&display_buf[n], " Priority: %s",
-                      threadinfo.more_display);
+         n += xsnprintf (&display_buf[n], sizeof (display_buf) - n, 
+                         " Priority: %s", threadinfo.more_display);
 
        if (n > 0)
          {
@@ -1907,10 +1910,9 @@ remote_threads_extra_info (struct thread_info *tp)
       }
   return NULL;
 }
-
 \f
 
-/*  Restart the remote side; this is an extended protocol operation.  */
+/* Restart the remote side; this is an extended protocol operation.  */
 
 static void
 extended_remote_restart (void)
@@ -1920,14 +1922,13 @@ extended_remote_restart (void)
 
   /* Send the restart command; for reasons I don't understand the
      remote side really expects a number after the "R".  */
-  buf[0] = 'R';
-  sprintf (&buf[1], "%x", 0);
+  xsnprintf (buf, rs->remote_packet_size, "R%x", 0);
   putpkt (buf);
 
   /* Now query for status so this looks just like we restarted
      gdbserver from scratch.  */
   putpkt ("?");
-  getpkt (buf, (rs->remote_packet_size), 0);
+  getpkt (buf, rs->remote_packet_size, 0);
 }
 \f
 /* Clean up connection to a remote debugger.  */
@@ -1953,8 +1954,7 @@ get_offsets (void)
   struct section_offsets *offs;
 
   putpkt ("qOffsets");
-
-  getpkt (buf, (rs->remote_packet_size), 0);
+  getpkt (buf, rs->remote_packet_size, 0);
 
   if (buf[0] == '\000')
     return;                    /* Return silently.  Stub doesn't support
@@ -2128,23 +2128,23 @@ remote_check_symbols (struct objfile *objfile)
   /* Invite target to request symbol lookups.  */
 
   putpkt ("qSymbol::");
-  getpkt (reply, (rs->remote_packet_size), 0);
+  getpkt (reply, rs->remote_packet_size, 0);
   packet_ok (reply, &remote_protocol_qSymbol);
 
   while (strncmp (reply, "qSymbol:", 8) == 0)
     {
       tmp = &reply[8];
-      end = hex2bin (tmp, msg, strlen (tmp) / 2);
+      end = hex2bin (tmp, (gdb_byte *) msg, strlen (tmp) / 2);
       msg[end] = '\0';
       sym = lookup_minimal_symbol (msg, NULL, NULL);
       if (sym == NULL)
-       sprintf (msg, "qSymbol::%s", &reply[8]);
+       xsnprintf (msg, rs->remote_packet_size, "qSymbol::%s", &reply[8]);
       else
-       sprintf (msg, "qSymbol:%s:%s",
-                paddr_nz (SYMBOL_VALUE_ADDRESS (sym)),
-                &reply[8]);
+       xsnprintf (msg, rs->remote_packet_size, "qSymbol:%s:%s",
+                  paddr_nz (SYMBOL_VALUE_ADDRESS (sym)),
+                  &reply[8]);
       putpkt (msg);
-      getpkt (reply, (rs->remote_packet_size), 0);
+      getpkt (reply, rs->remote_packet_size, 0);
     }
 }
 
@@ -2292,7 +2292,7 @@ remote_open_1 (char *name, int from_tty, struct target_ops *target,
       /* Tell the remote that we are using the extended protocol.  */
       char *buf = alloca (rs->remote_packet_size);
       putpkt ("!");
-      getpkt (buf, (rs->remote_packet_size), 0);
+      getpkt (buf, rs->remote_packet_size, 0);
     }
 
   /* FIXME: need a master target_open vector from which all
@@ -2331,7 +2331,7 @@ remote_detach (char *args, int from_tty)
 
   /* Tell the remote target to detach.  */
   strcpy (buf, "D");
-  remote_send (buf, (rs->remote_packet_size));
+  remote_send (buf, rs->remote_packet_size);
 
   /* Unregister the file descriptor from the event loop.  */
   if (target_is_async_p ())
@@ -2375,7 +2375,7 @@ fromhex (int a)
 }
 
 static int
-hex2bin (const char *hex, char *bin, int count)
+hex2bin (const char *hex, gdb_byte *bin, int count)
 {
   int i;
 
@@ -2405,12 +2405,12 @@ tohex (int nib)
 }
 
 static int
-bin2hex (const char *bin, char *hex, int count)
+bin2hex (const gdb_byte *bin, char *hex, int count)
 {
   int i;
   /* May use a length, or a nul-terminated string as input.  */
   if (count == 0)
-    count = strlen (bin);
+    count = strlen ((char *) bin);
 
   for (i = 0; i < count; i++)
     {
@@ -2830,7 +2830,7 @@ static ptid_t
 remote_wait (ptid_t ptid, struct target_waitstatus *status)
 {
   struct remote_state *rs = get_remote_state ();
-  unsigned char *buf = alloca (rs->remote_packet_size);
+  char *buf = alloca (rs->remote_packet_size);
   ULONGEST thread_num = -1;
   ULONGEST addr;
 
@@ -2839,10 +2839,10 @@ remote_wait (ptid_t ptid, struct target_waitstatus *status)
 
   while (1)
     {
-      unsigned char *p;
+      char *p;
 
       ofunc = signal (SIGINT, remote_interrupt);
-      getpkt (buf, (rs->remote_packet_size), 1);
+      getpkt (buf, rs->remote_packet_size, 1);
       signal (SIGINT, ofunc);
 
       /* This is a hook for when we need to do something (perhaps the
@@ -2862,7 +2862,7 @@ remote_wait (ptid_t ptid, struct target_waitstatus *status)
          continue;
        case 'T':               /* Status with PC, SP, FP, ...  */
          {
-           char regs[MAX_REGISTER_SIZE];
+           gdb_byte regs[MAX_REGISTER_SIZE];
 
            /* Expedited reply, containing Signal, {regno, reg} repeat.  */
            /*  format is:  'Tssn...:r...;n...:r...;n...:r...;#cc', where
@@ -2874,7 +2874,7 @@ remote_wait (ptid_t ptid, struct target_waitstatus *status)
 
            while (*p)
              {
-               unsigned char *p1;
+               char *p1;
                char *p_temp;
                int fieldsize;
                LONGEST pnum = 0;
@@ -2890,14 +2890,14 @@ remote_wait (ptid_t ptid, struct target_waitstatus *status)
                  {
                    /* Read the ``P'' register number.  */
                    pnum = strtol (p, &p_temp, 16);
-                   p1 = (unsigned char *) p_temp;
+                   p1 = p_temp;
                  }
                else
                  p1 = p;
 
                if (p1 == p)    /* No register number present here.  */
                  {
-                   p1 = (unsigned char *) strchr (p, ':');
+                   p1 = strchr (p, ':');
                    if (p1 == NULL)
                      warning (_("Malformed packet(a) (missing colon): %s\n\
 Packet: '%s'\n"),
@@ -2906,7 +2906,7 @@ Packet: '%s'\n"),
                      {
                        p_temp = unpack_varlen_hex (++p1, &thread_num);
                        record_currthread (thread_num);
-                       p = (unsigned char *) p_temp;
+                       p = p_temp;
                      }
                    else if ((strncmp (p, "watch", p1 - p) == 0)
                             || (strncmp (p, "rwatch", p1 - p) == 0)
@@ -2921,7 +2921,7 @@ Packet: '%s'\n"),
                        /* Silently skip unknown optional info.  */
                        p_temp = strchr (p1 + 1, ';');
                        if (p_temp)
-                         p = (unsigned char *) p_temp;
+                         p = p_temp;
                      }
                  }
                else
@@ -2939,7 +2939,7 @@ Packet: '%s'\n"),
 Packet: '%s'\n"),
                             phex_nz (pnum, 0), p, buf);
 
-                   fieldsize = hex2bin (p, regs, 
+                   fieldsize = hex2bin (p, regs,
                                         register_size (current_gdbarch, 
                                                        reg->regnum));
                    p += 2 * fieldsize;
@@ -3019,7 +3019,7 @@ static ptid_t
 remote_async_wait (ptid_t ptid, struct target_waitstatus *status)
 {
   struct remote_state *rs = get_remote_state ();
-  unsigned char *buf = alloca (rs->remote_packet_size);
+  char *buf = alloca (rs->remote_packet_size);
   ULONGEST thread_num = -1;
   ULONGEST addr;
 
@@ -3030,7 +3030,7 @@ remote_async_wait (ptid_t ptid, struct target_waitstatus *status)
 
   while (1)
     {
-      unsigned char *p;
+      char *p;
 
       if (!target_is_async_p ())
        ofunc = signal (SIGINT, remote_interrupt);
@@ -3038,7 +3038,7 @@ remote_async_wait (ptid_t ptid, struct target_waitstatus *status)
          _never_ wait for ever -> test on target_is_async_p().
          However, before we do that we need to ensure that the caller
          knows how to take the target into/out of async mode.  */
-      getpkt (buf, (rs->remote_packet_size), wait_forever_enabled_p);
+      getpkt (buf, rs->remote_packet_size, wait_forever_enabled_p);
       if (!target_is_async_p ())
        signal (SIGINT, ofunc);
 
@@ -3057,7 +3057,7 @@ remote_async_wait (ptid_t ptid, struct target_waitstatus *status)
          continue;
        case 'T':               /* Status with PC, SP, FP, ...  */
          {
-           char regs[MAX_REGISTER_SIZE];
+           gdb_byte regs[MAX_REGISTER_SIZE];
 
            /* Expedited reply, containing Signal, {regno, reg} repeat.  */
            /*  format is:  'Tssn...:r...;n...:r...;n...:r...;#cc', where
@@ -3069,7 +3069,7 @@ remote_async_wait (ptid_t ptid, struct target_waitstatus *status)
 
            while (*p)
              {
-               unsigned char *p1;
+               char *p1;
                char *p_temp;
                int fieldsize;
                long pnum = 0;
@@ -3085,14 +3085,14 @@ remote_async_wait (ptid_t ptid, struct target_waitstatus *status)
                  {
                    /* Read the register number.  */
                    pnum = strtol (p, &p_temp, 16);
-                   p1 = (unsigned char *) p_temp;
+                   p1 = p_temp;
                  }
                else
                  p1 = p;
 
                if (p1 == p)    /* No register number present here.  */
                  {
-                   p1 = (unsigned char *) strchr (p, ':');
+                   p1 = strchr (p, ':');
                    if (p1 == NULL)
                      error (_("Malformed packet(a) (missing colon): %s\n\
 Packet: '%s'\n"),
@@ -3101,7 +3101,7 @@ Packet: '%s'\n"),
                      {
                        p_temp = unpack_varlen_hex (++p1, &thread_num);
                        record_currthread (thread_num);
-                       p = (unsigned char *) p_temp;
+                       p = p_temp;
                      }
                    else if ((strncmp (p, "watch", p1 - p) == 0)
                             || (strncmp (p, "rwatch", p1 - p) == 0)
@@ -3114,7 +3114,7 @@ Packet: '%s'\n"),
                    else
                      {
                        /* Silently skip unknown optional info.  */
-                       p_temp = (unsigned char *) strchr (p1 + 1, ';');
+                       p_temp = strchr (p1 + 1, ';');
                        if (p_temp)
                          p = p_temp;
                      }
@@ -3134,7 +3134,7 @@ Packet: '%s'\n"),
 Packet: '%s'\n"),
                             pnum, p, buf);
 
-                   fieldsize = hex2bin (p, regs, 
+                   fieldsize = hex2bin (p, regs,
                                         register_size (current_gdbarch, 
                                                        reg->regnum));
                    p += 2 * fieldsize;
@@ -3310,7 +3310,7 @@ remote_fetch_registers (int regnum)
        }
 
   sprintf (buf, "g");
-  remote_send (buf, (rs->remote_packet_size));
+  remote_send (buf, rs->remote_packet_size);
 
   /* Save the size of the packet sent to us by the target.  Its used
      as a heuristic when determining the max size of packets that the
@@ -3332,7 +3332,7 @@ remote_fetch_registers (int regnum)
       if (remote_debug)
        fprintf_unfiltered (gdb_stdlog,
                            "Bad register packet; fetching a new packet\n");
-      getpkt (buf, (rs->remote_packet_size), 0);
+      getpkt (buf, rs->remote_packet_size, 0);
     }
 
   /* Reply describes registers byte by byte, each byte encoded as two
@@ -3405,7 +3405,7 @@ remote_prepare_to_store (void)
 {
   struct remote_state *rs = get_remote_state ();
   int i;
-  char buf[MAX_REGISTER_SIZE];
+  gdb_byte buf[MAX_REGISTER_SIZE];
 
   /* Make sure the entire registers array is valid.  */
   switch (remote_protocol_P.support)
@@ -3432,10 +3432,10 @@ store_register_using_P (int regnum)
   struct packet_reg *reg = packet_reg_from_regnum (rs, regnum);
   /* Try storing a single register.  */
   char *buf = alloca (rs->remote_packet_size);
-  char regp[MAX_REGISTER_SIZE];
+  gdb_byte regp[MAX_REGISTER_SIZE];
   char *p;
 
-  sprintf (buf, "P%s=", phex_nz (reg->pnum, 0));
+  xsnprintf (buf, rs->remote_packet_size, "P%s=", phex_nz (reg->pnum, 0));
   p = buf + strlen (buf);
   regcache_raw_collect (current_regcache, reg->regnum, regp);
   bin2hex (regp, p, register_size (current_gdbarch, reg->regnum));
@@ -3453,7 +3453,7 @@ remote_store_registers (int regnum)
 {
   struct remote_state *rs = get_remote_state ();
   char *buf;
-  char *regs;
+  gdb_byte *regs;
   char *p;
 
   set_thread (PIDGET (inferior_ptid), 1);
@@ -3508,7 +3508,7 @@ remote_store_registers (int regnum)
   *p++ = 'G';
   /* remote_prepare_to_store insures that register_bytes_found gets set.  */
   bin2hex (regs, p, register_bytes_found);
-  remote_send (buf, (rs->remote_packet_size));
+  remote_send (buf, rs->remote_packet_size);
 }
 \f
 
@@ -3585,6 +3585,7 @@ static void
 check_binary_download (CORE_ADDR addr)
 {
   struct remote_state *rs = get_remote_state ();
+
   switch (remote_protocol_binary_download.support)
     {
     case PACKET_DISABLE:
@@ -3605,7 +3606,7 @@ check_binary_download (CORE_ADDR addr)
        *p = '\0';
 
        putpkt_binary (buf, (int) (p - buf));
-       getpkt (buf, (rs->remote_packet_size), 0);
+       getpkt (buf, rs->remote_packet_size, 0);
 
        if (buf[0] == '\0')
          {
@@ -3636,17 +3637,17 @@ check_binary_download (CORE_ADDR addr)
    error.  Only transfer a single packet.  */
 
 int
-remote_write_bytes (CORE_ADDR memaddr, char *myaddr, int len)
+remote_write_bytes (CORE_ADDR memaddr, gdb_byte *myaddr, int len)
 {
-  unsigned char *buf;
-  unsigned char *p;
-  unsigned char *plen;
+  char *buf;
+  char *p;
+  char *plen;
   long sizeof_buf;
   int plenlen;
   int todo;
   int nr_bytes;
   int payload_size;
-  unsigned char *payload_start;
+  char *payload_start;
 
   /* Verify that the target can support a binary download.  */
   check_binary_download (memaddr);
@@ -3796,7 +3797,7 @@ remote_write_bytes (CORE_ADDR memaddr, char *myaddr, int len)
    handling partial reads.  */
 
 int
-remote_read_bytes (CORE_ADDR memaddr, char *myaddr, int len)
+remote_read_bytes (CORE_ADDR memaddr, gdb_byte *myaddr, int len)
 {
   char *buf;
   int max_buf_size;            /* Max size of packet output buffer.  */
@@ -3960,7 +3961,7 @@ putpkt (char *buf)
 
 /* Send a packet to the remote machine, with error checking.  The data
    of the packet is in BUF.  The string in BUF can be at most
-   (rs->remote_packet_size) - 5 to account for the $, # and checksum,
+   RS->remote_packet_size - 5 to account for the $, # and checksum,
    and for a possible /0 if we are debugging (remote_debug) and want
    to print the sent packet as a string.  */
 
@@ -3971,7 +3972,7 @@ putpkt_binary (char *buf, int cnt)
   int i;
   unsigned char csum = 0;
   char *buf2 = alloca (cnt + 6);
-  long sizeof_junkbuf = (rs->remote_packet_size);
+  long sizeof_junkbuf = rs->remote_packet_size;
   char *junkbuf = alloca (sizeof_junkbuf);
 
   int ch;
@@ -4521,7 +4522,7 @@ remote_insert_breakpoint (CORE_ADDR addr, bfd_byte *contents_cache)
       sprintf (p, ",%d", bp_size);
 
       putpkt (buf);
-      getpkt (buf, (rs->remote_packet_size), 0);
+      getpkt (buf, rs->remote_packet_size, 0);
 
       switch (packet_ok (buf, &remote_protocol_Z[Z_PACKET_SOFTWARE_BP]))
        {
@@ -4574,7 +4575,7 @@ remote_remove_breakpoint (CORE_ADDR addr, bfd_byte *contents_cache)
       sprintf (p, ",%d", bp_size);
 
       putpkt (buf);
-      getpkt (buf, (rs->remote_packet_size), 0);
+      getpkt (buf, rs->remote_packet_size, 0);
 
       return (buf[0] == 'E');
     }
@@ -4626,7 +4627,7 @@ remote_insert_watchpoint (CORE_ADDR addr, int len, int type)
   sprintf (p, ",%x", len);
 
   putpkt (buf);
-  getpkt (buf, (rs->remote_packet_size), 0);
+  getpkt (buf, rs->remote_packet_size, 0);
 
   switch (packet_ok (buf, &remote_protocol_Z[packet]))
     {
@@ -4660,7 +4661,7 @@ remote_remove_watchpoint (CORE_ADDR addr, int len, int type)
   p += hexnumstr (p, (ULONGEST) addr);
   sprintf (p, ",%x", len);
   putpkt (buf);
-  getpkt (buf, (rs->remote_packet_size), 0);
+  getpkt (buf, rs->remote_packet_size, 0);
 
   switch (packet_ok (buf, &remote_protocol_Z[packet]))
     {
@@ -4754,7 +4755,7 @@ remote_insert_hw_breakpoint (CORE_ADDR addr, gdb_byte *shadow)
   sprintf (p, ",%x", len);
 
   putpkt (buf);
-  getpkt (buf, (rs->remote_packet_size), 0);
+  getpkt (buf, rs->remote_packet_size, 0);
 
   switch (packet_ok (buf, &remote_protocol_Z[Z_PACKET_HARDWARE_BP]))
     {
@@ -4796,7 +4797,7 @@ remote_remove_hw_breakpoint (CORE_ADDR addr, gdb_byte *shadow)
   sprintf (p, ",%x", len);
 
   putpkt(buf);
-  getpkt (buf, (rs->remote_packet_size), 0);
+  getpkt (buf, rs->remote_packet_size, 0);
 
   switch (packet_ok (buf, &remote_protocol_Z[Z_PACKET_HARDWARE_BP]))
     {
@@ -4908,7 +4909,8 @@ compare_sections_command (char *args, int from_tty)
       matched = 1;             /* do this section */
       lma = s->lma;
       /* FIXME: assumes lma can fit into long.  */
-      sprintf (buf, "qCRC:%lx,%lx", (long) lma, (long) size);
+      xsnprintf (buf, rs->remote_packet_size, "qCRC:%lx,%lx", 
+                (long) lma, (long) size);
       putpkt (buf);
 
       /* Be clever; compute the host_crc before waiting for target
@@ -4918,7 +4920,7 @@ compare_sections_command (char *args, int from_tty)
       bfd_get_section_contents (exec_bfd, s, sectdata, 0, size);
       host_crc = crc32 ((unsigned char *) sectdata, size, 0xffffffff);
 
-      getpkt (buf, (rs->remote_packet_size), 0);
+      getpkt (buf, rs->remote_packet_size, 0);
       if (buf[0] == 'E')
        error (_("target memory fault, section %s, range 0x%s -- 0x%s"),
               sectname, paddr (lma), paddr (lma + size));
@@ -5040,9 +5042,9 @@ remote_xfer_partial (struct target_ops *ops, enum target_object object,
      buffer size.  */
   if (offset == 0 && len == 0)
     return (rs->remote_packet_size);
-  /* Minimum outbuf size is (rs->remote_packet_size) - if bufsiz is
-     not large enough let the caller.  */
-  if (len < (rs->remote_packet_size))
+  /* Minimum outbuf size is RS->remote_packet_size. If LEN is not
+     large enough let the caller deal with it.  */
+  if (len < rs->remote_packet_size)
     return -1;
   len = rs->remote_packet_size;
 
@@ -5062,7 +5064,7 @@ remote_xfer_partial (struct target_ops *ops, enum target_object object,
      (remote_debug), we have PBUFZIZ - 7 left to pack the query
      string.  */
   i = 0;
-  while (annex[i] && (i < ((rs->remote_packet_size) - 8)))
+  while (annex[i] && (i < (rs->remote_packet_size - 8)))
     {
       /* Bad caller may have sent forbidden characters.  */
       gdb_assert (isprint (annex[i]) && annex[i] != '$' && annex[i] != '#');
@@ -5076,9 +5078,9 @@ remote_xfer_partial (struct target_ops *ops, enum target_object object,
   if (i < 0)
     return i;
 
-  getpkt (readbuf, len, 0);
+  getpkt ((char *) readbuf, len, 0);
 
-  return strlen (readbuf);
+  return strlen ((char *) readbuf);
 }
 
 static void
@@ -5100,11 +5102,11 @@ remote_rcmd (char *command,
   strcpy (buf, "qRcmd,");
   p = strchr (buf, '\0');
 
-  if ((strlen (buf) + strlen (command) * 2 + 8/*misc*/) > (rs->remote_packet_size))
+  if ((strlen (buf) + strlen (command) * 2 + 8/*misc*/) > rs->remote_packet_size)
     error (_("\"monitor\" command ``%s'' is too long."), command);
 
   /* Encode the actual command.  */
-  bin2hex (command, p, 0);
+  bin2hex ((gdb_byte *) command, p, 0);
 
   if (putpkt (buf) < 0)
     error (_("Communication problem with target."));
@@ -5114,7 +5116,7 @@ remote_rcmd (char *command,
     {
       /* XXX - see also tracepoint.c:remote_get_noisy_reply().  */
       buf[0] = '\0';
-      getpkt (buf, (rs->remote_packet_size), 0);
+      getpkt (buf, rs->remote_packet_size, 0);
       if (buf[0] == '\0')
        error (_("Target does not support this command."));
       if (buf[0] == 'O' && buf[1] != 'K')
@@ -5155,7 +5157,7 @@ packet_command (char *args, int from_tty)
   puts_filtered ("\n");
   putpkt (args);
 
-  getpkt (buf, (rs->remote_packet_size), 0);
+  getpkt (buf, rs->remote_packet_size, 0);
   puts_filtered ("received: ");
   print_packet (buf);
   puts_filtered ("\n");
@@ -5313,10 +5315,8 @@ static char *
 remote_pid_to_str (ptid_t ptid)
 {
   static char buf[32];
-  int size;
 
-  size = snprintf (buf, sizeof buf, "thread %d", ptid_get_pid (ptid));
-  gdb_assert (size < sizeof buf);
+  xsnprintf (buf, sizeof buf, "thread %d", ptid_get_pid (ptid));
   return buf;
 }
 
This page took 0.036921 seconds and 4 git commands to generate.