From: Eli Zaretskii <eliz@gnu.org>
To: Pedro Alves <palves@redhat.com>
Cc: tom@tromey.com, gdb-patches@sourceware.org
Subject: Re: [PATCH] Readline: Cleanup some warnings
Date: Tue, 19 Mar 2019 20:14:00 -0000 [thread overview]
Message-ID: <83ftritydv.fsf@gnu.org> (raw)
In-Reply-To: <711b6636-b02c-edb2-308d-5fddbf4c33a9@redhat.com> (message from Pedro Alves on Tue, 19 Mar 2019 19:02:43 +0000)
> Cc: gdb-patches@sourceware.org
> From: Pedro Alves <palves@redhat.com>
> Date: Tue, 19 Mar 2019 19:02:43 +0000
>
> > https://sourceware.org/ml/gdb-patches/2008-02/msg00423.html
Caveat: I didn't yet read that thread myself.
> Hmmm,
>
> Daniel wrote:
>
> > GDB has several SIGINT handlers which call longjmp. This is
> > problematic for at least two reasons. One is that we could be in the
> > middle of something unwise to longjmp out of, for instance malloc. In
> > practice, this never happens because we're usually waiting for I/O
> > when one of the relevant handlers is invoked, but there are a number
> > of places where it could definitely happen.
>
> That was indeed true back then, but since then, immediate_quit
> was completely eliminated, and we no longer longjmp from signal
> handlers anymore, since:
> https://sourceware.org/ml/gdb-patches/2016-03/msg00351.html
>
> Daniel wrote:
>
> > My goals in fixing this were to hide the Windows ugliness, and to fit
> > in nicely with GDB's asynchronous event loop. Since we do not return
> > to the primary event loop during target actions (for the current,
> > non-async GDB), I couldn't rely on the event loop entirely. But I
> > could use the same token mechanism and thus share the bodies of
> > handlers for async mode with the Windows case.
> >
> > The new interface is gdb_call_async_signal_handler. SIGINT handlers,
>
> This interface he mentioned, gdb_call_async_signal_handler, was
> eliminated by that series too:
>
> https://sourceware.org/ml/gdb-patches/2016-03/msg00347.html
>
> So all that's left is that little readline hack, it seems:
>
> /* With multi-threaded SIGINT handling, there is a race between the
> readline signal handler and GDB. It may still be in
> rl_prep_terminal in another thread. Do not return until it is
> done; we can check the state here because we never longjmp from
> signal handlers on Windows. */
> while (RL_ISSTATE (RL_STATE_SIGHANDLER))
> Sleep (1);
>
> (Curiously, that bit only appeared in a later version of Dan's patch,
> here: https://sourceware.org/ml/gdb-patches/2008-03/msg00034.html)
>
> I'm not seeing why we'd still need that bit, but then again,
> I'm not seeing why it was needed in the first place.
> The signal handler could run concurrently with gdb at any other
> point in the gdb code, not just here, so at any point we
> call into readline, we can be running readline code in parallel
> with a signal handler touching readline's state. It sounds like
> that should be a readline problem to worry about.
>
> That could be related to the fact that readline's signal handler
> overrides gdb's, does its thing, and then calls gdb's signal
> handler manually? If the WaitForSingleObject call had already
> woken up, then gdb's signal handler has already run and SetEvent
> on sigint_event. Then the code would go and run the deferred
> signal handler. In the remote case, that handler would
> issue prompt "Give up (and stop debugging it)? (y or n)" prompt,
> and if that is running in parallel with readline's signal
> handler still calling rl_prep_terminal, bad things would happen.
Not sure if the above refers to what I wanted to say, but: as I'm sure
you know, SIGINT handlers on Windows run in a separate thread, created
by the OS, so a Readline SIGINT handler could ruin in parallel both
with Readline's other code and in parallel with GDB's code, depending
on when exactly did the user type Ctrl-C. In a few cases where it was
important to emulate Posix behavior in order not to step on the troes
of the mainline code, I needed to stop the main thread while the
SIGINT handler was running. Could it be that the code we are
discussing does something similar?
> But again, why isn't that a readline problem, instead of
> a gdb problem?
I agree: the right solution would be for the Readline's SIGINT handler
to stop the main thread (e.g., by using SuspendThread).
> I'm still puzzled on why this isn't a readline issue. Shouldn't
> readline's Windows signal handler be synchronizing with mainline
> code such that if a signal handler is running, mainline calls into
> readline would block?
Yes, I think so.
> I think there must be something else to this.
Maybe. I will try to read that discussion soon.
Thanks.
next prev parent reply other threads:[~2019-03-19 20:14 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-30 8:57 Alan Hayward
2019-01-31 7:59 ` Joel Brobecker
2019-01-31 10:02 ` Alan Hayward
2019-01-31 17:24 ` Alan Hayward
[not found] ` <20190201080533.GA31043@adacore.com>
2019-02-01 12:47 ` Tom Tromey
2019-02-01 18:54 ` Philippe Waroquiers
2019-02-06 19:56 ` Pedro Alves
2019-03-17 17:30 ` Tom Tromey
2019-03-17 18:35 ` Eli Zaretskii
[not found] ` <87imwex333.fsf@tromey.com>
2019-03-19 18:37 ` Eli Zaretskii
2019-03-19 19:02 ` Pedro Alves
2019-03-19 19:04 ` Pedro Alves
2019-03-19 20:14 ` Eli Zaretskii [this message]
2019-03-20 8:55 ` Eli Zaretskii
2019-03-20 15:46 ` Pedro Alves
2019-03-20 15:50 ` Pedro Alves
2019-03-20 17:39 ` Eli Zaretskii
2019-03-20 17:50 ` Pedro Alves
2019-03-20 18:01 ` Eli Zaretskii
2019-03-20 18:28 ` Pedro Alves
2019-03-21 17:31 ` Pedro Alves
2019-03-21 18:30 ` Eli Zaretskii
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=83ftritydv.fsf@gnu.org \
--to=eliz@gnu.org \
--cc=gdb-patches@sourceware.org \
--cc=palves@redhat.com \
--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