Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Mark Wielaard <mark@klomp.org>
To: Tom Tromey <tromey@adacore.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH] Do not write negative PID or TID in remote protocol
Date: Thu, 2 Jul 2026 12:18:55 +0200	[thread overview]
Message-ID: <20260702101855.GI4673@gnu.wildebeest.org> (raw)
In-Reply-To: <20260430175904.1342455-1-tromey@adacore.com>

Hi Tom,

On Thu, Apr 30, 2026 at 11:59:04AM -0600, Tom Tromey wrote:
> Currently both gdb and gdbserver can write a negative number for the
> PID or TID.  However, the only negative value that really makes sense
> is the special case of "-1" -- in other cases if the PID or TID has
> the high bit set, it should still be written as a positive number.
> 
> This patch attempts to fix the bug.
> 
> v2 of this patch combines the implementations and moves them to
> gdbsupport.  I tried making these standalone functions in rsp-low.cc,
> but that runs afoul of libipa.  So, I made them methods of ptid_t.
> 
> The new unit tests pointed out that round-tripping a sign-extended
> number didn't really work, because the checks were done via ULONGEST.
> It's kind of unfortunate that the PID and LWP are host-dependent
> types.  This should probably be fixed, but I haven't done so here.
> Meanwhile I changed the checks to use the corresponding unsigned type.

It looks like there is still something wrong on 32bit arches.
At least after this patch the i386 debian buildbot fails:
https://builder.sourceware.org/buildbot/#/builders/105/builds/12989

> +ptid_t
> +ptid_t::parse (const char *buf, const char **obuf, bool for_remote,
> +	       gdb::function_view<pid_type ()> default_pid)
> +{
> +  const char *p = buf;
> +  const char *pp;
> +  ptid_t::pid_type pid = 0;
> +  ptid_t::lwp_type lwp = 0;
> +  ULONGEST hex;
> +
> +  using unsigned_pid_type = std::make_unsigned<pid_type>::type;
> +  using unsigned_lwp_type = std::make_unsigned<lwp_type>::type;
> +
> +  if (*p == 'p')
> +    {
> +      /* Multi-process ptid.  */
> +      pp = unpack_varlen_hex (p + 1, &hex);
> +      if (pp == (p + 1) || *pp != '.')
> +	error (_("invalid remote ptid: %s"), buf);
> +
> +      pid = (ptid_t::pid_type) hex;
> +      if (hex != ((unsigned_pid_type) pid))
> +	error (_("invalid remote ptid: %s"), buf);
> +
> +      p = pp + 1;
> +      hex = hex_or_minus_one (p, &pp, for_remote);
> +      if (pp == p)
> +	error (_("invalid remote ptid: %s"), buf);
> +
> +      lwp = (ptid_t::lwp_type) hex;
> +      if (hex != ((unsigned_lwp_type) lwp))
> +	error (_("invalid remote ptid: %s"), buf);

Are the types/castes here correct? hex is an ULONGEST that is being
cast to an ptid_t::lwp_type and then an unsigned_lwp_type. Then this
sanity check seems to fail (on i386 at least). I think this is because
ULONGEST on i386 is unsigned long long, while unsigned_lwp_type is
unsigned long.

Cheers,

Mark

  parent reply	other threads:[~2026-07-02 10:19 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-30 17:59 Tom Tromey
2026-06-12 15:23 ` Tom Tromey
2026-07-01 17:47   ` Tom Tromey
2026-07-02 10:18 ` Mark Wielaard [this message]
2026-07-02 18:29   ` Tom Tromey
  -- strict thread matches above, loose matches on Subject: below --
2026-03-11 20:21 Tom Tromey
2026-03-12 19:42 ` Kevin Buettner
2026-04-30 17:33   ` Tom Tromey

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=20260702101855.GI4673@gnu.wildebeest.org \
    --to=mark@klomp.org \
    --cc=gdb-patches@sourceware.org \
    --cc=tromey@adacore.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