From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16343 invoked by alias); 12 Jan 2012 15:25:41 -0000 Received: (qmail 16329 invoked by uid 22791); 12 Jan 2012 15:25:39 -0000 X-SWARE-Spam-Status: No, hits=-2.1 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW X-Spam-Check-By: sourceware.org Received: from mail-vx0-f169.google.com (HELO mail-vx0-f169.google.com) (209.85.220.169) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 12 Jan 2012 15:25:26 +0000 Received: by vcge1 with SMTP id e1so1683397vcg.0 for ; Thu, 12 Jan 2012 07:25:25 -0800 (PST) Received: by 10.220.148.201 with SMTP id q9mr2351549vcv.33.1326381925251; Thu, 12 Jan 2012 07:25:25 -0800 (PST) MIME-Version: 1.0 Received: by 10.220.3.130 with HTTP; Thu, 12 Jan 2012 07:25:04 -0800 (PST) In-Reply-To: References: From: Kevin Pouget Date: Thu, 12 Jan 2012 15:52:00 -0000 Message-ID: Subject: Re: Handle SIGINT in Python To: Khoo Yit Phang Cc: Tom Tromey , gdb-patches@sourceware.org, Doug Evans Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes 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/msg00404.txt.bz2 On Thu, Jan 12, 2012 at 1:17 AM, Doug Evans wrote: > > On Wed, Jan 11, 2012 at 12:55 PM, Tom Tromey wrote: > >>>>>> "Doug" =3D=3D Doug Evans writes: > > > > Doug> There is value in having the SIGINT *only* affect the inferior. > > Doug> It's up to the script to handle the various reasons why the infer= ior > > Doug> may have stopped, and you don't (generally) want to interfere with > > Doug> that (by interrupting the script too). > > > > I think Python code should have to request something like this > > specially. =A0The scripting case is less usual than the interactive > > debugging (perhaps with some Python helper code) case. =A0I think it wo= uld > > be weird for the behavior the user sees, by default, to depend on > > whether Python or GDB code was active at the moment of C-c. > > I'm not sure we're talking about the same thing. > I wasn't suggesting the behaviour be different depending on whether > GDB or Python was running. > [For reference sake, to make sure we're on the same page, my comment > is solely for the case where the inferior is launched by gdb, the > inferior is running, has the terminal, and will get the SIGINT.] > > > That is, a C-c when processing a 'python' command in a breakpoint's > > 'commands' list should have the same general effect as if we were > > processing any other command. > > PTAL. Hello, just my 2 cents to the discussion. [I'm not sure I could follow all the arguments, so my comments are based on Khoo's patch] +static void +gdbpy_handle_sigint (int sig) +{ + PyErr_SetInterrupt (); +} I would be quite afraid if GDB could throw an KeyboardInterruptException in any call to its API, there wouldn't be any way to ensure internal consistency inside the script, except with try_catch surrounding every GDB function call ... In http://sourceware.org/bugzilla/show_bug.cgi?id=3D12615 I suggested using something similar to what already exist in GDB: > #define QUIT { \ > if (quit_flag) quit (); \ > if (deprecated_interactive_hook) deprecated_interactive_hook (); \ > } and: > /* Nonzero means a quit has been requested. */ > int quit_flag; > int immediate_quit; that is, setting a Python-reachable flag and let the script decides what to= do. `remote.c' mechanism > /* Signal handler for SIGINT, while the target is executing. */ > static void > > handle_remote_sigint (int sig) > { > signal (sig, handle_remote_sigint_twice); > ... > /* Signal handler for SIGINT, installed after SIGINT has already been > sent once. It will take effect the second time that the user sends > a ^C. */ > static void > handle_remote_sigint_twice (int sig) could also be used to actually send the KeyboardInterruptException if C^c is hit twice. Kevin