From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11934 invoked by alias); 7 May 2008 20:56:37 -0000 Received: (qmail 11918 invoked by uid 22791); 7 May 2008 20:56:35 -0000 X-Spam-Check-By: sourceware.org Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.31) with ESMTP; Wed, 07 May 2008 20:56:15 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 0FE842A99B8 for ; Wed, 7 May 2008 16:56:14 -0400 (EDT) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id zqKwYpBMtzob for ; Wed, 7 May 2008 16:56:14 -0400 (EDT) Received: from joel.gnat.com (localhost.localdomain [127.0.0.1]) by rock.gnat.com (Postfix) with ESMTP id 9A4FB2A99A8 for ; Wed, 7 May 2008 16:56:13 -0400 (EDT) Received: by joel.gnat.com (Postfix, from userid 1000) id 758FCE7ACD; Wed, 7 May 2008 13:56:11 -0700 (PDT) Date: Thu, 08 May 2008 09:46:00 -0000 From: Joel Brobecker To: gdb-patches@sourceware.org Subject: [RFC] control-c handling on Windows... Message-ID: <20080507205611.GB7421@adacore.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="WIyZ46R2i8wDzkSu" Content-Disposition: inline User-Agent: Mutt/1.4.2.2i Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2008-05/txt/msg00270.txt.bz2 --WIyZ46R2i8wDzkSu Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-length: 2308 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 --WIyZ46R2i8wDzkSu Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="win32-nat.c.diff" Content-length: 539 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 --WIyZ46R2i8wDzkSu--