From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id JxgaE4JxzGCoRwAAWB0awg (envelope-from ) for ; Fri, 18 Jun 2021 06:12:18 -0400 Received: by simark.ca (Postfix, from userid 112) id 3FA911F163; Fri, 18 Jun 2021 06:12:18 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-0.7 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,RDNS_DYNAMIC,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id F01781E939 for ; Fri, 18 Jun 2021 06:12:16 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 61C7B39DC4C7 for ; Fri, 18 Jun 2021 10:12:16 +0000 (GMT) Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by sourceware.org (Postfix) with ESMTPS id AD4D8384F014 for ; Fri, 18 Jun 2021 10:12:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org AD4D8384F014 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embecosm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=embecosm.com Received: by mail-wr1-x42f.google.com with SMTP id d11so7761082wrm.0 for ; Fri, 18 Jun 2021 03:12:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=PQH5QQYFVq7DyJD/zeJzypt/Omc8fHfQEGZU0tSdRjc=; b=A8GBJMKWLve9SXCOcNcCAeMa5OoBoZ1hPwj/L710RlaYAQwcCddeg3FUZV8oph/kxC 2iCSCgIAQuHDHNEOrXEhgxs6koPM2EF53TpC0H4hE0beMZ8GtklaZB9alX4QDHbzQ3Gb xKxVQ65yPIVNsHHzoH/EFBDco0QpUJm/B4e8ICdw0FluH8GxE+dzUR8I+LP8Ki8H6aR1 rcvKDKLZKyPjCJX2TCvtPSF8DFhu5NwCsOu1PX39/cAMjMSI33WaykdBidg0CLb/lZYQ 2qRbDm1kl5ZAmtbWoCKfBQ0C1Oarx4KfFQGl5gorFX8KyXlEqChlSAEUBR+WRTla3bDm gPXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=PQH5QQYFVq7DyJD/zeJzypt/Omc8fHfQEGZU0tSdRjc=; b=NEesbr+L0CCSNstfWS8+XCGvMJEmROy39BIXKu5Av8hGcPenVtzH7hdj76DB+8WXNP h7jHxw6GsH34Y5pDSJlannqIHcZqZXlMxG0S931BXLQM60UDaMSUFUiwAfrHHRuZtWXI eTlTIqXkFRfsrlTb7DFYjaWh+JVUZXjZ16Ti+cqKig5I2XR6T6PrxBYv3lDWzPo/Pc6c 4/yD62GYpHhQzVvVCs66+Tdzsw6R3H88hdxff+HKwlyE1z+6BZ93GpD9WW75mGEq/TT1 A8EecTR0Rp3EfZDRkvT0kaI2v1N09QweI25eJSpVAnCEGivMEaS0T6gnOP0IRm7t08/c CqiA== X-Gm-Message-State: AOAM532bWU7US40vXU6qGPaEZ5bgcQqUDZSvNFs/3pNIRSYfFYyRHvPn MduwkV6Ka/V7HSyqSXMFGBsHlAJkoF35CG2M X-Google-Smtp-Source: ABdhPJzm/xTyfBp6tlfG5v5TTd2Q2FELYT7K9Uuo0c+bl63wjOA6gSOoC7A8DieT++HX9lVEYGQieQ== X-Received: by 2002:a5d:59ae:: with SMTP id p14mr11173529wrr.188.1624011122981; Fri, 18 Jun 2021 03:12:02 -0700 (PDT) Received: from localhost (host86-140-92-85.range86-140.btcentralplus.com. [86.140.92.85]) by smtp.gmail.com with ESMTPSA id p12sm9958218wme.43.2021.06.18.03.12.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Jun 2021 03:12:02 -0700 (PDT) Date: Fri, 18 Jun 2021 11:12:01 +0100 From: Andrew Burgess To: Pedro Alves Subject: Re: [PATCH v2 00/16] Interrupting programs that block/ignore SIGINT Message-ID: <20210618101201.GA2568@embecosm.com> References: <20210614212410.1612666-1-pedro@palves.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210614212410.1612666-1-pedro@palves.net> X-Operating-System: Linux/5.8.18-100.fc31.x86_64 (x86_64) X-Uptime: 10:43:46 up 1 day, 17:35, X-Editor: GNU Emacs [ http://www.gnu.org/software/emacs ] X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: gdb-patches@sourceware.org Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" Pedro, This change looks awesome! I've wanted this for a long time now, so glad it might finally arrive. I have a question for a slightly related topic. I don't think this needs resolving prior to this series landing, but it might be worth having a discussion about what the solution might be within this new setup. I was recently looking at signal handling in general, and started looking at how SIGTSTP is handled, for example, as might be delivered by Ctrl-Z from a terminal. My interest in this started by looking at async_sigtstp_handler in event-top.c, I noticed at the end of this function there is code to reprint the prompt, which should be run after GDB is resumed, after a stop. However, right now, this is not the case. When the terminal is claimed by GDB then, when GDB is stopped and resumed, no prompt is printed. On digging into this, the problem is that the SIGTSTP handler is only installed for the duration of command_line_input, which is the non-async command line parser. So, my initial plan was to removed the SIGTSTP handling from command_line_input, and instead have the code which switches terminal ownership install/remove the SIGTSTP handler... ...but then I realised, that if GDB doesn't own the terminal the SIGTSTP should be sent directly to the inferior anyway, right? So, then my plan became, lets just install the SIGTSTP handler right from the start, and this seems to work fine before your changes (there are still some bugs to work out relating to printing the correct prompt in all cases, and reprinting any partial read line input that might have been in place, but these issues can be ignored for this discussion). The problem then is what should happen after your work is applied? The patch below applies on top of your work, and demonstrates the problem, when GDB owns the terminal stop/resume works fine: (gdb) [1]+ Stopped ./gdb/gdb --data-directory ./gdb/data-directory/ ~/tmp/loop.x $ fg ./gdb/gdb --data-directory ./gdb/data-directory/ ~/tmp/loop.x (gdb) But as the inferior never really takes over the terminal any more, it's not clear to me what we should do? One idea I've had is to just make SIGTSTP interrupt the inferior just like SIGINT does. This would drop the user back to a prompt, at which point the user could send SIGTSTP again if they then wanted GDB itself to stop. Look forward to hearing your thoughts, Thanks, Andrew --- diff --git a/gdb/event-top.c b/gdb/event-top.c index 9741b23576a..d609d73a016 100644 --- a/gdb/event-top.c +++ b/gdb/event-top.c @@ -962,6 +962,7 @@ async_init_signals (void) #ifdef SIGTSTP sigtstp_token = create_async_signal_handler (async_sigtstp_handler, NULL, "sigtstp"); + signal (SIGTSTP, handle_sigtstp); #endif install_handle_sigsegv (); @@ -1182,27 +1183,34 @@ handle_sigtstp (int sig) static void async_sigtstp_handler (gdb_client_data arg) { - char *prompt = get_prompt (); + if (!target_terminal::is_ours ()) + { + fprintf (stderr, "TODO: Not really sure what we should do here.\n"); + } + else + { + char *prompt = get_prompt (); - signal (SIGTSTP, SIG_DFL); + signal (SIGTSTP, SIG_DFL); #if HAVE_SIGPROCMASK - { - sigset_t zero; + { + sigset_t zero; - sigemptyset (&zero); - gdb_sigmask (SIG_SETMASK, &zero, 0); - } + sigemptyset (&zero); + gdb_sigmask (SIG_SETMASK, &zero, 0); + } #elif HAVE_SIGSETMASK - sigsetmask (0); + sigsetmask (0); #endif - raise (SIGTSTP); - signal (SIGTSTP, handle_sigtstp); - printf_unfiltered ("%s", prompt); - gdb_flush (gdb_stdout); + raise (SIGTSTP); + signal (SIGTSTP, handle_sigtstp); + fprintf_unfiltered (gdb_stdout, "%s%s", prompt, rl_line_buffer); + gdb_flush (gdb_stdout); - /* Forget about any previous command -- null line now will do - nothing. */ - dont_repeat (); + /* Forget about any previous command -- null line now will do + nothing. */ + dont_repeat (); + } } #endif /* SIGTSTP */ diff --git a/gdb/top.c b/gdb/top.c index 6e0f43d2fd9..876546c023f 100644 --- a/gdb/top.c +++ b/gdb/top.c @@ -1325,11 +1325,6 @@ command_line_input (const char *prompt_arg, const char *annotation_suffix) /* Starting a new command line. */ cmd_line_buffer.used_size = 0; -#ifdef SIGTSTP - if (job_control) - signal (SIGTSTP, handle_sigtstp); -#endif - while (1) { gdb::unique_xmalloc_ptr rl; @@ -1385,11 +1380,6 @@ command_line_input (const char *prompt_arg, const char *annotation_suffix) prompt = NULL; } -#ifdef SIGTSTP - if (job_control) - signal (SIGTSTP, SIG_DFL); -#endif - return cmd; }