From patchwork Tue Jan 26 09:58:59 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yao Qi X-Patchwork-Id: 10629 Received: (qmail 57239 invoked by alias); 26 Jan 2016 09:59:15 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 57105 invoked by uid 89); 26 Jan 2016 09:59:14 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.6 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 spammy=40211, 402, 11, Control-C, ControlC X-HELO: mail-pf0-f195.google.com Received: from mail-pf0-f195.google.com (HELO mail-pf0-f195.google.com) (209.85.192.195) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Tue, 26 Jan 2016 09:59:11 +0000 Received: by mail-pf0-f195.google.com with SMTP id e65so8124102pfe.0 for ; Tue, 26 Jan 2016 01:59:11 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=9DI4aCVSPPnNRsCTFNVODGNGRf5oQ01/VEMVGWB6lqg=; b=muyD7ZdjzCp/DgtqGVbXWNvLJCPAU4ty3rsFqSE4hn94t+S2K7CYGo+r1DmwQZvD97 5MaQWFRPG/Siw2TT2RXSoQaB7crAkDyScLjScoetOfiVBquAQgabbHQvZj6rPGdg11vN +14ty9/iMPQGssnk8lj74LF90Gw8LQSbhrm9p9A7/HligG7viRz4Mq3XXtUNrj3BeY6L oo6GwQLX4fZRBjH2EB8ZTQ+6hB7DxrhyUUIJYdmF5zeohqxKgWnuo25S66lTp+IW806E /7VWADk9qVUKqhrqccXa7+/Y0row93vGJCaYMyK3xLWBTYdpTKsM76wg7F784T7wU92J s2Tg== X-Gm-Message-State: AG10YOQIZyono5CNaDh1P5UiYg/32/8nvIGzzIX+Hukp3iqtlVpJVAUq48YQyUL8eT38JQ== X-Received: by 10.98.75.143 with SMTP id d15mr32732558pfj.96.1453802349989; Tue, 26 Jan 2016 01:59:09 -0800 (PST) Received: from E107787-LIN.cambridge.arm.com (gcc1-power7.osuosl.org. [140.211.15.137]) by smtp.gmail.com with ESMTPSA id 83sm900187pft.44.2016.01.26.01.59.08 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 26 Jan 2016 01:59:09 -0800 (PST) From: Yao Qi X-Google-Original-From: Yao Qi To: gdb-patches@sourceware.org Subject: [PATCH 2/2] [GDBserver] Block and unblock SIGIO Date: Tue, 26 Jan 2016 09:58:59 +0000 Message-Id: <1453802339-20401-3-git-send-email-yao.qi@linaro.org> In-Reply-To: <1453802339-20401-1-git-send-email-yao.qi@linaro.org> References: <86powqqa57.fsf@gmail.com> <1453802339-20401-1-git-send-email-yao.qi@linaro.org> X-IsSubscribed: yes Nowadays, GDBserver disables async io (by ignoring SIGIO) when process a serial event, and enables async io (by installing signal handler) when resume the inferior and wait. GDBserver may miss SIGIO (by interrupt) and doesn't process SIGIO in time, which is shown by gdb.base/interrupt-noterm.exp. In the test, GDB sends "continue &" and then "interrupt". if '\003' arrives at a period between GDBserver receives vCont;c and enables async io, SIGIO is ignored because signal handler isn't installed. GDBserver waits for the inferior and can not notice '\003' until it returns from wait. This patch changes the code to install SIGIO handler early, but block and unblock SIGIO as needed. In this way, we don't remove SIGIO handler, so SIGIO can't be ignored. However, GDBserver needs to remove the signal handler when connection is closed. gdb/gdbserver: 2016-01-26 Yao Qi * remote-utils.c (remote_close) [!USE_WIN32API]: Ignore SIGIO. (unblock_async_io): Remove. (enable_async_io): Don't install SIGIO handler. Unblock it instead. (disable_async_io): Don't ignore SIGIO. Block it instead. (initialize_async_io): Install SIGIO handler. Don't call unblock_async_io. --- gdb/gdbserver/remote-utils.c | 51 ++++++++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 21 deletions(-) diff --git a/gdb/gdbserver/remote-utils.c b/gdb/gdbserver/remote-utils.c index 000457d..541675a 100644 --- a/gdb/gdbserver/remote-utils.c +++ b/gdb/gdbserver/remote-utils.c @@ -402,6 +402,11 @@ remote_close (void) { delete_file_handler (remote_desc); +#ifndef USE_WIN32API + /* Remove SIGIO handler. */ + signal (SIGIO, SIG_IGN); +#endif + #ifdef USE_WIN32API closesocket (remote_desc); #else @@ -775,21 +780,9 @@ check_remote_input_interrupt_request (void) input_interrupt (0); } -/* Asynchronous I/O support. SIGIO must be enabled when waiting, in order to - accept Control-C from the client, and must be disabled when talking to - the client. */ - -static void -unblock_async_io (void) -{ -#ifndef USE_WIN32API - sigset_t sigio_set; - - sigemptyset (&sigio_set); - sigaddset (&sigio_set, SIGIO); - sigprocmask (SIG_UNBLOCK, &sigio_set, NULL); -#endif -} +/* Asynchronous I/O support. SIGIO must be unblocked when waiting, + in order to accept Control-C from the client, and must be blocked + when talking to the client. */ #ifdef __QNX__ static void @@ -820,12 +813,19 @@ static int async_io_enabled; void enable_async_io (void) { +#ifndef USE_WIN32API + sigset_t sigio_set; +#endif + if (async_io_enabled) return; #ifndef USE_WIN32API - signal (SIGIO, input_interrupt); + sigemptyset (&sigio_set); + sigaddset (&sigio_set, SIGIO); + sigprocmask (SIG_UNBLOCK, &sigio_set, NULL); #endif + async_io_enabled = 1; #ifdef __QNX__ nto_comctrl (1); @@ -836,12 +836,19 @@ enable_async_io (void) void disable_async_io (void) { +#ifndef USE_WIN32API + sigset_t sigio_set; +#endif + if (!async_io_enabled) return; #ifndef USE_WIN32API - signal (SIGIO, SIG_IGN); + sigemptyset (&sigio_set); + sigaddset (&sigio_set, SIGIO); + sigprocmask (SIG_BLOCK, &sigio_set, NULL); #endif + async_io_enabled = 0; #ifdef __QNX__ nto_comctrl (0); @@ -852,12 +859,14 @@ disable_async_io (void) void initialize_async_io (void) { - /* Make sure that async I/O starts disabled. */ + /* Install the signal handler. */ +#ifndef USE_WIN32API + signal (SIGIO, input_interrupt); +#endif + + /* Make sure that async I/O starts blocked. */ async_io_enabled = 1; disable_async_io (); - - /* Make sure the signal is unblocked. */ - unblock_async_io (); } /* Internal buffer used by readchar.