Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Andrew Burgess <aburgess@redhat.com>
To: Tom Tromey <tom@tromey.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH] gdb/python: avoid switching threads for send_packet where possible
Date: Sun, 07 Jun 2026 20:58:00 +0100	[thread overview]
Message-ID: <87o6hmqg1j.fsf@redhat.com> (raw)
In-Reply-To: <878q925lrk.fsf@tromey.com>

Tom Tromey <tom@tromey.com> writes:

>>>>>> "Andrew" == Andrew Burgess <aburgess@redhat.com> writes:
>
> Andrew> Bug PR gdb/32120 identifies a case where a user tried to write a
> Andrew> custom frame unwinder that made use of
> Andrew> RemoteTargetConnection.send_packet
>
> Just for the record this seems like a weird and bad choice.

Probably, I ended up looking at this because I added the send_packet
API, and I was curious why this didn't "just work".

>
> Andrew>   scoped_restore_current_thread restore_thread;
> Andrew>   switch_to_target_no_thread (conn->target);
>
> Andrew> The purpose of this is to ensure that the currently selected inferior
> Andrew> has the required remote connection pushed on its target stack.  This
> Andrew> is necessary because `send_remote_packet` (see remote.c) still relies
> Andrew> on global state read from the currently selected inferior.
>
> Andrew> Switching inferior and thread like this, and then switching back
> Andrew> thanks to the scoped restore, will flush the frame cache.
>
> ...
>
> Andrew> I propose that we special case connpy_send_packet so if the correct
> Andrew> inferior is already current then we avoid the switch completely.  This
> Andrew> avoids flushing the frame cache, and all the associated problems.
>
> No problem with the patch at all, but I wonder about the logic of
> putting this check here and not elsewhere.  Like would we want some sort
> of "switch to this inferior and we don't care which thread" -- which
> would be a no-op if the inferior is already selected?

I posted a v2 that moves the conditional logic into a new helper
function.  It's still a little weird because when we switch we likely
want to use switch_to_target_no_thread which ends with no thread
selected, while in the case where we don't need to switch we leave the
current thread selected.  That thread / no-thread difference is strange,
but hopefully with a good comment it shouldn't cause too many problems.

Anyway, feel free to checkout the V2 and see if that looks OK to you.

Thanks,
Andrew


      reply	other threads:[~2026-06-07 20:00 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-26 15:50 Andrew Burgess
2026-05-29 14:32 ` Tom Tromey
2026-06-07 19:58   ` Andrew Burgess [this message]

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=87o6hmqg1j.fsf@redhat.com \
    --to=aburgess@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=tom@tromey.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