Replace ../include/wait.h with gdb_wait.h.
[deliverable/binutils-gdb.git] / gdb / remote.c
index e63813628a37dfcc15f079cb67b113c1db67d203..8411f2f722d4b41f72a4b8daa8a1a0813ada6824 100644 (file)
@@ -1,6 +1,5 @@
 /* Remote target communications for serial-line targets in custom GDB protocol
-   Copyright 1988, 91, 92, 93, 94, 95, 96, 97, 98, 1999 
-   Free Software Foundation, Inc.
+   Copyright 1988, 1991-2000 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -30,7 +29,7 @@
 #include "bfd.h"
 #include "symfile.h"
 #include "target.h"
-#include "wait.h"
+#include "gdb_wait.h"
 /*#include "terminal.h" */
 #include "gdbcmd.h"
 #include "objfiles.h"
@@ -56,6 +55,7 @@
 /* Prototypes for local functions */
 static void cleanup_sigint_signal_handler (void *dummy);
 static void initialize_sigint_signal_handler (void);
+static int getpkt_sane (char *buf, long sizeof_buf, int forever);
 
 static void handle_remote_sigint PARAMS ((int));
 static void handle_remote_sigint_twice PARAMS ((int));
@@ -112,7 +112,7 @@ static void extended_remote_async_create_inferior PARAMS ((char *, char *, char
 
 static void remote_mourn_1 PARAMS ((struct target_ops *));
 
-static void remote_send PARAMS ((char *buf));
+static void remote_send (char *buf, long sizeof_buf);
 
 static int readchar PARAMS ((int timeout));
 
@@ -139,7 +139,7 @@ static int remote_thread_alive PARAMS ((int));
 
 static void get_offsets PARAMS ((void));
 
-static int read_frame PARAMS ((char *));
+static long read_frame (char *buf, long sizeof_buf);
 
 static int remote_insert_breakpoint PARAMS ((CORE_ADDR, char *));
 
@@ -245,15 +245,6 @@ static struct target_ops remote_async_ops;
 
 static struct target_ops extended_async_remote_ops;
 
-/* This was 5 seconds, which is a long time to sit and wait.
-   Unless this is going though some terminal server or multiplexer or
-   other form of hairy serial connection, I would think 2 seconds would
-   be plenty.  */
-
-/* Changed to allow option to set timeout value.
-   was static int remote_timeout = 2; */
-extern int remote_timeout;
-
 /* FIXME: cagney/1999-09-23: Even though getpkt was called with
    ``forever'' still use the normal timeout mechanism.  This is
    currently used by the ASYNC code to guarentee that target reads
@@ -497,9 +488,14 @@ register_remote_packet_sizes (void)
 static void
 build_remote_packet_sizes (void)
 {
-  /* Maximum number of characters in a packet. This default m68k-stub.c and
-     i386-stub.c stubs. */
-  remote_packet_size = 400;
+  /* Default maximum number of characters in a packet body. Many
+     remote stubs have a hardwired buffer size of 400 bytes
+     (c.f. BUFMAX in m68k-stub.c and i386-stub.c).  BUFMAX-1 is used
+     as the maximum packet-size to ensure that the packet and an extra
+     NUL character can always fit in the buffer.  This stops GDB
+     trashing stubs that try to squeeze an extra NUL into what is
+     already a full buffer (As of 1999-12-04 that was most stubs. */
+  remote_packet_size = 400 - 1;
   /* Should REGISTER_BYTES needs more space than the default, adjust
      the size accordingly. Remember that each byte is encoded as two
      characters. 32 is the overhead for the packet header /
@@ -753,7 +749,13 @@ record_currthread (currthread)
   if (!in_thread_list (currthread))
     {
       add_thread (currthread);
+#ifdef UI_OUT
+      ui_out_text (uiout, "[New ");
+      ui_out_text (uiout, target_pid_to_str (currthread));
+      ui_out_text (uiout, "]\n");
+#else
       printf_filtered ("[New %s]\n", target_pid_to_str (currthread));
+#endif
     }
 }
 
@@ -782,7 +784,7 @@ set_thread (th, gen)
   else
     sprintf (&buf[2], "%x", th);
   putpkt (buf);
-  getpkt (buf, 0);
+  getpkt (buf, PBUFSIZ, 0);
   if (gen)
     general_thread = th;
   else
@@ -802,7 +804,7 @@ remote_thread_alive (tid)
   else
     sprintf (buf, "T%08x", tid);
   putpkt (buf);
-  getpkt (buf, 0);
+  getpkt (buf, sizeof (buf), 0);
   return (buf[0] == 'O' && buf[1] == 'K');
 }
 
@@ -1342,7 +1344,7 @@ remote_get_threadinfo (threadid, fieldset, info)
 
   pack_threadinfo_request (threadinfo_pkt, fieldset, threadid);
   putpkt (threadinfo_pkt);
-  getpkt (threadinfo_pkt, 0);
+  getpkt (threadinfo_pkt, PBUFSIZ, 0);
   result = remote_unpack_thread_info_response (threadinfo_pkt + 2, threadid,
                                               info);
   return result;
@@ -1436,7 +1438,7 @@ remote_get_threadlist (startflag, nextthread, result_limit,
   pack_threadlist_request (threadlist_packet,
                           startflag, result_limit, nextthread);
   putpkt (threadlist_packet);
-  getpkt (t_response, 0);
+  getpkt (t_response, PBUFSIZ, 0);
 
   *result_count =
     parse_threadlist_response (t_response + 2, result_limit, &echo_nextthread,
@@ -1549,7 +1551,7 @@ remote_current_thread (oldpid)
   char *buf = alloca (PBUFSIZ);
 
   putpkt ("qC");
-  getpkt (buf, 0);
+  getpkt (buf, PBUFSIZ, 0);
   if (buf[0] == 'Q' && buf[1] == 'C')
     return strtol (&buf[2], NULL, 16);
   else
@@ -1578,7 +1580,8 @@ remote_threads_info (void)
     error ("Command can only be used when connected to the remote target.");
 
   putpkt ("qfThreadInfo");
-  getpkt (bufp = buf, 0);
+  bufp = buf;
+  getpkt (bufp, PBUFSIZ, 0);
   if (bufp[0] == '\0')         /* q packet not recognized! */
     {                          /* try old jmetzler method  */
       remote_find_new_threads ();
@@ -1595,7 +1598,8 @@ remote_threads_info (void)
          }
        while (*bufp++ == ','); /* comma-separated list */
        putpkt ("qsThreadInfo");
-       getpkt (bufp = buf, 0);
+       bufp = buf;
+       getpkt (bufp, PBUFSIZ, 0);
       }
 }
 \f
@@ -1616,7 +1620,7 @@ extended_remote_restart ()
   /* Now query for status so this looks just like we restarted
      gdbserver from scratch.  */
   putpkt ("?");
-  getpkt (buf, 0);
+  getpkt (buf, PBUFSIZ, 0);
 }
 \f
 /* Clean up connection to a remote debugger.  */
@@ -1644,7 +1648,7 @@ get_offsets ()
 
   putpkt ("qOffsets");
 
-  getpkt (buf, 0);
+  getpkt (buf, PBUFSIZ, 0);
 
   if (buf[0] == '\000')
     return;                    /* Return silently.  Stub doesn't support
@@ -1728,14 +1732,12 @@ get_offsets ()
  */
 
 static int
-remote_cisco_section_offsets (text_addr, data_addr, bss_addr,
-                             text_offs, data_offs, bss_offs)
-     bfd_vma text_addr;
-     bfd_vma data_addr;
-     bfd_vma bss_addr;
-     bfd_signed_vma *text_offs;
-     bfd_signed_vma *data_offs;
-     bfd_signed_vma *bss_offs;
+remote_cisco_section_offsets (bfd_vma text_addr,
+                             bfd_vma data_addr,
+                             bfd_vma bss_addr,
+                             bfd_signed_vma *text_offs,
+                             bfd_signed_vma *data_offs,
+                             bfd_signed_vma *bss_offs)
 {
   bfd_vma text_base, data_base, bss_base;
   struct minimal_symbol *start;
@@ -1835,8 +1837,7 @@ remote_cisco_objfile_relocate (text_off, data_off, bss_off)
 /* Stub for catch_errors.  */
 
 static int
-remote_start_remote_dummy (dummy)
-     char *dummy;
+remote_start_remote_dummy (void *dummy)
 {
   start_remote ();             /* Initialize gdb process mechanisms */
   return 1;
@@ -1917,7 +1918,8 @@ remote_open_1 (name, from_tty, target, extended_p)
 {
   if (name == 0)
     error ("To open a remote debug connection, you need to specify what\n\
-serial device is attached to the remote system (e.g. /dev/ttya).");
+serial device is attached to the remote system\n\
+(e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).");
 
   /* See FIXME above */
   wait_forever_enabled_p = 1;
@@ -1989,7 +1991,7 @@ serial device is attached to the remote system (e.g. /dev/ttya).");
       /* tell the remote that we're using the extended protocol.  */
       char *buf = alloca (PBUFSIZ);
       putpkt ("!");
-      getpkt (buf, 0);
+      getpkt (buf, PBUFSIZ, 0);
     }
 }
 
@@ -2003,7 +2005,8 @@ remote_async_open_1 (name, from_tty, target, extended_p)
 {
   if (name == 0)
     error ("To open a remote debug connection, you need to specify what\n\
-serial device is attached to the remote system (e.g. /dev/ttya).");
+serial device is attached to the remote system\n\
+(e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).");
 
   target_preopen (from_tty);
 
@@ -2088,7 +2091,7 @@ serial device is attached to the remote system (e.g. /dev/ttya).");
       /* tell the remote that we're using the extended protocol.  */
       char *buf = alloca (PBUFSIZ);
       putpkt ("!");
-      getpkt (buf, 0);
+      getpkt (buf, PBUFSIZ, 0);
     }
 }
 
@@ -2109,7 +2112,7 @@ remote_detach (args, from_tty)
 
   /* Tell the remote target to detach.  */
   strcpy (buf, "D");
-  remote_send (buf);
+  remote_send (buf, PBUFSIZ);
 
   pop_target ();
   if (from_tty)
@@ -2130,10 +2133,10 @@ remote_async_detach (args, from_tty)
 
   /* Tell the remote target to detach.  */
   strcpy (buf, "D");
-  remote_send (buf);
+  remote_send (buf, PBUFSIZ);
 
   /* Unregister the file descriptor from the event loop. */
-  if (SERIAL_IS_ASYNC_P (remote_desc))
+  if (target_is_async_p ())
     SERIAL_ASYNC (remote_desc, NULL, 0);
 
   pop_target ();
@@ -2250,14 +2253,14 @@ remote_async_resume (pid, step, siggnal)
   /* FIXME: ezannoni 1999-09-28: We may need to move this out of here
      into infcmd.c in order to allow inferior function calls to work
      NOT asynchronously. */
-  if (event_loop_p && SERIAL_CAN_ASYNC_P (remote_desc))
+  if (event_loop_p && target_can_async_p ())
     target_async (inferior_event_handler, 0);
   /* Tell the world that the target is now executing. */
   /* FIXME: cagney/1999-09-23: Is it the targets responsibility to set
      this?  Instead, should the client of target just assume (for
      async targets) that the target is going to start executing?  Is
      this information already found in the continuation block?  */
-  if (SERIAL_IS_ASYNC_P (remote_desc))
+  if (target_is_async_p ())
     target_executing = 1;
   putpkt (buf);
 }
@@ -2490,7 +2493,7 @@ remote_wait (pid, status)
       unsigned char *p;
 
       ofunc = signal (SIGINT, remote_interrupt);
-      getpkt ((char *) buf, 1);
+      getpkt (buf, PBUFSIZ, 1);
       signal (SIGINT, ofunc);
 
       /* This is a hook for when we need to do something (perhaps the
@@ -2706,14 +2709,14 @@ remote_async_wait (pid, status)
     {
       unsigned char *p;
 
-      if (!SERIAL_IS_ASYNC_P (remote_desc))
+      if (!target_is_async_p ())
        ofunc = signal (SIGINT, remote_interrupt);
       /* FIXME: cagney/1999-09-27: If we're in async mode we should
          _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 ((char *) buf, wait_forever_enabled_p);
-      if (!SERIAL_IS_ASYNC_P (remote_desc))
+      getpkt (buf, PBUFSIZ, wait_forever_enabled_p);
+      if (!target_is_async_p ())
        signal (SIGINT, ofunc);
 
       /* This is a hook for when we need to do something (perhaps the
@@ -2882,7 +2885,10 @@ Packet Dropped");
          goto got_status;
        case 'O':               /* Console output */
          remote_console_output (buf + 1);
-         continue;
+         /* Return immediately to the event loop. The event loop will
+             still be waiting on the inferior afterwards. */
+          status->kind = TARGET_WAITKIND_IGNORE;
+          goto got_status;
        case '\0':
          if (last_sent_signal != TARGET_SIGNAL_0)
            {
@@ -2933,7 +2939,7 @@ remote_fetch_registers (regno)
   set_thread (inferior_pid, 1);
 
   sprintf (buf, "g");
-  remote_send (buf);
+  remote_send (buf, PBUFSIZ);
 
   /* 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
@@ -2954,7 +2960,7 @@ remote_fetch_registers (regno)
       if (remote_debug)
        fprintf_unfiltered (gdb_stdlog,
                            "Bad register packet; fetching a new packet\n");
-      getpkt (buf, 0);
+      getpkt (buf, PBUFSIZ, 0);
     }
 
   /* Reply describes registers byte by byte, each byte encoded as two
@@ -3021,8 +3027,7 @@ remote_prepare_to_store ()
    packet was not recognized. */
 
 static int
-store_register_using_P (regno)
-     int regno;
+store_register_using_P (int regno)
 {
   /* Try storing a single register.  */
   char *buf = alloca (PBUFSIZ);
@@ -3039,7 +3044,7 @@ store_register_using_P (regno)
       *p++ = tohex (regp[i] & 0xf);
     }
   *p = '\0';
-  remote_send (buf);
+  remote_send (buf, PBUFSIZ);
 
   return buf[0] != '\0';
 }
@@ -3101,7 +3106,7 @@ remote_store_registers (regno)
     }
   *p = '\0';
 
-  remote_send (buf);
+  remote_send (buf, PBUFSIZ);
 }
 
 /* Use of the data cache *used* to be disabled because it loses for looking
@@ -3239,7 +3244,7 @@ check_binary_download (addr)
        *p = '\0';
        
        putpkt_binary (buf, (int) (p - buf));
-       getpkt (buf, 0);
+       getpkt (buf, PBUFSIZ, 0);
 
        if (buf[0] == '\0')
          {
@@ -3276,6 +3281,7 @@ remote_write_bytes (CORE_ADDR memaddr, char *myaddr, int len)
   int max_buf_size;            /* Max size of packet output buffer */
   unsigned char *p;
   unsigned char *plen;
+  long sizeof_buf;
   int plenlen;
   int todo;
   int nr_bytes;
@@ -3285,7 +3291,8 @@ remote_write_bytes (CORE_ADDR memaddr, char *myaddr, int len)
 
   /* Determine the max packet size. */
   max_buf_size = get_memory_write_packet_size ();
-  buf = alloca (max_buf_size + 1);
+  sizeof_buf = max_buf_size + 1; /* Space for trailing NUL */
+  buf = alloca (sizeof_buf);
 
   /* Subtract header overhead from max payload size -  $M<memaddr>,<len>:#nn */
   max_buf_size -= 2 + hexnumlen (memaddr + len - 1) + 1 + hexnumlen (len) + 4;
@@ -3377,7 +3384,7 @@ remote_write_bytes (CORE_ADDR memaddr, char *myaddr, int len)
     }
   
   putpkt_binary (buf, (int) (p - buf));
-  getpkt (buf, 0);
+  getpkt (buf, sizeof_buf, 0);
   
   if (buf[0] == 'E')
     {
@@ -3417,11 +3424,13 @@ remote_read_bytes (memaddr, myaddr, len)
 {
   char *buf;
   int max_buf_size;            /* Max size of packet output buffer */
+  long sizeof_buf;
   int origlen;
 
   /* Create a buffer big enough for this packet. */
   max_buf_size = get_memory_read_packet_size ();
-  buf = alloca (max_buf_size);
+  sizeof_buf = max_buf_size + 1; /* Space for trailing NUL */
+  buf = alloca (sizeof_buf);
 
   origlen = len;
   while (len > 0)
@@ -3443,7 +3452,7 @@ remote_read_bytes (memaddr, myaddr, len)
       *p = '\0';
 
       putpkt (buf);
-      getpkt (buf, 0);
+      getpkt (buf, sizeof_buf, 0);
 
       if (buf[0] == 'E')
        {
@@ -3534,7 +3543,7 @@ remote_search (len, data, mask, startaddr, increment, lorange, hirange
       data_long = extract_unsigned_integer (data, len);
       sprintf (buf, "t%x:%x,%x", startaddr, data_long, mask_long);
       putpkt (buf);
-      getpkt (buf, 0);
+      getpkt (buf, PBUFSIZ, 0);
       if (buf[0] == '\0')
        {
          /* The stub doesn't support the 't' request.  We might want to
@@ -3621,11 +3630,11 @@ readchar (timeout)
    into BUF.  Report an error if we get an error reply.  */
 
 static void
-remote_send (buf)
-     char *buf;
+remote_send (char *buf,
+            long sizeof_buf)
 {
   putpkt (buf);
-  getpkt (buf, 0);
+  getpkt (buf, sizeof_buf, 0);
 
   if (buf[0] == 'E')
     error ("Remote failure reply: %s", buf);
@@ -3663,7 +3672,8 @@ putpkt_binary (buf, cnt)
   int i;
   unsigned char csum = 0;
   char *buf2 = alloca (cnt + 6);
-  char *junkbuf = alloca (PBUFSIZ);
+  long sizeof_junkbuf = PBUFSIZ;
+  char *junkbuf = alloca (sizeof_junkbuf);
 
   int ch;
   int tcount = 0;
@@ -3711,6 +3721,7 @@ putpkt_binary (buf, cnt)
              switch (ch)
                {
                case '+':
+               case '-':
                case SERIAL_TIMEOUT:
                case '$':
                  if (started_error_output)
@@ -3727,6 +3738,9 @@ putpkt_binary (buf, cnt)
              if (remote_debug)
                fprintf_unfiltered (gdb_stdlog, "Ack\n");
              return 1;
+           case '-':
+             if (remote_debug)
+               fprintf_unfiltered (gdb_stdlog, "Nak\n");
            case SERIAL_TIMEOUT:
              tcount++;
              if (tcount > 3)
@@ -3736,7 +3750,7 @@ putpkt_binary (buf, cnt)
              {
                /* It's probably an old response, and we're out of sync.
                   Just gobble up the packet and ignore it.  */
-               getpkt (junkbuf, 0);
+               getpkt (junkbuf, sizeof_junkbuf, 0);
                continue;       /* Now, go look for + */
              }
            default:
@@ -3773,45 +3787,50 @@ static int remote_cisco_mode;
 
 /* Come here after finding the start of the frame.  Collect the rest
    into BUF, verifying the checksum, length, and handling run-length
-   compression.  Returns 0 on any error, 1 on success.  */
+   compression.  No more than sizeof_buf-1 characters are read so that
+   the buffer can be NUL terminated.
 
-static int
-read_frame (buf)
-     char *buf;
+   Returns -1 on error, number of characters in buffer (ignoring the
+   trailing NULL) on success. (could be extended to return one of the
+   SERIAL status indications). */
+
+static long
+read_frame (char *buf,
+           long sizeof_buf)
 {
   unsigned char csum;
-  char *bp;
+  long bc;
   int c;
 
   csum = 0;
-  bp = buf;
+  bc = 0;
 
   while (1)
     {
+      /* ASSERT (bc < sizeof_buf - 1) - space for trailing NUL */
       c = readchar (remote_timeout);
-
       switch (c)
        {
        case SERIAL_TIMEOUT:
          if (remote_debug)
            fputs_filtered ("Timeout in mid-packet, retrying\n", gdb_stdlog);
-         return 0;
+         return -1;
        case '$':
          if (remote_debug)
            fputs_filtered ("Saw new packet start in middle of old one\n",
                            gdb_stdlog);
-         return 0;             /* Start a new packet, count retries */
+         return -1;            /* Start a new packet, count retries */
        case '#':
          {
            unsigned char pktcsum;
 
-           *bp = '\000';
+           buf[bc] = '\0';
 
            pktcsum = fromhex (readchar (remote_timeout)) << 4;
            pktcsum |= fromhex (readchar (remote_timeout));
 
            if (csum == pktcsum)
-              return 1;
+              return bc;
 
            if (remote_debug)
              {
@@ -3821,7 +3840,9 @@ read_frame (buf)
                fputs_filtered (buf, gdb_stdlog);
                fputs_filtered ("\n", gdb_stdlog);
              }
-           return 0;
+           /* Number of characters in buffer ignoring trailing
+               NUL. */
+           return -1;
          }
        case '*':               /* Run length encoding */
           {
@@ -3847,47 +3868,70 @@ read_frame (buf)
                repeat += fromhex (c);
              }
 
+           /* The character before ``*'' is repeated. */
+
            if (repeat > 0 && repeat <= 255 
-                && bp + repeat - 1 < buf + PBUFSIZ - 1)
+               && bc > 0
+                && bc + repeat < sizeof_buf - 1)
              {
-               memset (bp, *(bp - 1), repeat);
-               bp += c;
+               memset (&buf[bc], buf[bc - 1], repeat);
+               bc += repeat;
                continue;
              }
 
-           *bp = '\0';
+           buf[bc] = '\0';
            printf_filtered ("Repeat count %d too large for buffer: ", repeat);
            puts_filtered (buf);
            puts_filtered ("\n");
-           return 0;
+           return -1;
          }
        default:
-         if (bp < buf + PBUFSIZ - 1)
+         if (bc < sizeof_buf - 1)
            {
-             *bp++ = c;
+             buf[bc++] = c;
              csum += c;
              continue;
            }
 
-         *bp = '\0';
+         buf[bc] = '\0';
          puts_filtered ("Remote packet too long: ");
          puts_filtered (buf);
          puts_filtered ("\n");
 
-         return 0;
+         return -1;
        }
     }
 }
 
 /* Read a packet from the remote machine, with error checking, and
-   store it in BUF.  BUF is expected to be of size PBUFSIZ.  If
-   FOREVER, wait forever rather than timing out; this is used while
-   the target is executing user code.  */
-
+   store it in BUF.  If FOREVER, wait forever rather than timing out;
+   this is used (in synchronous mode) to wait for a target that is is
+   executing user code to stop.  */
+/* FIXME: ezannoni 2000-02-01 this wrapper is necessary so that we
+   don't have to change all the calls to getpkt to deal with the
+   return value, because at the moment I don't know what the right
+   thing to do it for those. */
 void
-getpkt (buf, forever)
-     char *buf;
-     int forever;
+getpkt (char *buf,
+       long sizeof_buf,
+       int forever)
+{
+  int timed_out;
+
+  timed_out = getpkt_sane (buf, sizeof_buf, forever);
+}
+
+
+/* Read a packet from the remote machine, with error checking, and
+   store it in BUF.  If FOREVER, wait forever rather than timing out;
+   this is used (in synchronous mode) to wait for a target that is is
+   executing user code to stop. If FOREVER == 0, this function is
+   allowed to time out gracefully and return an indication of this to
+   the caller. */
+int
+getpkt_sane (char *buf,
+       long sizeof_buf,
+       int forever)
 {
   int c;
   int tries;
@@ -3937,9 +3981,9 @@ getpkt (buf, forever)
 
       /* We've found the start of a packet, now collect the data.  */
 
-      val = read_frame (buf);
+      val = read_frame (buf, sizeof_buf);
 
-      if (val == 1)
+      if (val >= 0)
        {
          if (remote_debug)
            {
@@ -3948,7 +3992,7 @@ getpkt (buf, forever)
              fprintf_unfiltered (gdb_stdlog, "\n");
            }
          SERIAL_WRITE (remote_desc, "+", 1);
-         return;
+         return 0;
        }
 
       /* Try the whole thing again.  */
@@ -3960,6 +4004,7 @@ getpkt (buf, forever)
 
   printf_unfiltered ("Ignoring packet error, continuing...\n");
   SERIAL_WRITE (remote_desc, "+", 1);
+  return 1;
 }
 \f
 static void
@@ -3988,7 +4033,7 @@ static void
 remote_async_kill ()
 {
   /* Unregister the file descriptor from the event loop. */
-  if (SERIAL_IS_ASYNC_P (remote_desc))
+  if (target_is_async_p ())
     SERIAL_ASYNC (remote_desc, NULL, 0);
 
   /* For some mysterious reason, wait_for_inferior calls kill instead of
@@ -4171,7 +4216,7 @@ remote_insert_breakpoint (addr, contents_cache)
       sprintf (p, ",%d", bp_size);
       
       putpkt (buf);
-      getpkt (buf, 0);
+      getpkt (buf, PBUFSIZ, 0);
 
       if (buf[0] != '\0')
        {
@@ -4236,7 +4281,7 @@ remote_remove_breakpoint (addr, contents_cache)
       sprintf (p, ",%d", bp_size);
       
       putpkt (buf);
-      getpkt (buf, 0);
+      getpkt (buf, PBUFSIZ, 0);
 
       return (buf[0] == 'E');
     }
@@ -4268,7 +4313,7 @@ remote_insert_watchpoint (addr, len, type)
   sprintf (p, ",%x", len);
   
   putpkt (buf);
-  getpkt (buf, 0);
+  getpkt (buf, PBUFSIZ, 0);
 
   if (buf[0] == '\0' || buf [0] == 'E')
     return -1;
@@ -4291,7 +4336,7 @@ remote_remove_watchpoint (addr, len, type)
   p += hexnumstr (p, (ULONGEST) addr);
   sprintf (p, ",%x", len);
   putpkt (buf);
-  getpkt (buf, 0);
+  getpkt (buf, PBUFSIZ, 0);
 
   if (buf[0] == '\0' || buf [0] == 'E')
     return -1;
@@ -4319,7 +4364,7 @@ remote_insert_hw_breakpoint (addr, len)
   *p = '\0';
 
   putpkt (buf);
-  getpkt (buf, 0);
+  getpkt (buf, PBUFSIZ, 0);
 
   if (buf[0] == '\0' || buf [0] == 'E')
     return -1;
@@ -4344,7 +4389,7 @@ remote_remove_hw_breakpoint (addr, len)
   *p = '\0';
 
   putpkt(buf);
-  getpkt (buf, 0);
+  getpkt (buf, PBUFSIZ, 0);
   
   if (buf[0] == '\0' || buf [0] == 'E')
     return -1;
@@ -4481,7 +4526,7 @@ compare_sections_command (args, from_tty)
       bfd_get_section_contents (exec_bfd, s, sectdata, 0, size);
       host_crc = crc32 ((unsigned char *) sectdata, size, 0xffffffff);
 
-      getpkt (buf, 0);
+      getpkt (buf, PBUFSIZ, 0);
       if (buf[0] == 'E')
        error ("target memory fault, section %s, range 0x%08x -- 0x%08x",
               sectname, lma, lma + size);
@@ -4575,14 +4620,14 @@ remote_query (query_type, buf, outbuf, bufsiz)
   if (i < 0)
     return i;
 
-  getpkt (outbuf, 0);
+  getpkt (outbuf, *bufsiz, 0);
 
   return 0;
 }
 
 static void
 remote_rcmd (char *command,
-            struct gdb_file *outbuf)
+            struct ui_file *outbuf)
 {
   int i;
   char *buf = alloca (PBUFSIZ);
@@ -4618,7 +4663,7 @@ remote_rcmd (char *command,
     {
       /* XXX - see also tracepoint.c:remote_get_noisy_reply() */
       buf[0] = '\0';
-      getpkt (buf, 0);
+      getpkt (buf, PBUFSIZ, 0);
       if (buf[0] == '\0')
        error ("Target does not support this command\n");
       if (buf[0] == 'O' && buf[1] != 'K')
@@ -4660,7 +4705,7 @@ packet_command (args, from_tty)
   puts_filtered ("\n");
   putpkt (args);
 
-  getpkt (buf, 0);
+  getpkt (buf, PBUFSIZ, 0);
   puts_filtered ("received: ");
   print_packet (buf);
   puts_filtered ("\n");
@@ -4834,7 +4879,8 @@ init_remote_ops ()
   remote_ops.to_longname = "Remote serial target in gdb-specific protocol";
   remote_ops.to_doc =
     "Use a remote computer via a serial line, using a gdb-specific protocol.\n\
-Specify the serial device it is connected to (e.g. /dev/ttya).";
+Specify the serial device it is connected to\n\
+(e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).";
   remote_ops.to_open = remote_open;
   remote_ops.to_close = remote_close;
   remote_ops.to_detach = remote_detach;
@@ -4900,9 +4946,7 @@ Specify the serial device it is connected to (e.g. /dev/ttya).",
  */
 
 static void
-remote_info_process (args, from_tty)
-     char *args;
-     int from_tty;
+remote_info_process (char *args, int from_tty)
 {
   char *buf = alloca (PBUFSIZ);
 
@@ -4910,7 +4954,7 @@ remote_info_process (args, from_tty)
     error ("Command can only be used when connected to the remote target.");
 
   putpkt ("qfProcessInfo");
-  getpkt (buf, 0);
+  getpkt (buf, PBUFSIZ, 0);
   if (buf[0] == 0)
     return;                    /* Silently: target does not support this feature. */
 
@@ -4921,7 +4965,7 @@ remote_info_process (args, from_tty)
     {
       remote_console_output (&buf[1]);
       putpkt ("qsProcessInfo");
-      getpkt (buf, 0);
+      getpkt (buf, PBUFSIZ, 0);
     }
 }
 
@@ -4930,9 +4974,7 @@ remote_info_process (args, from_tty)
  */
 
 static void
-remote_cisco_open (name, from_tty)
-     char *name;
-     int from_tty;
+remote_cisco_open (char *name, int from_tty)
 {
   if (name == 0)
     error (
@@ -5012,8 +5054,7 @@ device is attached to the remote system (e.g. host:port).");
 }
 
 static void
-remote_cisco_close (quitting)
-     int quitting;
+remote_cisco_close (int quitting)
 {
   remote_cisco_mode = 0;
   remote_close (quitting);
@@ -5043,7 +5084,7 @@ static int echo_check;
 extern int quit_flag;
 
 static int
-readsocket ()
+readsocket (void)
 {
   int data;
 
@@ -5110,7 +5151,7 @@ readsocket ()
 }
 
 static int
-readtty ()
+readtty (void)
 {
   int tty_bytecount;
 
@@ -5150,7 +5191,7 @@ readtty ()
 }
 
 static int
-minitelnet ()
+minitelnet (void)
 {
   fd_set input;                        /* file descriptors for select */
   int tablesize;               /* max number of FDs for select */
@@ -5233,9 +5274,7 @@ minitelnet ()
 }
 
 static int
-remote_cisco_wait (pid, status)
-     int pid;
-     struct target_waitstatus *status;
+remote_cisco_wait (int pid, struct target_waitstatus *status)
 {
   if (minitelnet () != ENTER_DEBUG)
     {
@@ -5283,14 +5322,14 @@ static int
 remote_can_async_p (void)
 {
   /* We're async whenever the serial device is. */
-  return SERIAL_CAN_ASYNC_P (remote_desc);
+  return (current_target.to_async_mask_value) && SERIAL_CAN_ASYNC_P (remote_desc);
 }
 
 static int
 remote_is_async_p (void)
 {
   /* We're async whenever the serial device is. */
-  return SERIAL_IS_ASYNC_P (remote_desc);
+  return (current_target.to_async_mask_value) && SERIAL_IS_ASYNC_P (remote_desc);
 }
 
 /* Pass the SERIAL event on and up to the client.  One day this code
@@ -5312,6 +5351,9 @@ remote_async_serial_handler (serial_t scb, void *context)
 static void
 remote_async (void (*callback) (enum inferior_event_type event_type, void *context), void *context)
 {
+  if (current_target.to_async_mask_value == 0)
+    internal_error ("Calling remote_async when async is masked");
+
   if (callback != NULL)
     {
       SERIAL_ASYNC (remote_desc, remote_async_serial_handler, NULL);
@@ -5329,7 +5371,7 @@ remote_async (void (*callback) (enum inferior_event_type event_type, void *conte
    target. */
 
 static void
-init_remote_async_ops ()
+init_remote_async_ops (void)
 {
   remote_async_ops.to_shortname = "async";
   remote_async_ops.to_longname = "Remote serial target in async version of the gdb-specific protocol";
@@ -5368,6 +5410,7 @@ Specify the serial device it is connected to (e.g. /dev/ttya).";
   remote_async_ops.to_can_async_p = remote_can_async_p;
   remote_async_ops.to_is_async_p = remote_is_async_p;
   remote_async_ops.to_async = remote_async;
+  remote_async_ops.to_async_mask_value = 1;
   remote_async_ops.to_magic = OPS_MAGIC;
 }
 
@@ -5375,7 +5418,7 @@ Specify the serial device it is connected to (e.g. /dev/ttya).";
    remote vector and adding to it.  */
 
 static void
-init_extended_async_remote_ops ()
+init_extended_async_remote_ops (void)
 {
   extended_async_remote_ops = remote_async_ops;
 
@@ -5391,9 +5434,7 @@ Specify the serial device it is connected to (e.g. /dev/ttya).",
 }
 
 static void
-set_remote_cmd (args, from_tty)
-     char *args;
-     int from_tty;
+set_remote_cmd (char *args, int from_tty)
 {
   
 }
@@ -5470,13 +5511,6 @@ response packet.  GDB supplies the initial `$' character, and the\n\
 terminating `#' character and checksum.",
           &maintenancelist);
 
-  add_show_from_set
-    (add_set_cmd ("remotetimeout", no_class,
-                 var_integer, (char *) &remote_timeout,
-                 "Set timeout value for remote read.\n",
-                 &setlist),
-     &showlist);
-
   add_show_from_set
     (add_set_cmd ("remotebreak", no_class,
                  var_boolean, (char *) &remote_break,
This page took 0.036733 seconds and 4 git commands to generate.