From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Daniel Colascione Newsgroups: gmane.emacs.devel Subject: Re: [PATCH] Unconditional quit on SIGUSR2 Date: Tue, 29 Mar 2011 10:55:40 -0700 Message-ID: <4D921D1C.30806@gmail.com> References: <4D90354E.9000704@gmail.com> <4D908F5F.8000303@gmail.com> <4D90C42F.9060500@gmail.com> <83bp0vrszf.fsf@gnu.org> <4D90E199.2040809@gmail.com> <83aagfrq1y.fsf@gnu.org> <4D90E661.40207@gmail.com> <8362r2sy5x.fsf@gnu.org> <4D9106E7.5010902@gmail.com> <162CA738-6205-4D86-B263-B1C6408950BD@gmail.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="------------enigFCC2979EBB9208A9363A2617" X-Trace: dough.gmane.org 1301421358 22760 80.91.229.12 (29 Mar 2011 17:55:58 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 29 Mar 2011 17:55:58 +0000 (UTC) Cc: emacs-devel@gnu.org To: chad Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Mar 29 19:55:54 2011 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Q4d8z-00085p-5V for ged-emacs-devel@m.gmane.org; Tue, 29 Mar 2011 19:55:53 +0200 Original-Received: from localhost ([127.0.0.1]:46169 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q4d8y-0003R7-2G for ged-emacs-devel@m.gmane.org; Tue, 29 Mar 2011 13:55:52 -0400 Original-Received: from [140.186.70.92] (port=43000 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q4d8t-0003R2-JV for emacs-devel@gnu.org; Tue, 29 Mar 2011 13:55:48 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Q4d8s-0005x9-70 for emacs-devel@gnu.org; Tue, 29 Mar 2011 13:55:47 -0400 Original-Received: from mail-gy0-f169.google.com ([209.85.160.169]:54822) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Q4d8s-0005x3-3E for emacs-devel@gnu.org; Tue, 29 Mar 2011 13:55:46 -0400 Original-Received: by gyd8 with SMTP id 8so223334gyd.0 for ; Tue, 29 Mar 2011 10:55:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:message-id:date:from:user-agent:mime-version:to :cc:subject:references:in-reply-to:x-enigmail-version:content-type; bh=YBKNQBPophac/jEmyjz9oejhHfMXE5op2pDJzT22vQs=; b=atpC/foK78KCpQZ3OLPXLm6b+JspxP/EisCBoOkp/QgXQQcWPJo3Jk6nTkof0GZbET b62Kg7zrTTnOTZGbx3pnCmiX8Ro/lJ2ecemI97phiIld2lZe8WcjDaorVcYjhlvnjvY0 JCuXQvVNtiuDH9VDYOxPV0Odo/ZCs5ITlVMrA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:x-enigmail-version:content-type; b=NhGI0sOYhwFEnv/zUOH/EQNkYTxTnCfr8WCnP9d5aUCy/tPKPWmqZ1Di70kKxfQk3w RZwEzTerV6Nzg4ZSNwZ7ThqpCkabVjHlMWR3mPj5qVs6YBySYs5wQYYyXlxpQBGI2GkZ 2somXl2E3Qm2L+H7BwPCye5vo/1Vjz3iBLUfA= Original-Received: by 10.236.32.65 with SMTP id n41mr123385yha.221.1301421345000; Tue, 29 Mar 2011 10:55:45 -0700 (PDT) Original-Received: from edith.local (c-67-183-23-114.hsd1.wa.comcast.net [67.183.23.114]) by mx.google.com with ESMTPS id 73sm2572191yhl.49.2011.03.29.10.55.43 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 29 Mar 2011 10:55:43 -0700 (PDT) User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.15) Gecko/20110303 Thunderbird/3.1.9 In-Reply-To: <162CA738-6205-4D86-B263-B1C6408950BD@gmail.com> X-Enigmail-Version: 1.1.1 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 209.85.160.169 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:137860 Archived-At: This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enigFCC2979EBB9208A9363A2617 Content-Type: multipart/mixed; boundary="------------000307090208060206040504" This is a multi-part message in MIME format. --------------000307090208060206040504 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable On 3/28/11 3:20 PM, chad wrote: > If the method works out in practice, how would people feel about a > patch to emacsclient adding a flag to send such signals? That would be fine. For NT Emacs, the best approach would be for emacsclient to suspend all threads in the target Emacs process, then use CreateRemoteThread to inject code into a running Emacs. This code would trip the debugger the same way the signal handler in my patch does, then resume the rest of Emacs. Below is another version of the patch. I've changed the code so that we instead inspect a new debug-on-special-event variable, which by default is the symbol sigusr2. This way, we can extend the mechanism and use another kind of special event for platforms that lack signals. --------------000307090208060206040504 Content-Type: text/plain; x-mac-type="0"; x-mac-creator="0"; name="debugsig3.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="debugsig3.patch" =3D=3D=3D modified file 'doc/emacs/trouble.texi' --- doc/emacs/trouble.texi 2011-01-25 04:08:28 +0000 +++ doc/emacs/trouble.texi 2011-03-29 17:47:26 +0000 @@ -812,6 +812,14 @@ This backtrace is useful for debugging such long loops, so if you can produce it, copy it into the bug report. =20 +@vindex debug-on-special-event +If the normal quit process is ineffective, you can try sending Emacs +the special event given in @code{debug-on-special-event}, which by +default corresponds to SIGUSR2. When Emacs receives this event, it +stops what it's doing, sets @code{debug-on-quit} to @code{t}, and +tries to break into the debugger in a variety of ways. This process +happens even in places where quitting is normally not allowed. + @item Check whether any programs you have loaded into the Lisp world, including your @file{.emacs} file, set any variables that may affect the= =3D=3D=3D modified file 'doc/lispref/debugging.texi' --- doc/lispref/debugging.texi 2011-01-25 04:08:28 +0000 +++ doc/lispref/debugging.texi 2011-03-29 17:46:44 +0000 @@ -185,6 +185,20 @@ when you quit. @xref{Quitting}. @end defopt =20 +@defopt debug-on-special-event +When this variable contains a symbol matching one of the special +events in @code{special-event-map} (@pxref{Active Keymaps}) and Emacs +receives the corresponding event, Emacs will break into the debugger +instead of processing the event normally, setting @code{debug-on-quit} +to @code{t} as a side effect. This feature is useful for terminating +infinite loops in places where quits would normally be ignored, such +as in code that runs during redisplay. + +Currently, the only events Emacs recognizes as valid values for +@code{debug-on-special-event} are @code{sigusr1} and @code{sigusr2}. + +@end defopt + @node Function Debugging @subsection Entering the Debugger on a Function Call @cindex function call debugging =3D=3D=3D modified file 'lisp/cus-start.el' --- lisp/cus-start.el 2011-03-27 10:55:07 +0000 +++ lisp/cus-start.el 2011-03-29 17:36:51 +0000 @@ -259,6 +259,11 @@ (suggest-key-bindings keyboard (choice (const :tag "off" nil) (integer :tag "time" 2) (other :tag "on"))) + (debug-on-special-event debug + (choice (const :tag "None" nil) + (const :tag "When sent SIGUSR1" sigu= sr1) + (const :tag "When sent SIGUSR2" sigu= sr2)) + "24.1") =20 ;; This is not good news because it will use the wrong ;; version-specific directories when you upgrade. We need =3D=3D=3D modified file 'src/keyboard.c' --- src/keyboard.c 2011-03-27 02:27:11 +0000 +++ src/keyboard.c 2011-03-29 17:29:47 +0000 @@ -7165,12 +7165,33 @@ { int old_errno =3D errno; struct user_signal_info *p; + const char* special_event_name =3D NULL; =20 SIGNAL_THREAD_CHECK (sig); - + =20 + if (SYMBOLP (Vdebug_on_special_event) && + STRINGP (XSYMBOL (Vdebug_on_special_event)->xname)) + { + special_event_name =3D + SSDATA (XSYMBOL (Vdebug_on_special_event)->xname); + } + =20 for (p =3D user_signals; p; p =3D p->next) if (p->sig =3D=3D sig) { + if (special_event_name && + strcmp (special_event_name, p->name) =3D=3D 0) + { + /* Enter the debugger in many ways. */ + debug_on_next_call =3D 1; + debug_on_quit =3D 1; + Vquit_flag =3D Qt; + Vinhibit_quit =3D Qnil; + + /* Eat the event. */ + break; + } + =20 p->npending++; #ifdef SIGIO if (interrupt_input) @@ -12178,6 +12199,17 @@ `deactivate-mark' call uses this to set the window selection. */); Vsaved_region_selection =3D Qnil; =20 + DEFVAR_LISP ("debug-on-special-event", + Vdebug_on_special_event, + doc: /* Enter debugger on this special event. +When Emacs receives the special event specifed by this variable, +it will try to break into the debugger as soon as possible instead of +processing the event normally through `special-event-map'. + +Currently, the only meaningful values for this +variable are `sigusr1' and `sigusr2'. */); + Vdebug_on_special_event =3D intern_c_string ("sigusr2"); + /* Create the initial keyboard. */ initial_kboard =3D (KBOARD *) xmalloc (sizeof (KBOARD)); init_kboard (initial_kboard); =3D=3D=3D modified file 'src/lisp.h' --- src/lisp.h 2011-03-27 02:27:11 +0000 +++ src/lisp.h 2011-03-28 13:06:41 +0000 @@ -2814,7 +2814,7 @@ =20 /* Defined in eval.c */ extern Lisp_Object Qautoload, Qexit, Qinteractive, Qcommandp, Qdefun, Qm= acro; -extern Lisp_Object Qinhibit_quit; +extern Lisp_Object Qinhibit_quit, Qdebug; extern Lisp_Object Vautoload_queue; extern Lisp_Object Vsignaling_function; extern int handling_signal; --------------000307090208060206040504-- --------------enigFCC2979EBB9208A9363A2617 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (Darwin) iEYEARECAAYFAk2SHR4ACgkQ17c2LVA10VspJQCfcL6IBr5YkRMC5WPEcc5KXvdM yAoAoKil8KgjgHoDhuVsIAZBRFfXd4xf =bbVX -----END PGP SIGNATURE----- --------------enigFCC2979EBB9208A9363A2617--