/* Remote target communications for serial-line targets in custom GDB protocol
 
    Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996,
-   1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
+   1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006
    Free Software Foundation, Inc.
 
    This file is part of GDB.
 
 \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).  */
     }
   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)
   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;
 }
 
   else
     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
   int mask, length;
   unsigned int tag;
   threadref ref;
-  char *limit = pkt + (rs->remote_packet_size);        /* plausible parsing limit */
+  char *limit = pkt + rs->remote_packet_size; /* Plausible parsing limit.  */
   int retval = 1;
 
   /* info->threadid = 0; FIXME: implement zero_threadref.  */
 
   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;
 
   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);
   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,
   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
     {
       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 */
              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 */
        }
       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));
       }
   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)
   /* 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.  */
   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
   /* 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)
                   paddr_nz (SYMBOL_VALUE_ADDRESS (sym)),
                   &reply[8]);
       putpkt (msg);
-      getpkt (reply, (rs->remote_packet_size), 0);
+      getpkt (reply, rs->remote_packet_size, 0);
     }
 }
 
       /* 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
 
   /* 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 ())
       unsigned 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
          _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);
 
        }
 
   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
       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
   *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
 
 check_binary_download (CORE_ADDR addr)
 {
   struct remote_state *rs = get_remote_state ();
+
   switch (remote_protocol_binary_download.support)
     {
     case PACKET_DISABLE:
        *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')
          {
 
 /* 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.  */
 
   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;
       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]))
        {
       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');
     }
   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]))
     {
   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]))
     {
   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]))
     {
   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]))
     {
       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));
      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;
 
      (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] != '#');
   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.  */
     {
       /* 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')
   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");