Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Joel Brobecker <brobecker@adacore.com>
To: gdb-patches@sourceware.org
Subject: [RFC] control-c handling on Windows...
Date: Thu, 08 May 2008 09:46:00 -0000	[thread overview]
Message-ID: <20080507205611.GB7421@adacore.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 2308 bytes --]

Hello,

We noticed the following anomaly when trying to interrupt the inferior
with a control-c event:

(gdb) run
Starting program: C:\[...]/always.exe
[New thread 6772.0xadc]
Hello world: 1
Hello world: 2
[New thread 6772.0x13fc]
[Switching to thread 6772.0x13fc]
Quit (expect signal SIGINT when the program is resumed)
(gdb)

The debugger stopped but doesn't show the usual "Program received
SIGINT [...]" message. It almost looks like the debugger stopped
because of the new thread.

Also, the "Quit (expect signal SIGINT when the program is resumed)"
message is indeed right. When I do a "continue", I immediately get
the SIGINT:

    (gdb) c
    Continuing.
    Hello world: 3
    Program received signal SIGINT, Interrupt.
    0x7c87534d in KERNEL32!GetConsoleCharType ()
       from C:\WINDOWS\system32\kernel32.dll
    (gdb)

In fact, what happened was that GDB received a SIGINT event,
and as such set the quit_flag. At the same time, the inferior
received the control-c event as well, and therefore created
a new thread to handle it. That new thread generated an event
intercepted by GDB; after GDB updated its thread list, it tried
to resume the execution. However, there is a QUIT at the very
beginning of resume which, because of quit_flag being set,
aborted the resume action. This is why GDB stopped the first
time instead of resuming until we get the control-c exception
event.

I think this is happening because of a change that was made a year
ago which adds a call to target_terminal_ours at the beginning of
win32_wait().  As a result, the SIGINT handler gets reactivated while
the inferior is running.  This change was made because TUI apparently
does some output while the terminal process group is set to the inferior
process.

For now, the attached patch seems to work around the issue, but
I'm a little suspicious of grabing the terminal while we're waiting
for an event. (I will add more comment in my patch when the situation
is a little clarified).

Opinions? For reference, the target_terminal_ours patch is:

        * win32-nat.c (win32_wait): Reset terminal pgrp to GDB.
        (do_initial_win32_stuff): Call terminal_init_inferior_with_pgrp
        instead of target_terminal_init since inferior_ptid isn't set yet.

and it was checked in on Feb 12, 2007.

Thanks,
-- 
Joel

[-- Attachment #2: win32-nat.c.diff --]
[-- Type: text/plain, Size: 539 bytes --]

Index: win32-nat.c
===================================================================
--- win32-nat.c	(revision 130731)
+++ win32-nat.c	(working copy)
@@ -1467,7 +1467,13 @@ win32_wait (ptid_t ptid, struct target_w
 
   while (1)
     {
-      int retval = get_win32_debug_event (pid, ourstatus);
+      int retval;
+      void (*ofunc) (int);
+
+      ofunc = signal (SIGINT, SIG_IGN);
+      retval = get_win32_debug_event (pid, ourstatus);
+      signal (SIGINT, ofunc);
+
       if (retval)
 	return pid_to_ptid (retval);
       else

             reply	other threads:[~2008-05-07 20:56 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-05-08  9:46 Joel Brobecker [this message]
2008-05-10  4:34 ` Christopher Faylor
2008-05-10 13:10   ` Joel Brobecker
2008-05-10 15:31     ` Christopher Faylor
2008-05-10 22:28       ` Joel Brobecker
2008-05-11  5:30         ` Christopher Faylor
2008-05-11 13:31         ` Joel Brobecker
2008-05-11 13:46           ` Eli Zaretskii
2008-05-11 13:58           ` Christopher Faylor
2008-05-11 21:26             ` Joel Brobecker
2008-05-17 11:38               ` Christopher Faylor
2008-05-21  0:34                 ` Joel Brobecker
2008-05-21  3:19                   ` Christopher Faylor

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=20080507205611.GB7421@adacore.com \
    --to=brobecker@adacore.com \
    --cc=gdb-patches@sourceware.org \
    /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