--- gdb/remote.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 49 insertions(+), 13 deletions(-) Index: src/gdb/remote.c =================================================================== --- src.orig/gdb/remote.c 2008-10-22 14:25:12.000000000 +0100 +++ src/gdb/remote.c 2008-10-22 14:58:28.000000000 +0100 @@ -209,6 +209,8 @@ static void show_remote_protocol_packet_ const char *value); static char *write_ptid (char *buf, const char *endbuf, ptid_t ptid); +static char *write_ptid_leading_zeros (char *buf, const char *endbuf, + ptid_t ptid); static ptid_t read_ptid (char *buf, char **obuf); static void remote_query_supported (void); @@ -1296,7 +1298,10 @@ remote_thread_alive (ptid_t ptid) endp = rs->buf + get_remote_packet_size (); *p++ = 'T'; - write_ptid (p, endp, ptid); + + /* Make sure we output an 8-char wide thread id (if the + multi-process extensions aren't in effect). */ + write_ptid_leading_zeros (p, endp, ptid); putpkt (rs->buf); getpkt (&rs->buf, &rs->buf_size, 0); @@ -1420,32 +1425,63 @@ static int remote_newthread_step (thread /* Write a PTID to BUF. ENDBUF points to one-passed-the-end of the - buffer we're allowed to write to. Returns - BUF+CHARACTERS_WRITTEN. */ + buffer we're allowed to write to. If LEADING_ZEROS, and the + multi-process extensions are in effect, always output an 8-char + long tid, padding with leading 0's if required to do so. + Returns BUF+CHARACTERS_WRITTEN. */ static char * -write_ptid (char *buf, const char *endbuf, ptid_t ptid) +write_ptid_1 (char *buf, const char *endbuf, + ptid_t ptid, int leading_zeros) { int pid, tid; struct remote_state *rs = get_remote_state (); - if (remote_multi_process_p (rs)) + tid = ptid_get_tid (ptid); + + /* GDB has always output leading zeros in the thread id in some + packets. Some stubs misparse those packets if the leading zeros + are removed. GDB never sent leading zeros when multi-process + extensions are in effect, so it's safe to not send them in that + case (since it's just extra traffic). */ + if (leading_zeros && !remote_multi_process_p (rs)) { - pid = ptid_get_pid (ptid); - if (pid < 0) - buf += xsnprintf (buf, endbuf - buf, "p-%x.", -pid); + if (tid < 0) + buf += xsnprintf (buf, endbuf - buf, "-%08x", -tid); else - buf += xsnprintf (buf, endbuf - buf, "p%x.", pid); + buf += xsnprintf (buf, endbuf - buf, "%08x", tid); } - tid = ptid_get_tid (ptid); - if (tid < 0) - buf += xsnprintf (buf, endbuf - buf, "-%x", -tid); else - buf += xsnprintf (buf, endbuf - buf, "%x", tid); + { + if (remote_multi_process_p (rs)) + { + pid = ptid_get_pid (ptid); + if (pid < 0) + buf += xsnprintf (buf, endbuf - buf, "p-%x.", -pid); + else + buf += xsnprintf (buf, endbuf - buf, "p%x.", pid); + } + if (tid < 0) + buf += xsnprintf (buf, endbuf - buf, "-%x", -tid); + else + buf += xsnprintf (buf, endbuf - buf, "%x", tid); + } return buf; } +static char * +write_ptid (char *buf, const char *endbuf, ptid_t ptid) +{ + return write_ptid_1 (buf, endbuf, ptid, 0); +} + +static char * +write_ptid_leading_zeros (char *buf, const char *endbuf, ptid_t ptid) +{ + return write_ptid_1 (buf, endbuf, ptid, 1); +} + /* 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. */