From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 67479 invoked by alias); 26 Jan 2016 13:55:01 -0000 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 Received: (qmail 67458 invoked by uid 89); 26 Jan 2016 13:55:00 -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= X-HELO: mail-pa0-f68.google.com Received: from mail-pa0-f68.google.com (HELO mail-pa0-f68.google.com) (209.85.220.68) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Tue, 26 Jan 2016 13:54:58 +0000 Received: by mail-pa0-f68.google.com with SMTP id pv5so7923106pac.0 for ; Tue, 26 Jan 2016 05:54:58 -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:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version:content-type :content-transfer-encoding; bh=ALaRn9IUKEAMhU2rV6QGxNAm5f6bBmCd1zB/q1fRU8M=; b=D36+N4s9XWoCluKzlxeGfYi+sTKhkl9URN68Vr3i8W/4dAD7AQ9oclyacXQwaJ3avQ 2anDRy+IVQr5LFf+ZJ1QHuSWXXd3X0YbLbnJNIfoWWQ3MMrXI4gYJz64gsLW47kRi/vv FAtOuM3MZg1/XQ5bnFkh3rn+5wX51WL+FCzKjb9Cr/T7NChDryvwr0F+hR8qJ8Mz7ZVB lWOA4d+0gV1TaZGtXyRy367bGz+nlNFUBk1/hxQqqSLgobB7ShN6Q3IuwUwOQRa5T5cC DhVAOi5kGkY3PjTM4X3uLOCGapsxSnSbKllN6X9Z3EwnNnB9vVlyv0mkQl9mr+y+xcOJ VfPQ== X-Gm-Message-State: AG10YOSbqWYG5DhuVOZRX8MgLqbzi8G2bErluEbBxQN8gdebmT0csfqkZZQVl5LmyOFOuQ== X-Received: by 10.66.191.104 with SMTP id gx8mr10196942pac.21.1453816496012; Tue, 26 Jan 2016 05:54:56 -0800 (PST) Received: from E107787-LIN (gcc1-power7.osuosl.org. [140.211.15.137]) by smtp.gmail.com with ESMTPSA id z87sm2170837pfi.19.2016.01.26.05.54.53 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Tue, 26 Jan 2016 05:54:55 -0800 (PST) From: Yao Qi To: Pedro Alves Cc: Yao Qi , gdb-patches@sourceware.org Subject: Re: [PATCH 2/2] [GDBserver] Block and unblock SIGIO References: <86powqqa57.fsf@gmail.com> <1453802339-20401-1-git-send-email-yao.qi@linaro.org> <1453802339-20401-3-git-send-email-yao.qi@linaro.org> <56A76003.1010308@redhat.com> Date: Tue, 26 Jan 2016 13:55:00 -0000 In-Reply-To: <56A76003.1010308@redhat.com> (Pedro Alves's message of "Tue, 26 Jan 2016 12:01:07 +0000") Message-ID: <86d1soqwd4.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes X-SW-Source: 2016-01/txt/msg00655.txt.bz2 Pedro Alves writes: > I'd suggest factoring out this duplicate sigprocmask handling, > like, say, rename unblock_async_io and add a parameter: > > /* Block or unblock SIGIO. */ > > static void > block_unblock_async_io (int block) > { > #ifndef USE_WIN32API > sigset_t sigio_set; > > sigemptyset (&sigio_set); > sigaddset (&sigio_set, SIGIO); > sigprocmask (block ? SIG_BLOCK : SIG_UNBLOCK, &sigio_set, NULL); > #endif > } Done. > >> async_io_enabled =3D 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 =3D 1; >> disable_async_io (); > > I think it's safer practice to block the signal before > installing the handler. OK, and fixed. > > Otherwise LGTM. Patch below is pushed in. --=20 Yao (=E9=BD=90=E5=B0=A7) =46rom 8b2073398477b33d425b0570236fe4e4222fe2c4 Mon Sep 17 00:00:00 2001 From: Yao Qi Date: Tue, 26 Jan 2016 13:50:22 +0000 Subject: [PATCH] [GDBserver] Block and unblock SIGIO 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): Rename to ... (block_unblock_async_io): ... it. New function. (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. diff --git a/gdb/gdbserver/ChangeLog b/gdb/gdbserver/ChangeLog index 4aa7350..0ba902e 100644 --- a/gdb/gdbserver/ChangeLog +++ b/gdb/gdbserver/ChangeLog @@ -1,5 +1,16 @@ 2016-01-26 Yao Qi =20 + * remote-utils.c (remote_close) [!USE_WIN32API]: Ignore SIGIO. + (unblock_async_io): Rename to ... + (block_unblock_async_io): ... it. New function. + (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. + +2016-01-26 Yao Qi + * remote-utils.c (getpkt): If the buffer isn't empty, and the first character is '\003', call *the_target->request_interrupt. =20 diff --git a/gdb/gdbserver/remote-utils.c b/gdb/gdbserver/remote-utils.c index ccc99f1..e751473 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); =20 +#ifndef USE_WIN32API + /* Remove SIGIO handler. */ + signal (SIGIO, SIG_IGN); +#endif + #ifdef USE_WIN32API closesocket (remote_desc); #else @@ -775,19 +780,19 @@ check_remote_input_interrupt_request (void) input_interrupt (0); } =20 -/* 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. */ +/* 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. */ =20 static void -unblock_async_io (void) +block_unblock_async_io (int block) { #ifndef USE_WIN32API sigset_t sigio_set; =20 sigemptyset (&sigio_set); sigaddset (&sigio_set, SIGIO); - sigprocmask (SIG_UNBLOCK, &sigio_set, NULL); + sigprocmask (block ? SIG_BLOCK : SIG_UNBLOCK, &sigio_set, NULL); #endif } =20 @@ -823,9 +828,8 @@ enable_async_io (void) if (async_io_enabled) return; =20 -#ifndef USE_WIN32API - signal (SIGIO, input_interrupt); -#endif + block_unblock_async_io (0); + async_io_enabled =3D 1; #ifdef __QNX__ nto_comctrl (1); @@ -839,9 +843,8 @@ disable_async_io (void) if (!async_io_enabled) return; =20 -#ifndef USE_WIN32API - signal (SIGIO, SIG_IGN); -#endif + block_unblock_async_io (1); + async_io_enabled =3D 0; #ifdef __QNX__ nto_comctrl (0); @@ -852,12 +855,14 @@ disable_async_io (void) void initialize_async_io (void) { - /* Make sure that async I/O starts disabled. */ + /* Make sure that async I/O starts blocked. */ async_io_enabled =3D 1; disable_async_io (); =20 - /* Make sure the signal is unblocked. */ - unblock_async_io (); + /* Install the signal handler. */ +#ifndef USE_WIN32API + signal (SIGIO, input_interrupt); +#endif } =20 /* Internal buffer used by readchar.