Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom Tromey via Gdb-patches <gdb-patches@sourceware.org>
To: Hannes Domani <ssbssa@yahoo.de>
Cc: "gdb-patches@sourceware.org" <gdb-patches@sourceware.org>,
	 Tom Tromey <tromey@adacore.com>
Subject: Re: [PATCH 3/3] Fix control-c handling on Windows
Date: Fri, 09 Dec 2022 08:58:09 -0700	[thread overview]
Message-ID: <87ilikin72.fsf@tromey.com> (raw)
In-Reply-To: <102195784.4047621.1670433222150@mail.yahoo.com> (Hannes Domani's message of "Wed, 7 Dec 2022 17:13:42 +0000 (UTC)")

>>>>> "Hannes" == Hannes Domani <ssbssa@yahoo.de> writes:

Hannes> I've now tested this a bit, it's a big improvement.

Thanks for trying it.  I appreciate that.

Hannes> When I first started a program with 'new-console on', then the
Hannes> sigint_ours variable would not be initialized, and I would later get
Hannes> a crash on C-c.

I looked at this and my feeling is that this is a latent bug.

I think what's going on is that sigint_ours is set under different
conditions than it is used.

That is, it is set like:

  if (gdb_has_a_terminal ()
      && tinfo->ttystate != NULL
      && sharing_input_terminal (inf))
[...]
      if (!job_control)
	{
	  sigint_ours = install_sigint_handler (SIG_IGN);
[...]
      gdb_tty_state = target_terminal_state::is_inferior;


However later it is used:

  if (gdb_tty_state != desired_state)
[...]
      if (!job_control && desired_state == target_terminal_state::is_ours)
	{
	  install_sigint_handler (sigint_ours);

It's maybe hard to reason about but it seems to me that there's some
possibility for the value to be used even though it hasn't been set, and
I suspect that is what you are seeing.

It might be useful if you could confirm this.  Just some simple logging
at these two points would be sufficient.

If that's the issue then I can write a patch to change sigint_ours to be
a gdb::optional and check it that way.

Hannes> And for some reason one of my builds (x86_64+TUI+python) needed the
Hannes> #include <signal.h> in mingw-hdep.c, but my other (i686 basic) didn't.

I didn't see this but I went ahead and added the include to my patch,
since it seems harmless.

Hannes> But my basic i686 build had another problem when starting a program with
Hannes> 'new-console on', because at program start it called install_sigint_handler(),
Hannes> but rl_set_signals() would later override the SIGINT handler again, so C-c
Hannes> didn't work work in this situation.
Hannes> With 'new-console off' this didn't happen, since install_sigint_handler() was
Hannes> again called later since it shared the console.

I really don't understand the interaction between signal and
SetConsoleCtrlHandler.  I tried searching for some docs on this but
didn't find anything that was really enlightening.

Also it's somewhat surprising that the x86 and x86-64 builds would be
different in this regard.

Anyway ... I'm not sure what to do here yet.  The interactions with
readline are pretty hard to understand.  I guess the question is where
should install_sigint_handler be called where it is not called -- that
is, to reset the signals from readline.  Alternatively, where is it
called on x86-64 but not on x86?

I did try 'new-console on' with my (x86-64) build, and that worked fine.
I can try an x86 build and see if that works any better.

Tom

  reply	other threads:[~2022-12-09 15:58 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-05 18:56 [PATCH 0/3] Fix Windows C-c handling Tom Tromey via Gdb-patches
2022-12-05 18:56 ` [PATCH 1/3] Rename install_sigint_handler Tom Tromey via Gdb-patches
2022-12-05 18:56 ` [PATCH 2/3] Refactor code to check for terminal sharing Tom Tromey via Gdb-patches
2022-12-05 19:50   ` Eli Zaretskii via Gdb-patches
2022-12-12 17:27     ` Tom Tromey via Gdb-patches
2022-12-05 18:56 ` [PATCH 3/3] Fix control-c handling on Windows Tom Tromey via Gdb-patches
2022-12-07 17:13   ` Hannes Domani via Gdb-patches
2022-12-09 15:58     ` Tom Tromey via Gdb-patches [this message]
2022-12-09 16:19       ` Hannes Domani via Gdb-patches
2022-12-09 17:20         ` Tom Tromey via Gdb-patches
2022-12-09 18:13           ` Hannes Domani via Gdb-patches
2022-12-12 15:36             ` Tom Tromey via Gdb-patches
2022-12-12 17:05               ` Tom Tromey via Gdb-patches
2022-12-13 11:30                 ` Hannes Domani via Gdb-patches
2022-12-13 19:51                   ` Tom Tromey via Gdb-patches
2022-12-05 18:59 ` [PATCH 0/3] Fix Windows C-c handling Tom Tromey via Gdb-patches
2022-12-12 13:23   ` Jon Turney
2022-12-12 17:29     ` Tom Tromey via Gdb-patches

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=87ilikin72.fsf@tromey.com \
    --to=gdb-patches@sourceware.org \
    --cc=ssbssa@yahoo.de \
    --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