From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2837 invoked by alias); 6 Feb 2009 16:43:05 -0000 Received: (qmail 2823 invoked by uid 22791); 6 Feb 2009 16:43:04 -0000 X-SWARE-Spam-Status: No, hits=-2.4 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 06 Feb 2009 16:42:59 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id EB4292A9730; Fri, 6 Feb 2009 11:42:57 -0500 (EST) 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 VExTF96henz4; Fri, 6 Feb 2009 11:42:57 -0500 (EST) Received: from joel.gnat.com (localhost.localdomain [127.0.0.1]) by rock.gnat.com (Postfix) with ESMTP id 6A3252A972A; Fri, 6 Feb 2009 11:42:57 -0500 (EST) Received: by joel.gnat.com (Postfix, from userid 1000) id 6AA46E7ACD; Fri, 6 Feb 2009 08:42:54 -0800 (PST) Date: Fri, 06 Feb 2009 16:43:00 -0000 From: Joel Brobecker To: "Amker.Cheng" Cc: gdb@sourceware.org, paawan1982@yahoo.com, teawater Subject: Re: What happened in gdb between handle_sigint and async_request_quit? Message-ID: <20090206164254.GZ3683@adacore.com> References: <308806.32791.qm@web36206.mail.mud.yahoo.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.4.2.2i Mailing-List: contact gdb-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sourceware.org X-SW-Source: 2009-02/txt/msg00065.txt.bz2 > both of GDB and Debuggee will get the event. Windows will report DBG_CONTROL_C > exception to GDB, which was turned into TARGET_SIGNAL_INT in GDB. > According to MSDN, this is the First Chance Exception! The situation on Windows is different from the situation on Unix. On Unix, we give the terminal back to the inferior while the inferior is running. So, when a user presses Ctrl-c, only the inferior gets the signal. This signal triggers a debug event to GDB and suspends the inferior, and GDB treats this signal as it would treat any other signal. On Windows, things are a little trickier, because the inferior and GDB might be running in the same console. This means that, when the user presses Ctrl-c, then *both* GDB and the inferior get the associated signal. But we don't actually want GDB to receive the signal, so we simply temporarily ignore all Ctrl-C signals in GDB while the inferior is waiting: /* Ignore CTRL+C signals while waiting for a debug event. FIXME: brobecker/2008-05-20: When the user presses CTRL+C while the inferior is running, both the inferior and GDB receive the associated signal. If the inferior receives the signal first and the delay until GDB receives that signal is sufficiently long, GDB can sometimes receive the SIGINT after we have unblocked the CTRL+C handler. This would lead to the debugger to stop prematurely while handling the new-thread event that comes with the handling of the SIGINT inside the inferior, and then stop again immediately when the user tries to resume the execution in the inferior. This is a classic race, and it would be nice to find a better solution to that problem. But in the meantime, the current approach already greatly mitigate this issue. */ SetConsoleCtrlHandler (NULL, TRUE); retval = get_windows_debug_event (pid, ourstatus); SetConsoleCtrlHandler (NULL, FALSE); The code above assumes that the inferior and GDB are running in the same console, which is not always the case. Currently, when this is the case, the only way to interrupt your program is by pressing Ctrl-c in the console where your program is running. There is patch pending that enhances GDB to handle the case when the inferior is running in a separate console. -- Joel