From patchwork Tue Jan 26 13:54:47 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yao Qi X-Patchwork-Id: 10632 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-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 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:54:47 +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 X-IsSubscribed: yes 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 = 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 (); > > I think it's safer practice to block the signal before > installing the handler. OK, and fixed. > > Otherwise LGTM. Patch below is pushed in. 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 + * 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. 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); +#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); } -/* 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. */ static void -unblock_async_io (void) +block_unblock_async_io (int block) { #ifndef USE_WIN32API sigset_t sigio_set; sigemptyset (&sigio_set); sigaddset (&sigio_set, SIGIO); - sigprocmask (SIG_UNBLOCK, &sigio_set, NULL); + sigprocmask (block ? SIG_BLOCK : SIG_UNBLOCK, &sigio_set, NULL); #endif } @@ -823,9 +828,8 @@ enable_async_io (void) if (async_io_enabled) return; -#ifndef USE_WIN32API - signal (SIGIO, input_interrupt); -#endif + block_unblock_async_io (0); + async_io_enabled = 1; #ifdef __QNX__ nto_comctrl (1); @@ -839,9 +843,8 @@ disable_async_io (void) if (!async_io_enabled) return; -#ifndef USE_WIN32API - signal (SIGIO, SIG_IGN); -#endif + block_unblock_async_io (1); + async_io_enabled = 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 = 1; disable_async_io (); - /* Make sure the signal is unblocked. */ - unblock_async_io (); + /* Install the signal handler. */ +#ifndef USE_WIN32API + signal (SIGIO, input_interrupt); +#endif } /* Internal buffer used by readchar.