Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: "Metzger, Markus T" <markus.t.metzger@intel.com>
To: Simon Marchi <simark@simark.ca>,
	Thiago Jung Bauermann <thiago.bauermann@linaro.org>
Cc: "gdb-patches@sourceware.org" <gdb-patches@sourceware.org>
Subject: RE: [PATCH 1/2] gdbserver, read_ptid: handle '0' and '-1' thread ids
Date: Mon, 22 Sep 2025 13:29:12 +0000	[thread overview]
Message-ID: <DM8PR11MB5749157EE14AE4DABBF2269FDE12A@DM8PR11MB5749.namprd11.prod.outlook.com> (raw)
In-Reply-To: <4bc68b3a-d8a5-45b1-aa94-0b6af488d8bc@simark.ca>

Hello Simon, Thiago,

Thanks for your reviews.

>>> 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'.
>
>I can see that there are read_ptid functions both on GDB and
>GDBserver-side.  We can see that they are similar, but they have
>diverged a bit (and they will diverge even more with this patch).  IWBN
>if possible to have just one shared implementation.  One part that
>differs between the implementations is where we get the default pid
>value.  That value would have to be passed in as a parameter.  The nice
>side-effect of that is that it make it easy to unit test this function,
>which we don't do right now.

They are more different than it first appears.  The gdbserver side
accepts pN.-1, for example, while the gdb side doesn't.  The gdb side
doesn't accept -1 at all.

When the string does not start with 'p', both fall back to the
respective inferior on either side, but gdb has special handling for a
not-yet-known process id, whereas the gdbserver side doesn't.


>>>
>>> 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':
>
>Agreed.  I think it would be valid to pass `0A`, to represent tid 10.
>
>Can we instead let the code go through hex_or_minus_one below and handle
>"tid == 0" there?

That is indeed a nice improvement that simplifies this patch to just:

diff --git a/gdbserver/remote-utils.cc b/gdbserver/remote-utils.cc
index 760655994c5..f5d70c546d3 100644
--- a/gdbserver/remote-utils.cc
+++ b/gdbserver/remote-utils.cc
@@ -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.  */

Intel Deutschland GmbH
Registered Address: Am Campeon 10, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de
Managing Directors: Sean Fennelly, Jeffrey Schneiderman, Tiffany Doon Silva
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928

  reply	other threads:[~2025-09-22 13:30 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 ` [PATCH 1/2] gdbserver, read_ptid: handle '0' and '-1' thread ids Thiago Jung Bauermann
2025-08-14 20:40   ` Simon Marchi
2025-09-22 13:29     ` Metzger, Markus T [this message]
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=DM8PR11MB5749157EE14AE4DABBF2269FDE12A@DM8PR11MB5749.namprd11.prod.outlook.com \
    --to=markus.t.metzger@intel.com \
    --cc=gdb-patches@sourceware.org \
    --cc=simark@simark.ca \
    --cc=thiago.bauermann@linaro.org \
    /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