strcpy (buf,"timeout");  if (forever) { #ifdef MAINTENANCE_CMDS timeout = watchdog > 0 ? watchdog : -1; #else timeout = -1; #endif }  else timeout = remote_timeout;  #define MAX_TRIES 3  for (tries = 1; tries <= MAX_TRIES; tries++) {     do { c = readchar (timeout);  if (c == SERIAL_TIMEOUT) { #ifdef MAINTENANCE_CMDS if (forever)	 { target_mourn_inferior (); error ("Watchdog has expired.  Target detached.\n"); } #endif if (remote_debug) puts_filtered ("Timed out.\n"); goto retry; } } while (c != '$');    val = read_frame (buf);  if (val == 1) { if (remote_debug) fprintf_unfiltered (gdb_stderr, "Packet received: %s\n", buf); SERIAL_WRITE (remote_desc, "+", 1); return; }   retry: SERIAL_WRITE (remote_desc, "-", 1); }    printf_unfiltered ("Ignoring packet error, continuing...\n"); SERIAL_WRITE (remote_desc, "+", 1);
timed_out = getpkt_sane (buf, sizeof_buf, forever);
getpkt (buf, forever)     char *buf;     int forever;{  int c;  int tries;  int timeout;  int val;  strcpy (buf,"timeout");  if (forever)    {#ifdef MAINTENANCE_CMDS      timeout = watchdog > 0 ? watchdog : -1;#else      timeout = -1;#endif    }  else    timeout = remote_timeout;#define MAX_TRIES 3  for (tries = 1; tries <= MAX_TRIES; tries++)    {      /* This can loop forever if the remote side sends us characters	 continuously, but if it pauses, we'll get a zero from readchar	 because of timeout.  Then we'll count that as a retry.  */      /* Note that we will only wait forever prior to the start of a packet.	 After that, we expect characters to arrive at a brisk pace.  They	 should show up within remote_timeout intervals.  */      do	{	  c = readchar (timeout);	  if (c == SERIAL_TIMEOUT)	    {#ifdef MAINTENANCE_CMDS	      if (forever)	/* Watchdog went off.  Kill the target. */		{		  target_mourn_inferior ();		  error ("Watchdog has expired.  Target detached.\n");		}#endif	      if (remote_debug)		puts_filtered ("Timed out.\n");	      goto retry;	    }	}      while (c != '$');      /* We've found the start of a packet, now collect the data.  */      val = read_frame (buf);      if (val == 1)	{	  if (remote_debug)	    fprintf_unfiltered (gdb_stderr, "Packet received: %s\n", buf);	  SERIAL_WRITE (remote_desc, "+", 1);	  return;	}      /* Try the whole thing again.  */    retry:      SERIAL_WRITE (remote_desc, "-", 1);    }  /* We have tried hard enough, and just can't receive the packet.  Give up. */  printf_unfiltered ("Ignoring packet error, continuing...\n");  SERIAL_WRITE (remote_desc, "+", 1);}