if (target_wait_loop_hook) (*target_wait_loop_hook) ();
if (deprecated_target_wait_loop_hook) (*deprecated_target_wait_loop_hook) ();
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);  ULONGEST thread_num = -1;  ULONGEST addr;  status->kind = TARGET_WAITKIND_EXITED;  status->value.integer = 0;  remote_stopped_by_watchpoint_p = 0;  while (1)    {      unsigned char *p;      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 (buf, (rs->remote_packet_size), 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         collection of trace data) every time the target stops.  */      if (target_wait_loop_hook)	(*target_wait_loop_hook) ();      switch (buf[0])	{	case 'E':		/* Error of some sort */	  warning ("Remote failure reply: %s", buf);	  continue;	case 'F':		/* File-I/O request */	  remote_fileio_request (buf);	  continue;	case 'T':		/* Status with PC, SP, FP, ... */	  {	    int i;	    char regs[MAX_REGISTER_SIZE];	    /* Expedited reply, containing Signal, {regno, reg} repeat */	    /*  format is:  'Tssn...:r...;n...:r...;n...:r...;#cc', where	       ss = signal number	       n... = register number	       r... = register contents	     */	    p = &buf[3];	/* after Txx */	    while (*p)	      {		unsigned char *p1;		char *p_temp;		int fieldsize;		long pnum = 0;		/* If the packet contains a register number, save it in pnum		   and set p1 to point to the character following it.		   Otherwise p1 points to p.  */		/* If this packet is an awatch packet, don't parse the 'a'		   as a register number.  */		if (!strncmp (p, "awatch", strlen ("awatch")) != 0)		  {		    /* Read the register number.  */		    pnum = strtol (p, &p_temp, 16);		    p1 = (unsigned char *) p_temp;		  }		else		  p1 = p;		if (p1 == p)	/* No register number present here */		  {		    p1 = (unsigned char *) strchr (p, ':');		    if (p1 == NULL)		      error ("Malformed packet(a) (missing colon): %s\nPacket: '%s'\n",			     p, buf);		    if (strncmp (p, "thread", p1 - p) == 0)		      {			p_temp = unpack_varlen_hex (++p1, &thread_num);			record_currthread (thread_num);			p = (unsigned char *) p_temp;		      }		    else if ((strncmp (p, "watch", p1 - p) == 0)			     || (strncmp (p, "rwatch", p1 - p) == 0)			     || (strncmp (p, "awatch", p1 - p) == 0))		      {			remote_stopped_by_watchpoint_p = 1;			p = unpack_varlen_hex (++p1, &addr);			remote_watch_data_address = (CORE_ADDR)addr;		      }		    else 		      { 			/* Silently skip unknown optional info.  */ 			p_temp = (unsigned char *) strchr (p1 + 1, ';'); 			if (p_temp)			  p = p_temp; 		      }		  }		else		  {		    struct packet_reg *reg = packet_reg_from_pnum (rs, pnum);		    p = p1;		    if (*p++ != ':')		      error ("Malformed packet(b) (missing colon): %s\nPacket: '%s'\n",			     p, buf);		    if (reg == NULL)		      error ("Remote sent bad register number %ld: %s\nPacket: '%s'\n",			     pnum, p, buf);		    fieldsize = hex2bin (p, regs, DEPRECATED_REGISTER_RAW_SIZE (reg->regnum));		    p += 2 * fieldsize;		    if (fieldsize < DEPRECATED_REGISTER_RAW_SIZE (reg->regnum))		      warning ("Remote reply is too short: %s", buf);		    supply_register (reg->regnum, regs);		  }		if (*p++ != ';')		  error ("Remote register badly formatted: %s\nhere: %s",			 buf, p);	      }	  }	  /* fall through */	case 'S':		/* Old style status, just signal only */	  status->kind = TARGET_WAITKIND_STOPPED;	  status->value.sig = (enum target_signal)	    (((fromhex (buf[1])) << 4) + (fromhex (buf[2])));	  if (buf[3] == 'p')	    {	      thread_num = strtol ((const char *) &buf[4], NULL, 16);	      record_currthread (thread_num);	    }	  goto got_status;	case 'W':		/* Target exited */	  {	    /* The remote process exited.  */	    status->kind = TARGET_WAITKIND_EXITED;	    status->value.integer = (fromhex (buf[1]) << 4) + fromhex (buf[2]);	    goto got_status;	  }	case 'X':	  status->kind = TARGET_WAITKIND_SIGNALLED;	  status->value.sig = (enum target_signal)	    (((fromhex (buf[1])) << 4) + (fromhex (buf[2])));	  kill_kludge = 1;	  goto got_status;	case 'O':		/* Console output */	  remote_console_output (buf + 1);	  /* 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)	    {	      /* Zero length reply means that we tried 'S' or 'C' and	         the remote system doesn't support it.  */	      target_terminal_ours_for_output ();	      printf_filtered		("Can't send signals to this remote system.  %s not sent.\n",		 target_signal_to_name (last_sent_signal));	      last_sent_signal = TARGET_SIGNAL_0;	      target_terminal_inferior ();	      strcpy ((char *) buf, last_sent_step ? "s" : "c");	      putpkt ((char *) buf);	      continue;	    }	  /* else fallthrough */	default:	  warning ("Invalid remote reply: %s", buf);	  continue;	}    }got_status:  if (thread_num != -1)    {      return pid_to_ptid (thread_num);    }  return inferior_ptid;}