public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom de Vries <tdevries@suse.de>
To: Tom Tromey <tom@tromey.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH v2 2/2] [gdb/dap] Fix stray KeyboardInterrupt after cancel
Date: Thu, 29 Feb 2024 15:07:42 +0100	[thread overview]
Message-ID: <db693117-7953-4323-a06b-9c6afa0f0264@suse.de> (raw)
In-Reply-To: <87o7c0tkk5.fsf@tromey.com>

On 2/28/24 21:12, Tom Tromey wrote:
>>>>>> "Tom" == Tom de Vries <tdevries@suse.de> writes:
> 
> Tom> Fix this by:
> Tom> - in CancellationHandler, renaming variable in_flight to in_flight_dap_thread,
> Tom>   and adding a variable in_flight_gdb_thread to be able to distinguish when
> Tom>   a request is in flight in the dap thread or the gdb thread.
> Tom> - adding a wrapper Cancellable to to deal with cancelling the wrapped
> Tom>   event
> Tom> - using Cancellable in send_gdb and send_gdb_with_response to wrap the posted
> Tom>   event
> Tom> - in CancellationHandler.cancel, only call gdb.interrupt if
> Tom>   req == self.in_flight_gdb_thread.
> 
> Thanks.  I like this patch a lot.
> 
> I have one question about it.
> 
> Tom> +    @contextmanager
> Tom> +    def interruptable_region(self, req):
> Tom> +        with self.lock:
> Tom> +            # If the request is cancelled, don't execute the region.
> Tom> +            while len(self.reqs) > 0 and self.reqs[0] <= req:
> Tom> +                if heapq.heappop(self.reqs) == req:
> Tom> +                    raise KeyboardInterrupt()
> Tom> +            # Request is being handled by the gdb thread.
> Tom> +            self.in_flight_gdb_thread = req
> 
> (see below)
> 
> Tom> +        try:
> Tom> +            # Execute region.  This may be interrupted by gdb.interrupt.
> Tom> +            yield None
> Tom> +        finally:
> Tom> +            # Request has been handled by the gdb thread,
> Tom> +            with self.lock:
> Tom> +                self.in_flight_gdb_thread = None
> Tom> +
> 
> I think it's possible for the interrupt to occur at the marked spot
> above -- in_flight_gdb_thread has been set and the lock has been
> released.
> 
> However, in this case it seems like in_flight_gdb_thread won't be reset?
> 
> I'm not really sure if this matters.  However, wouldn't moving the 'with'
> block inside the 'try' definitely fix this?
> 

Done in v3.

Thanks,
- Tom


> Tom


  reply	other threads:[~2024-02-29 14:07 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-26 11:58 [PATCH v2 1/2] [gdb/dap] Move send_gdb and send_gdb_with_response to server module Tom de Vries
2024-02-26 11:58 ` [PATCH v2 2/2] [gdb/dap] Fix stray KeyboardInterrupt after cancel Tom de Vries
2024-02-28 20:12   ` Tom Tromey
2024-02-29 14:07     ` Tom de Vries [this message]
2024-02-28 20:09 ` [PATCH v2 1/2] [gdb/dap] Move send_gdb and send_gdb_with_response to server module 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=db693117-7953-4323-a06b-9c6afa0f0264@suse.de \
    --to=tdevries@suse.de \
    --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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).