Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
To: Markus Metzger <markus.t.metzger@intel.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH 1/2] gdbserver, read_ptid: handle '0' and '-1' thread ids
Date: Thu, 14 Aug 2025 00:36:51 -0300	[thread overview]
Message-ID: <87wm76zi98.fsf@linaro.org> (raw)
In-Reply-To: <20250805071914.3832823-1-markus.t.metzger@intel.com> (Markus Metzger's message of "Tue, 5 Aug 2025 07:19:13 +0000")

Hello Markus,

Markus Metzger <markus.t.metzger@intel.com> writes:

> The special thread id '-1' means 'all threads'.
> The special thread id '0' means 'any thread'.
>
> Read_ptid () currently returns
>
>     <current pid>.-1.0
>
> and
>
>     <current pid>.0.0
>
> respectively.
>
> Change that to minus_one_ptid for '-1' and to null_ptid for '0'.
>
> CC: Thiago Jung Bauermann  <thiago.bauermann@linaro.org>
> ---
>  gdbserver/remote-utils.cc | 20 ++++++++++++++++++++
>  1 file changed, 20 insertions(+)

Nice improvement. Just a minor comment.

> diff --git a/gdbserver/remote-utils.cc b/gdbserver/remote-utils.cc
> index 15f073dd6be..9562cc2e1fb 100644
> --- a/gdbserver/remote-utils.cc
> +++ b/gdbserver/remote-utils.cc
> @@ -566,6 +566,26 @@ read_ptid (const char *buf, const char **obuf)
>    const char *p = buf;
>    const char *pp;
>  
> +  /* Handle special thread ids.  */
> +  if (*p == '0')

I think this should also check the character after '0':

-  if (*p == '0')
+  if (*p == '0' && !isxdigit (p[1]))

> +    {
> +      if (obuf)
> +	*obuf = p + 1;
> +
> +      return null_ptid;
> +    }
> +
> +  if (*p == '-')
> +    {
> +      if (p[1] != '1')

Same here:

-      if (p[1] != '1')
+      if (p[1] != '1' || isxdigit (p[2]))

> +	return null_ptid;
> +
> +      if (obuf)
> +	*obuf = p + 2;
> +
> +      return minus_one_ptid;
> +    }
> +
>    if (*p == 'p')
>      {
>        ULONGEST pid;

From reading the RSP documentation, thread ids are followed only by ',',
';', ':' or '\0', but checking for an hex digit should be enough.

With the changes:

Reviewed-by: Thiago Jung Bauermann <thiago.bauermann@linaro.org>

-- 
Thiago

  parent reply	other threads:[~2025-08-14  3:37 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-05  7:19 Markus Metzger
2025-08-05  7:19 ` [PATCH 2/2] gdb, remote: fix set_thread () in start_remote () Markus Metzger
2025-08-14  4:29   ` Thiago Jung Bauermann
2025-08-14 22:28     ` Simon Marchi
2025-08-15  0:29       ` Thiago Jung Bauermann
2025-08-15  5:33         ` Simon Marchi
2025-08-18  1:43           ` Thiago Jung Bauermann
2025-09-22 13:29       ` Metzger, Markus T
2025-08-14  3:36 ` Thiago Jung Bauermann [this message]
2025-08-14 20:40   ` [PATCH 1/2] gdbserver, read_ptid: handle '0' and '-1' thread ids Simon Marchi
2025-09-22 13:29     ` Metzger, Markus T
2025-09-23 18:26       ` Tom Tromey
2025-09-24  8:04         ` Metzger, Markus T
2025-09-26  6:43           ` Metzger, Markus T

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87wm76zi98.fsf@linaro.org \
    --to=thiago.bauermann@linaro.org \
    --cc=gdb-patches@sourceware.org \
    --cc=markus.t.metzger@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox