all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Helmut Eller <eller.helmut@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 65837@debbugs.gnu.org
Subject: bug#65837: 30.0.50; Debugger in non-main threads
Date: Sat, 09 Sep 2023 19:24:31 +0200	[thread overview]
Message-ID: <m28r9f2rao.fsf@gmail.com> (raw)
In-Reply-To: <83il8jthup.fsf@gnu.org> (Eli Zaretskii's message of "Sat, 09 Sep 2023 19:46:22 +0300")

[-- Attachment #1: Type: text/plain, Size: 718 bytes --]

On Sat, Sep 09 2023, Eli Zaretskii wrote:

> So I think the only reasonably practical way to make this particular
> use case stable is to disable thread switching for as long as the
> debugger is active.  WDYT?

Having to disable thread switching for so long would be quite
unfortunate.

I think that is safe for the debuggee to call condition-wait or
accept-process-output on a specific pipe process.  That should be enough
to implement some form of channel/mailbox to communicate between the
debuggee and the main thread.  The debuggee would then read commands
from that channel and the main thread would send messages to that
channel instead of executing the commands.  Something like the patch in
the attachment.


[-- Attachment #2: debug-patch.el --]
[-- Type: text/plain, Size: 1775 bytes --]

--- /scratch/emacs/emacs-git/lisp/emacs-lisp/debug.el	2023-01-29 15:26:37.886911531 +0100
+++ debug.el	2023-09-09 19:20:49.039995072 +0200
@@ -283,7 +283,7 @@
 		  (message "")
 		  ;; Make sure we unbind buffer-read-only in the right buffer.
 		  (save-excursion
-		    (recursive-edit))))
+                    (debugger--recursive-edit))))
 	    (when (and (window-live-p debugger-window)
 		       (eq (window-buffer debugger-window) debugger-buffer))
 	      ;; Record height of debugger window.
@@ -314,6 +314,24 @@
 	    (set-match-data debugger-outer-match-data)))
         (setq debug-on-next-call debugger-step-after-exit)
         debugger-value))))
+
+(require 'channel)
+(defvar-local debugger--channel nil)
+(defvar-local debugger--thread nil)
+
+(defun debugger--recursive-edit ()
+  (setq debugger--thread (current-thread))
+  (cond ((eq (current-thread) main-thread)
+         (recursive-edit))
+        (t
+         (let ((ch (channel-make-channel 0)))
+           (setq debugger--channel (cdr ch))
+           (while t
+             (pcase-exhaustive (channel-receive (car ch))
+               ('(quit)
+                (message "quit received...")
+                (debugger-quit))))))))
+
 \f
 (defun debugger--print (obj &optional stream)
   (condition-case err
@@ -755,9 +773,12 @@
 (defun debugger-quit ()
   "Quit debugging and return to the top level."
   (interactive)
-  (if (= (recursion-depth) 0)
-      (quit-window)
-    (top-level)))
+  (cond ((eq (current-thread) debugger--thread)
+         (if (= (recursion-depth) 0)
+             (quit-window)
+           (top-level)))
+        (t
+         (channel-send debugger--channel 'quit nil))))
 
 (defun debug--implement-debug-watch (symbol newval op where)
   "Conditionally call the debugger.

[-- Attachment #3: Type: text/plain, Size: 8 bytes --]


Helmut

  reply	other threads:[~2023-09-09 17:24 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-09  9:15 bug#65837: 30.0.50; Debugger in non-main threads Helmut Eller
2023-09-09 11:14 ` Eli Zaretskii
2023-09-09 15:35   ` Helmut Eller
2023-09-09 15:57     ` Eli Zaretskii
2023-09-09 16:23       ` Helmut Eller
2023-09-09 16:46         ` Eli Zaretskii
2023-09-09 17:24           ` Helmut Eller [this message]
2023-09-09 17:37             ` Eli Zaretskii
2023-09-09 18:29               ` Helmut Eller
2023-09-09 18:34                 ` Eli Zaretskii
2023-09-09 18:50                   ` Helmut Eller

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=m28r9f2rao.fsf@gmail.com \
    --to=eller.helmut@gmail.com \
    --cc=65837@debbugs.gnu.org \
    --cc=eliz@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.