if (object == TARGET_OBJECT_MEMORY) { int xfered; errno = 0;  if (writebuf != NULL) { void *buffer = xmalloc (len); struct cleanup *cleanup = make_cleanup (xfree, buffer); memcpy (buffer, writebuf, len); xfered = remote_xfer_memory (offset, buffer, len, 1, NULL, ops); do_cleanups (cleanup); } else xfered = remote_xfer_memory (offset, readbuf, len, 0, NULL, ops);  if (xfered > 0) return xfered; else if (xfered == 0 && errno == 0) return 0; else return -1; }
remote_xfer_partial (struct target_ops *ops, enum target_object object,		     const char *annex, void *readbuf, const void *writebuf,		     ULONGEST offset, LONGEST len){  struct remote_state *rs = get_remote_state ();  int i;  char *buf2 = alloca (rs->remote_packet_size);  char *p2 = &buf2[0];  char query_type;  /* Only handle reads.  */  if (writebuf != NULL || readbuf == NULL)    return -1;  /* Map pre-existing objects onto letters.  DO NOT do this for new     objects!!!  Instead specify new query packets.  */  switch (object)    {    case TARGET_OBJECT_KOD:      query_type = 'K';      break;    case TARGET_OBJECT_AVR:      query_type = 'R';      break;    case TARGET_OBJECT_AUXV:      if (remote_protocol_qPart_auxv.support != PACKET_DISABLE)	{	  unsigned int total = 0;	  while (len > 0)	    {	      LONGEST n = min ((rs->remote_packet_size - 2) / 2, len);	      snprintf (buf2, rs->remote_packet_size,			"qPart:auxv:read::%s,%s",			phex_nz (offset, sizeof offset),			phex_nz (n, sizeof n));	      i = putpkt (buf2);	      if (i < 0)		return total > 0 ? total : i;	      buf2[0] = '\0';	      getpkt (buf2, rs->remote_packet_size, 0);	      if (packet_ok (buf2, &remote_protocol_qPart_auxv) != PACKET_OK)		return total > 0 ? total : -1;	      if (buf2[0] == 'O' && buf2[1] == 'K' && buf2[2] == '\0')		break;		/* Got EOF indicator.  */	      /* Got some data.  */	      i = hex2bin (buf2, readbuf, len);	      if (i > 0)		{		  readbuf = (void *) ((char *) readbuf + i);		  offset += i;		  len -= i;		  total += i;		}	    }	  return total;	}      return -1;    default:      return -1;    }  /* Note: a zero OFFSET and LEN can be used to query the minimum     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))    return -1;  len = rs->remote_packet_size;  /* except for querying the minimum buffer size, target must be open */  if (!remote_desc)    error ("remote query is only available after target open");  gdb_assert (annex != NULL);  gdb_assert (readbuf != NULL);  *p2++ = 'q';  *p2++ = query_type;  /* we used one buffer char for the remote protocol q command and another     for the query type.  As the remote protocol encapsulation uses 4 chars     plus one extra in case we are debugging (remote_debug),     we have PBUFZIZ - 7 left to pack the query string */  i = 0;  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] != '#');      *p2++ = annex[i];      i++;    }  *p2 = '\0';  gdb_assert (annex[i] == '\0');  i = putpkt (buf2);  if (i < 0)    return i;  getpkt (readbuf, len, 0);  return strlen (readbuf);}