public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tromey@adacore.com>
To: Tom Tromey <tromey@adacore.com>
Cc: Hannes Domani <ssbssa@yahoo.de>,
	 Hannes Domani via Gdb-patches <gdb-patches@sourceware.org>
Subject: Re: [PATCH] [RFC] Move SetConsoleCtrlHandler calls to async thread
Date: Fri, 02 Dec 2022 09:12:48 -0700	[thread overview]
Message-ID: <87o7sllr7j.fsf@tromey.com> (raw)
In-Reply-To: <87zgc6lszn.fsf@tromey.com> (Tom Tromey's message of "Thu, 01 Dec 2022 14:22:04 -0700")

Tom> Me neither.  I'll see if I can try a different console tomorrow.

I used powershell today.  It seems to mostly work.  I do see the
ctrl-break exit when running with 'set new-console on'... but

One weird thing is if I add logging (see appended hack), the problem
goes away.  That seems extra mysterious to me.

Another problem I thought of is what should happen with these interrupt
sequences when the user puts the inferior in the background, like with
"continue &".  Having them stop the inferior seems wrong, the user might
be trying to interrupt some gdb command instead.

I don't know how this area is supposed to work.

Tom

diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c
index 3d6a3528914..d8e627621e5 100644
--- a/gdb/windows-nat.c
+++ b/gdb/windows-nat.c
@@ -462,6 +462,17 @@ windows_nat_target::process_thread_starter (LPVOID self)
   return 0;
 }
 
+static BOOL
+wrap_wait_for_debug_event (DEBUG_EVENT *event, DWORD timeout)
+{
+  fprintf (stderr, "+++ installing ctrl_c_handler\n");
+  SetConsoleCtrlHandler (&ctrl_c_handler, TRUE);
+  BOOL r = wait_for_debug_event (event, INFINITE);
+  fprintf (stderr, "+++ removing ctrl_c_handler\n");
+  SetConsoleCtrlHandler (&ctrl_c_handler, FALSE);
+  return r;
+}
+
 void
 windows_nat_target::process_thread ()
 {
@@ -507,9 +518,7 @@ windows_nat_target::process_thread ()
 		     immediately when the user tries to resume the execution
 		     in the inferior.  This is a classic race that we should
 		     try to fix one day.  */
-	      SetConsoleCtrlHandler (&ctrl_c_handler, TRUE);
-	      wait_for_debug_event (&m_last_debug_event, INFINITE);
-	      SetConsoleCtrlHandler (&ctrl_c_handler, FALSE);
+	      wrap_wait_for_debug_event (&m_last_debug_event, INFINITE);
 	      m_debug_event_pending = true;
 	    }
 	  serial_event_set (m_wait_event);
@@ -537,11 +546,7 @@ windows_nat_target::wait_for_debug_event_main_thread (DEBUG_EVENT *event)
 	  serial_event_clear (m_wait_event);
 	}
       else
-	{
-	  SetConsoleCtrlHandler (&ctrl_c_handler, TRUE);
-	  wait_for_debug_event (event, INFINITE);
-	  SetConsoleCtrlHandler (&ctrl_c_handler, FALSE);
-	}
+	wrap_wait_for_debug_event (event, INFINITE);
       return false;
     });
 }
@@ -1558,9 +1563,14 @@ ctrl_c_handler (DWORD event_type)
 {
   const int attach_flag = current_inferior ()->attach_flag;
 
+  fprintf (stderr, "+++ ctrl_c_handler, attach = %d\n", attach_flag);
+
   /* Only handle Ctrl-C and Ctrl-Break events.  Ignore others.  */
   if (event_type != CTRL_C_EVENT && event_type != CTRL_BREAK_EVENT)
     return FALSE;
+  fprintf (stderr, "+++ ctrl_c_handler, event type ok, new_console = %d, type = %s\n",
+	   (int) new_console,
+	   event_type == CTRL_C_EVENT ? "control-c" : "BREAK");
 
   /* If the inferior and the debugger share the same console, do nothing as
      the inferior has also received the Ctrl-C event.  */

  reply	other threads:[~2022-12-02 16:12 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20221128191526.1426-1-ssbssa.ref@yahoo.de>
2022-11-28 19:15 ` Hannes Domani
2022-12-01 17:30   ` Tom Tromey
2022-12-01 19:06     ` Hannes Domani
2022-12-01 21:22       ` Tom Tromey
2022-12-02 16:12         ` Tom Tromey [this message]
2022-12-02 22:22           ` Tom Tromey
2022-12-02 22:51             ` Hannes Domani
2022-12-05 18:54               ` 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=87o7sllr7j.fsf@tromey.com \
    --to=tromey@adacore.com \
    --cc=gdb-patches@sourceware.org \
    --cc=ssbssa@yahoo.de \
    /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).