From 43ae0585aa438e66a5e1ed79b42afe986c18d0a3 Mon Sep 17 00:00:00 2001 From: Markus Metzger Date: Fri, 1 Aug 2025 09:44:44 +0000 Subject: [PATCH] gdbserver, read_ptid: handle '0' and '-1' thread ids The special thread id '-1' means 'all threads'. The special thread id '0' means 'any thread'. Read_ptid () currently returns .-1.0 and .0.0 respectively. Change that to minus_one_ptid for '-1' and to null_ptid for '0'. CC: Thiago Jung Bauermann Approved-By: Tom Tromey --- gdbserver/remote-utils.cc | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/gdbserver/remote-utils.cc b/gdbserver/remote-utils.cc index a89d5c66a81..b7eed731749 100644 --- a/gdbserver/remote-utils.cc +++ b/gdbserver/remote-utils.cc @@ -557,8 +557,8 @@ hex_or_minus_one (const char *buf, const char **obuf) 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. */ +/* Extract a PTID from BUF. If non-null, OBUF is set to one past the last + parsed char. Throws on error. */ ptid_t read_ptid (const char *buf, const char **obuf) { @@ -587,6 +587,13 @@ read_ptid (const char *buf, const char **obuf) /* No multi-process. Just a tid. */ ULONGEST tid = hex_or_minus_one (p, &pp); + /* Handle special thread ids. */ + if (tid == (ULONGEST) -1) + return minus_one_ptid; + + if (tid == 0) + return null_ptid; + /* 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. */ -- 2.47.3