From patchwork Thu May 16 15:51:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Hayward X-Patchwork-Id: 32717 Received: (qmail 34275 invoked by alias); 16 May 2019 15:51:59 -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 34266 invoked by uid 89); 16 May 2019 15:51:58 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-24.0 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, MIME_BASE64_BLANKS, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.1 spammy=blocked, sk:alan.ha, alanhaywardarmcom, alan.hayward@arm.com X-HELO: EUR01-VE1-obe.outbound.protection.outlook.com Received: from mail-eopbgr140083.outbound.protection.outlook.com (HELO EUR01-VE1-obe.outbound.protection.outlook.com) (40.107.14.83) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 16 May 2019 15:51:57 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=6C4j31ENZkuhIMHTjsbPr2RfzYExbxg5QiXim2DQouM=; b=3ZFElA0u4YOK5zjux7v1sBOx2/xEigsH/Zg8F8LQ82LaODnUUqMyPqMGj752KYZ7Lsm5MZZT5xBGW6hJyZelRWI95J2CKH65dKWHYHB3mMs+PdBtGRWT/ZEbVrOXEkLjHosReh8U8ZdV19IUnQtl/3RQoRRizIP4mE3qsknRhFg= Received: from DB6PR0802MB2133.eurprd08.prod.outlook.com (10.172.227.22) by DB6PR0802MB2614.eurprd08.prod.outlook.com (10.172.246.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1900.16; Thu, 16 May 2019 15:51:53 +0000 Received: from DB6PR0802MB2133.eurprd08.prod.outlook.com ([fe80::8c26:bb4b:6c93:9d40]) by DB6PR0802MB2133.eurprd08.prod.outlook.com ([fe80::8c26:bb4b:6c93:9d40%2]) with mapi id 15.20.1900.010; Thu, 16 May 2019 15:51:53 +0000 From: Alan Hayward To: "gdb-patches@sourceware.org" CC: nd , Alan Hayward Subject: [PATCH] Supress SIGTTOU when handling errors Date: Thu, 16 May 2019 15:51:53 +0000 Message-ID: <20190516155150.71826-1-alan.hayward@arm.com> authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alan.Hayward@arm.com; x-ms-oob-tlc-oobclassifiers: OLM:9508; received-spf: None (protection.outlook.com: arm.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 MIME-Version: 1.0 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-IsSubscribed: yes [I've seen this on and off over many months on AArch64 and Arm, and am assuming it isn't the intended behaviour. Not sure if this should be at tcdrain or it should be done at a higher level - eg in the terminal handling code] Calls to error () can cause SIGTTOU to send gdb to the background. For example, on an Arm build: (gdb) b main Breakpoint 1 at 0x10774: file /build/gdb/testsuite/../../../src/binutils-gdb/gdb/testsuite/gdb.base/watchpoint.c, line 174. (gdb) r Starting program: /build/gdb/testsuite/outputs/gdb.base/watchpoint/watchpoint [1]+ Stopped ../gdb ./outputs/gdb.base/watchpoint/watchpoint localhost$ fg ../gdb ./outputs/gdb.base/watchpoint/watchpoint Cannot parse expression `.L1199 4@r4'. warning: Probes-based dynamic linker interface failed. Reverting to original interface. The SIGTTOU is raised whilst inside a syscall during the call to tcdrain. Fix is to use scoped_ignore_sigttou to ensure SIGTTOU is blocked. In addition fix include comments - job_control is not included via terminal.h gdb/ChangeLog: 2019-05-15 Alan Hayward * event-top.c: Remove include comment. * inflow.c (class scoped_ignore_sigttou): Move from here... * inflow.h (class scoped_ignore_sigttou): ...to here. * ser-unix.c (hardwire_drain_output): Block SIGTTOU during drain. * top.c: Remove include comment. --- gdb/event-top.c | 2 +- gdb/inflow.c | 29 ----------------------------- gdb/inflow.h | 31 +++++++++++++++++++++++++++++++ gdb/ser-unix.c | 4 ++++ gdb/top.c | 2 +- 5 files changed, 37 insertions(+), 31 deletions(-) -- 2.20.1 (Apple Git-117) diff --git a/gdb/event-top.c b/gdb/event-top.c index 3ccf136ff1..93b7d2d28b 100644 --- a/gdb/event-top.c +++ b/gdb/event-top.c @@ -24,7 +24,7 @@ #include "inferior.h" #include "infrun.h" #include "target.h" -#include "terminal.h" /* for job_control */ +#include "terminal.h" #include "event-loop.h" #include "event-top.h" #include "interps.h" diff --git a/gdb/inflow.c b/gdb/inflow.c index 339b55c0bc..eba7a931f4 100644 --- a/gdb/inflow.c +++ b/gdb/inflow.c @@ -106,35 +106,6 @@ static serial_ttystate initial_gdb_ttystate; static struct terminal_info *get_inflow_inferior_data (struct inferior *); -/* RAII class used to ignore SIGTTOU in a scope. */ - -class scoped_ignore_sigttou -{ -public: - scoped_ignore_sigttou () - { -#ifdef SIGTTOU - if (job_control) - m_osigttou = signal (SIGTTOU, SIG_IGN); -#endif - } - - ~scoped_ignore_sigttou () - { -#ifdef SIGTTOU - if (job_control) - signal (SIGTTOU, m_osigttou); -#endif - } - - DISABLE_COPY_AND_ASSIGN (scoped_ignore_sigttou); - -private: -#ifdef SIGTTOU - sighandler_t m_osigttou = NULL; -#endif -}; - /* While the inferior is running, we want SIGINT and SIGQUIT to go to the inferior only. If we have job control, that takes care of it. If not, we save our handlers in these two variables and set SIGINT and SIGQUIT diff --git a/gdb/inflow.h b/gdb/inflow.h index c32aa14433..5dd5c37bd2 100644 --- a/gdb/inflow.h +++ b/gdb/inflow.h @@ -21,5 +21,36 @@ #define INFLOW_H #include +#include +#include "common/job-control.h" + +/* RAII class used to ignore SIGTTOU in a scope. */ + +class scoped_ignore_sigttou +{ +public: + scoped_ignore_sigttou () + { +#ifdef SIGTTOU + if (job_control) + m_osigttou = signal (SIGTTOU, SIG_IGN); +#endif + } + + ~scoped_ignore_sigttou () + { +#ifdef SIGTTOU + if (job_control) + signal (SIGTTOU, m_osigttou); +#endif + } + + DISABLE_COPY_AND_ASSIGN (scoped_ignore_sigttou); + +private: +#ifdef SIGTTOU + sighandler_t m_osigttou = NULL; +#endif +}; #endif /* inflow.h */ diff --git a/gdb/ser-unix.c b/gdb/ser-unix.c index 5a9965bf74..3492619f2d 100644 --- a/gdb/ser-unix.c +++ b/gdb/ser-unix.c @@ -32,6 +32,7 @@ #include "gdbcmd.h" #include "common/filestuff.h" #include +#include "inflow.h" struct hardwire_ttystate { @@ -164,6 +165,9 @@ hardwire_print_tty_state (struct serial *scb, static int hardwire_drain_output (struct serial *scb) { + /* Ignore SIGTTOU which may occur during the drain. */ + scoped_ignore_sigttou ignore_sigttou; + return tcdrain (scb->fd); } diff --git a/gdb/top.c b/gdb/top.c index bacd684dba..1e17ebee87 100644 --- a/gdb/top.c +++ b/gdb/top.c @@ -34,7 +34,7 @@ #include "expression.h" #include "value.h" #include "language.h" -#include "terminal.h" /* For job_control. */ +#include "terminal.h" #include "common/job-control.h" #include "annotate.h" #include "completer.h"