+#endif
+
+#ifndef IN_PROCESS_AGENT
+
+/* Write a PTID to BUF. Returns BUF+CHARACTERS_WRITTEN. */
+
+char *
+write_ptid (char *buf, ptid_t ptid)
+{
+ int pid, tid;
+
+ if (multi_process)
+ {
+ pid = ptid_get_pid (ptid);
+ if (pid < 0)
+ buf += sprintf (buf, "p-%x.", -pid);
+ else
+ buf += sprintf (buf, "p%x.", pid);
+ }
+ tid = ptid_get_lwp (ptid);
+ if (tid < 0)
+ buf += sprintf (buf, "-%x", -tid);
+ else
+ buf += sprintf (buf, "%x", tid);
+
+ return buf;
+}
+
+static ULONGEST
+hex_or_minus_one (char *buf, char **obuf)
+{
+ ULONGEST ret;
+
+ if (startswith (buf, "-1"))
+ {
+ ret = (ULONGEST) -1;
+ buf += 2;
+ }
+ else
+ buf = unpack_varlen_hex (buf, &ret);
+
+ if (obuf)
+ *obuf = buf;
+
+ return ret;
+}
+
+/* Extract a PTID from BUF. If non-null, OBUF is set to the to one
+ passed the last parsed char. Returns null_ptid on error. */
+ptid_t
+read_ptid (char *buf, char **obuf)
+{
+ char *p = buf;
+ char *pp;
+ ULONGEST pid = 0, tid = 0;
+
+ if (*p == 'p')
+ {
+ /* Multi-process ptid. */
+ pp = unpack_varlen_hex (p + 1, &pid);
+ if (*pp != '.')
+ error ("invalid remote ptid: %s\n", p);
+
+ p = pp + 1;
+
+ tid = hex_or_minus_one (p, &pp);
+
+ if (obuf)
+ *obuf = pp;
+ return ptid_build (pid, tid, 0);
+ }
+
+ /* No multi-process. Just a tid. */
+ tid = hex_or_minus_one (p, &pp);
+
+ /* Since GDB is not sending a process id (multi-process extensions
+ are off), then there's only one process. Default to the first in
+ the list. */
+ pid = pid_of (get_first_process ());
+
+ if (obuf)
+ *obuf = pp;
+ return ptid_build (pid, tid, 0);
+}
+
+/* Write COUNT bytes in BUF to the client.
+ The result is the number of bytes written or -1 if error.
+ This may return less than COUNT. */
+
+static int
+write_prim (const void *buf, int count)
+{
+ if (remote_connection_is_stdio ())
+ return write (fileno (stdout), buf, count);
+ else
+ return write (remote_desc, buf, count);
+}
+
+/* Read COUNT bytes from the client and store in BUF.
+ The result is the number of bytes read or -1 if error.
+ This may return less than COUNT. */
+
+static int
+read_prim (void *buf, int count)
+{
+ if (remote_connection_is_stdio ())
+ return read (fileno (stdin), buf, count);
+ else
+ return read (remote_desc, buf, count);
+}
+