From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Helmut Eller Newsgroups: gmane.emacs.bugs Subject: bug#65837: 30.0.50; Debugger in non-main threads Date: Sat, 09 Sep 2023 19:24:31 +0200 Message-ID: References: <83bkebvbsj.fsf@gnu.org> <83msxvtk3r.fsf@gnu.org> <83il8jthup.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="10973"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: 65837@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Sep 09 19:25:19 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qf1hv-0002fs-GW for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 09 Sep 2023 19:25:19 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qf1hd-0004ZF-9y; Sat, 09 Sep 2023 13:25:01 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qf1hb-0004Yf-KB for bug-gnu-emacs@gnu.org; Sat, 09 Sep 2023 13:24:59 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qf1ha-0003P9-VC for bug-gnu-emacs@gnu.org; Sat, 09 Sep 2023 13:24:59 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qf1hd-0005BH-Sc for bug-gnu-emacs@gnu.org; Sat, 09 Sep 2023 13:25:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Helmut Eller Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 09 Sep 2023 17:25:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 65837 X-GNU-PR-Package: emacs Original-Received: via spool by 65837-submit@debbugs.gnu.org id=B65837.169428028719892 (code B ref 65837); Sat, 09 Sep 2023 17:25:01 +0000 Original-Received: (at 65837) by debbugs.gnu.org; 9 Sep 2023 17:24:47 +0000 Original-Received: from localhost ([127.0.0.1]:48430 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qf1hP-0005Al-5G for submit@debbugs.gnu.org; Sat, 09 Sep 2023 13:24:47 -0400 Original-Received: from mail-wm1-x32a.google.com ([2a00:1450:4864:20::32a]:58692) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qf1hK-0005AV-EW for 65837@debbugs.gnu.org; Sat, 09 Sep 2023 13:24:46 -0400 Original-Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-401b393df02so35883415e9.1 for <65837@debbugs.gnu.org>; Sat, 09 Sep 2023 10:24:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694280273; x=1694885073; darn=debbugs.gnu.org; h=mime-version:user-agent:message-id:date:references:in-reply-to :subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to; bh=4tPRhtbALtw5xL9H9BIz5D6ErwxIqxrrF0kOQnSzYO0=; b=LTARjTiCOrq4QzYoNJow2EbbCI9aKlYG8l/H5B4YpdVdb2VohENjBMI2qnn3ZmLmu1 +RMFYaxjVTYDdqfkzH0RsqZRRnCRZmCRUZAMkx1drZjo2RG9motD0PSNIJMO77HEnR0R KFfsRaW7FYyVOM34ThuiV9nsiPELIyPbwf8i6GOYRbNjcNdp5j15Qyidf0U/ObPE387G t6j+e1tvC/3NqU1bO760F05qdNb6bAYMLzXT5Mr1XqJ9lz2EbR2kkIFsqn9NufjwC6li 8qKrL7+7+Xomt1yuZ31Q0/wM1dY8NaTsUcRRJXti0VbaAhhqMB6Qjpu1dmJFm7+t0biI kQcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694280273; x=1694885073; h=mime-version:user-agent:message-id:date:references:in-reply-to :subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=4tPRhtbALtw5xL9H9BIz5D6ErwxIqxrrF0kOQnSzYO0=; b=dgOp02CuILEQYRQs9ZdXVc+zUxDawFKzB1w2vrcl33wd/VjkeLMNPayiCwUYlBGrkm rjgM9O2F5tY6JFRVDF8NvZ+0HTXcQCutlE+0ExW3Suve5czqYu9C04KVgbmizSPDZgu0 LavDvEwKNXR9eqoPFKOK4QeZrcOc5NUX9lbcEaRX80m/+JvHLX1SNhvaPQQW0iOx4dm2 8DE42rjGoKGMUkzDOeSzDcIxAscTTSqEfLSZiedsoNW9b3ys+0FLqLWDrEEmIRS5bTxD 9jv41Tz+ZuIhZHGm33o4rRIk/woTX4PH+JTiVitnaqokAr6Gjf70sXYTbgu5EHild3Q3 8OnQ== X-Gm-Message-State: AOJu0YxkmNPObMmh8Z4PNYJyNAP47BdmFc3xbx+BZqU7oDRTGP8hxTGv r2OwnJcUJzFGdMP7H9LwOOfNb1laXoE= X-Google-Smtp-Source: AGHT+IEVbWQO7GZ39qjYYX9Zb1G11kVHybgZxm6LKqBq6+u9Q8aGPwM9xw0HV/u0z2oLDOTnZQtLEw== X-Received: by 2002:adf:dec2:0:b0:319:7428:9caa with SMTP id i2-20020adfdec2000000b0031974289caamr4106195wrn.38.1694280272559; Sat, 09 Sep 2023 10:24:32 -0700 (PDT) Original-Received: from caladan ([31.177.119.112]) by smtp.gmail.com with ESMTPSA id a3-20020adfeec3000000b003196e992567sm5259751wrp.115.2023.09.09.10.24.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 09 Sep 2023 10:24:31 -0700 (PDT) In-Reply-To: <83il8jthup.fsf@gnu.org> (Eli Zaretskii's message of "Sat, 09 Sep 2023 19:46:22 +0300") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:269888 Archived-At: --=-=-= Content-Type: text/plain 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. --=-=-= Content-Type: text/plain Content-Disposition: attachment; filename=debug-patch.el --- /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)))))))) + (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. --=-=-= Content-Type: text/plain Helmut --=-=-=--