From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21699 invoked by alias); 15 Nov 2018 13:55:25 -0000 Mailing-List: contact gdb-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sourceware.org Received: (qmail 21679 invoked by uid 89); 15 Nov 2018 13:55:24 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=intercept, No, H*f:sk:17a7ce8, H*i:sk:17a7ce8 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 15 Nov 2018 13:55:22 +0000 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1F6501561A; Thu, 15 Nov 2018 13:55:21 +0000 (UTC) Received: from [127.0.0.1] (ovpn04.gateway.prod.ext.ams2.redhat.com [10.39.146.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 15A326148D; Thu, 15 Nov 2018 13:55:19 +0000 (UTC) Subject: Re: GDB (not) handling SIGINT...? To: Simon Marchi , paul@mad-scientist.net References: <8003dfcd98e9a4d1e43f53220e0d446669944ead.camel@mad-scientist.net> <17a7ce8aa190956bd7a8ba9bd7cdea16@polymtl.ca> Cc: gdb@sourceware.org From: Pedro Alves Message-ID: Date: Thu, 15 Nov 2018 13:55:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <17a7ce8aa190956bd7a8ba9bd7cdea16@polymtl.ca> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-SW-Source: 2018-11/txt/msg00005.txt.bz2 On 11/14/2018 10:32 PM, Simon Marchi wrote: > On 2018-11-13 17:37, Paul Smith wrote: >> Hi all; I'm using GDB 8.1 on a modern 64bit GNU/Linux system (Ubuntu >> 18.04LTS). >> >> Recently I added a call to sigtimedwait() for SIGINT into my >> (multithreaded) program and now I'm having an issue with GDB. >> >> What I want is that if I attach to my program then continue, then use >> ^C at the GDB terminal, I should get a (gdb) prompt back but I do NOT >> want the SIGINT delivered to my program to wake up my sigtimedwait() >> call (because it will cause my program to do various things that I >> don't want it to do). >> >> I see that SIGINT is set to nopass: >> >>   (gdb) info signals SIGINT >>   Signal        Stop      Print   Pass to program Description >>   SIGINT        Yes       Yes     No              Interrupt >> >> but yet when I use ^C at the GDB prompt my sigtimedwait() call inside >> my program does return with "2" (SIGINT), which I don't want. >> >> I guess I don't understand what the docs mean when they say that the >> signal is not passed to the process under debug.  Note that in my case >> I'm attaching to the program from a completely different terminal so >> there's no issue with process groups etc. and as far as I can >> understand it, the signal should only be delivered to GDB not my >> process, so unless there's some weird magic at work here it must be GDB >> forwarding that signal to my process. >> >> Anyone have any thoughts about this? >> >> Cheers! > > I was able to reproduce it with, it really sounds like a bug. > > If others want to try, here's my test program: > > #include > #include > #include > > int main() > { >     sigset_t set; >     sigemptyset(&set); >     sigaddset(&set, SIGINT); >     sigprocmask(SIG_BLOCK, &set, NULL); >     for (int i = 0; i < 10; i++) { >         int n = sigwaitinfo(&set, NULL); >         printf("signal %d\n", n); >     } > } > > > Run in a terminal, attach with GDB in another terminal, continue, then ctrl-C in GDB's terminal.  The first call to sigwaitinfo returns -1, I think it's expected as the syscall gets interrupted.  But the subsequent calls return 2, showing that indeed the process has received a SIGINT. > > Paul, could you please file a bug?  You can re-use this test program if you want. There are a few things going on here, none of it is really new, though: #1 - If your program blocks SIGINT and then uses sigwait, then GDB won't ever intercept the SIGINT, because ptrace doesn't ever see the signal. This is an ancient issue. See: https://sourceware.org/bugzilla/show_bug.cgi?id=9425 #2 - If you attach to a process instead of running it from GDB, then ctrl-c reaches gdb first, and then GDB sends/forwards a SIGINT to the child process. Normally this then causes ptrace to intercept the SIGINT, but, see #1 above. This case ("attach"), could be handled by GDB instead stopping the process with SIGTOP or even better, PTRACE_INTERRUPT. Note, TBC, would only work with attach/a separate terminal. #3 - If you run the process instead of attaching, in the same terminal as GDB, then ctrl-c reaches the inferior process first (because the inferior is put in the foreground), gdb would have no chance to do PTRACE_INTERRUPT at all. That would be fixable (combined with PTRACE_INTERRUPT) by my WIP branch here: https://github.com/palves/gdb/commits/palves/tty-always-separate-session which effectively makes the "run" case the same as the "attach" case, by always putting the inferior in a separate terminal session. Thanks, Pedro Alves