From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23817 invoked by alias); 11 Jan 2012 21:15:04 -0000 Received: (qmail 23745 invoked by uid 22791); 11 Jan 2012 21:15:02 -0000 X-SWARE-Spam-Status: No, hits=-7.0 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_HI,SPF_HELO_PASS,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 11 Jan 2012 21:14:49 +0000 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q0BLEkah005417 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 11 Jan 2012 16:14:46 -0500 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q0BLEk9n015764; Wed, 11 Jan 2012 16:14:46 -0500 Received: from barimba (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id q0BLEiL2010847; Wed, 11 Jan 2012 16:14:45 -0500 From: Tom Tromey To: Cc: , , Subject: Re: Handle SIGINT in Python References: <09787EF419216C41A903FD14EE5506DD030F1EAD9E@AUSX7MCPC103.AMER.DELL.COM> Date: Wed, 11 Jan 2012 21:23:00 -0000 In-Reply-To: <09787EF419216C41A903FD14EE5506DD030F1EAD9E@AUSX7MCPC103.AMER.DELL.COM> (Paul Koning's message of "Wed, 11 Jan 2012 15:03:08 -0600") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.92 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain 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 X-SW-Source: 2012-01/txt/msg00374.txt.bz2 >>>>> "Paul" == writes: Paul> To get what you're asking (C-c work like in non-Python settings in Paul> GDB) all that would be needed is for the interpreter top level to Paul> check for specifically the KeyboardInterrupt exception and give that Paul> to the GDB C-c handler, rather than printing the default exception Paul> traceback. It would still do that for other (non-interrupt) Paul> exceptions. I think there are basically 2 cases to consider: does the SIGINT arrive in Python code, or in GDB code? In GDB code, the SIGINT handler should be handle_sigint. (AFAIK -- there may be other situations, and I'm not familiar with all of them). This sets quit_flag. Then, appropriate spots in GDB invoke QUIT, which checks this flag and calls 'fatal' if it is set. fatal just throws a RETURN_QUIT exception. In Python code, is the SIGINT handler. I believe it calls PyErr_SetInterrupt. Then Python does something similar: it checks this flag periodically and turns it into a KeyboardInterrupt exception. We are already pretty good at converting GDB exceptions to Python exceptions. gdbpy_convert_exception handles the RETURN_QUIT -> KeyboardInterrupt case already. We are pretty bad at converting Python exceptions to GDB exceptions. See: http://sourceware.org/bugzilla/show_bug.cgi?id=12174 This is the problem where we lose information in exception round-trips. So, one idea would be to make this better: fix the round-trip problem, and convert KeyboardInterrupt to RETURN_QUIT, then find all the Python->GDB boundaries and make them deal with this as appropriate. Perhaps we could also just have a single SIGINT handler that can handle all cases. I am not sure. Tom