all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Daniel Colascione <dan.colascione@gmail.com>
To: chad <chadpbrown@gmail.com>
Cc: emacs-devel@gnu.org
Subject: Re: [PATCH] Unconditional quit on SIGUSR2
Date: Tue, 29 Mar 2011 10:55:40 -0700	[thread overview]
Message-ID: <4D921D1C.30806@gmail.com> (raw)
In-Reply-To: <162CA738-6205-4D86-B263-B1C6408950BD@gmail.com>


[-- Attachment #1.1: Type: text/plain, Size: 766 bytes --]

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.


[-- Attachment #1.2: debugsig3.patch --]
[-- Type: text/plain, Size: 4865 bytes --]

=== 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.
 
+@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

=== 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
 
+@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

=== 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" sigusr1)
+                                    (const :tag "When sent SIGUSR2" sigusr2))
+                            "24.1")
 
 ;; This is not good news because it will use the wrong
 ;; version-specific directories when you upgrade.  We need

=== 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 = errno;
   struct user_signal_info *p;
+  const char* special_event_name = NULL;
 
   SIGNAL_THREAD_CHECK (sig);
-
+  
+  if (SYMBOLP (Vdebug_on_special_event) &&
+      STRINGP (XSYMBOL (Vdebug_on_special_event)->xname))
+    {
+      special_event_name =
+        SSDATA (XSYMBOL (Vdebug_on_special_event)->xname);
+    }
+  
   for (p = user_signals; p; p = p->next)
     if (p->sig == sig)
       {
+        if (special_event_name &&
+            strcmp (special_event_name, p->name) == 0)
+          {
+            /* Enter the debugger in many ways.  */
+            debug_on_next_call = 1;
+            debug_on_quit = 1;
+            Vquit_flag = Qt;
+            Vinhibit_quit = Qnil;
+
+            /* Eat the event.  */
+            break;
+          }
+        
 	p->npending++;
 #ifdef SIGIO
 	if (interrupt_input)
@@ -12178,6 +12199,17 @@
 `deactivate-mark' call uses this to set the window selection.  */);
   Vsaved_region_selection = Qnil;
 
+  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 = intern_c_string ("sigusr2");
+
   /* Create the initial keyboard. */
   initial_kboard = (KBOARD *) xmalloc (sizeof (KBOARD));
   init_kboard (initial_kboard);

=== 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 @@
 
 /* Defined in eval.c */
 extern Lisp_Object Qautoload, Qexit, Qinteractive, Qcommandp, Qdefun, Qmacro;
-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;


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

  reply	other threads:[~2011-03-29 17:55 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-28  7:14 [PATCH] Unconditional quit on SIGUSR2 Daniel Colascione
2011-03-28 11:48 ` Eli Zaretskii
2011-03-28 12:32   ` Julien Danjou
2011-03-28 14:32     ` Eli Zaretskii
2011-03-28 14:49       ` Julien Danjou
2011-03-28 13:38   ` Daniel Colascione
2011-03-28 14:47     ` Eli Zaretskii
2011-03-28 17:23       ` Daniel Colascione
2011-03-28 18:37         ` Eli Zaretskii
2011-03-28 19:29           ` Daniel Colascione
2011-03-28 19:41             ` Eli Zaretskii
2011-03-28 19:49               ` Daniel Colascione
2011-03-28 19:52                 ` Lennart Borgman
2011-03-28 19:56                   ` Daniel Colascione
2011-03-28 20:06                     ` Lennart Borgman
2011-03-28 20:12                       ` Daniel Colascione
2011-03-28 20:45                         ` Lennart Borgman
2011-03-28 21:13                           ` In praise of font-lock (Was: Re: [PATCH] Unconditional quit on SIGUSR2) Daniel Colascione
2011-03-28 21:27                             ` Lennart Borgman
2011-03-28 20:10                     ` [PATCH] Unconditional quit on SIGUSR2 chad
2011-03-28 22:00                 ` Eli Zaretskii
2011-03-28 22:08                   ` Daniel Colascione
2011-03-28 22:20                     ` chad
2011-03-29 17:55                       ` Daniel Colascione [this message]
2011-03-29 18:14                         ` Daniel Colascione
2011-04-25  2:16                         ` Daniel Colascione
2011-04-25  9:23                           ` joakim
2011-04-25  9:33                             ` Daniel Colascione
2011-04-25 13:32                           ` Stefan Monnier
2011-04-25 18:21                             ` Daniel Colascione
2011-04-25 18:43                               ` Stefan Monnier
2011-04-26 14:47                             ` Richard Stallman
2011-03-29 13:23         ` Tom Tromey
2011-03-29 14:25           ` Stefan Monnier
2011-03-29 14:47             ` Tom Tromey
2011-03-29 21:37               ` Stefan Monnier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4D921D1C.30806@gmail.com \
    --to=dan.colascione@gmail.com \
    --cc=chadpbrown@gmail.com \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.