From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#31671: 26.1; edebug-defun doesn't step if functions run in a separate thread Date: Tue, 05 Jun 2018 17:51:03 +0300 Message-ID: <834lihb82w.fsf@gnu.org> References: <87muwfsp4i.fsf@konghq.com> <83r2lmbidf.fsf@gnu.org> Reply-To: Eli Zaretskii NNTP-Posting-Host: blaine.gmane.org X-Trace: blaine.gmane.org 1528210211 25596 195.159.176.226 (5 Jun 2018 14:50:11 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 5 Jun 2018 14:50:11 +0000 (UTC) Cc: 31671@debbugs.gnu.org To: raimon@konghq.com Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Jun 05 16:50:07 2018 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fQDHh-0006WA-VI for geb-bug-gnu-emacs@m.gmane.org; Tue, 05 Jun 2018 16:50:06 +0200 Original-Received: from localhost ([::1]:47311 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fQDJn-00055P-9M for geb-bug-gnu-emacs@m.gmane.org; Tue, 05 Jun 2018 10:52:15 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:49639) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fQDJf-000557-OM for bug-gnu-emacs@gnu.org; Tue, 05 Jun 2018 10:52:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fQDJa-0002Z2-9U for bug-gnu-emacs@gnu.org; Tue, 05 Jun 2018 10:52:07 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:55635) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fQDJa-0002Yq-4h for bug-gnu-emacs@gnu.org; Tue, 05 Jun 2018 10:52:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1fQDJZ-0001qs-Ul for bug-gnu-emacs@gnu.org; Tue, 05 Jun 2018 10:52:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 05 Jun 2018 14:52:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 31671 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 31671-submit@debbugs.gnu.org id=B31671.15282102647020 (code B ref 31671); Tue, 05 Jun 2018 14:52:01 +0000 Original-Received: (at 31671) by debbugs.gnu.org; 5 Jun 2018 14:51:04 +0000 Original-Received: from localhost ([127.0.0.1]:35289 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fQDId-0001p9-Kj for submit@debbugs.gnu.org; Tue, 05 Jun 2018 10:51:03 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:58365) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fQDIc-0001oe-3p for 31671@debbugs.gnu.org; Tue, 05 Jun 2018 10:51:02 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fQDIT-0002Al-Q7 for 31671@debbugs.gnu.org; Tue, 05 Jun 2018 10:50:57 -0400 Original-Received: from fencepost.gnu.org ([2001:4830:134:3::e]:45070) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fQDIT-0002Ah-LY; Tue, 05 Jun 2018 10:50:53 -0400 Original-Received: from [176.228.60.248] (port=3872 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1fQDIT-000306-1p; Tue, 05 Jun 2018 10:50:53 -0400 In-reply-to: <83r2lmbidf.fsf@gnu.org> (message from Eli Zaretskii on Mon, 04 Jun 2018 19:56:28 +0300) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 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.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:147016 Archived-At: > Date: Mon, 04 Jun 2018 19:56:28 +0300 > From: Eli Zaretskii > Cc: 31671@debbugs.gnu.org > > The problem here is that Edebug enters recursive-editing (on the > non-main thread which runs the function 'foo'), then waits for the > user to press a key. While it waits, it releases the global lock, and > the main thread starts running. So when you press a key, you are on a > different thread, and 'throw' doesn't have a matching 'catch' (because > that 'catch' is stored with the handlers of the thread which runs > 'foo'. > > Not yet sure how to deal with this. Thoughts and ideas are welcome. Any objections to the following band-aid? (Of course, user-error does nothing visible on non-main threads, and you have too invoke thread-last-error to see the error message, but at least we don't leave around a thread in limbo waiting forever for input that will never come...) --- src/thread.c~0 2018-01-28 06:56:25.000000000 +0200 +++ src/thread.c 2018-06-05 17:25:43.147566500 +0300 @@ -980,6 +980,23 @@ DEFUN ("thread-last-error", Fthread_last return last_thread_error; } +DEFUN ("main-thread-p", Fmain_thread_p, Smain_thread_p, 0, 1, 0, + doc: /* Return non-nil if THREAD is the main thread. +If THREAD is nil or omitted, it defaults to the current thread. */) + (Lisp_Object thread) +{ + struct thread_state *tstate; + + if (NILP (thread)) + tstate = current_thread; + else + { + CHECK_THREAD (thread); + tstate = XTHREAD (thread); + } + return main_thread_p (tstate) ? Qt : Qnil; +} + bool @@ -1073,6 +1090,7 @@ syms_of_threads (void) defsubr (&Scondition_mutex); defsubr (&Scondition_name); defsubr (&Sthread_last_error); + defsubr (&Smain_thread_p); staticpro (&last_thread_error); last_thread_error = Qnil; --- lisp/emacs-lisp/edebug.el~0 2018-03-14 06:39:59.000000000 +0200 +++ lisp/emacs-lisp/edebug.el 2018-06-05 17:19:52.017355000 +0300 @@ -2425,6 +2425,8 @@ (if inhibit-redisplay ;; Don't really try to enter edebug within an eval from redisplay. value + (or (main-thread-p) + (user-error "Debugging on non-main thread is not yet supported")) ;; Check breakpoints and pending input. ;; If edebug display should be updated, call edebug--display. ;; Return value. --- lisp/emacs-lisp/debug.el~0 2018-01-03 13:08:56.000000000 +0200 +++ lisp/emacs-lisp/debug.el 2018-06-05 17:31:39.765134800 +0300 @@ -147,6 +147,8 @@ (if inhibit-redisplay ;; Don't really try to enter debugger within an eval from redisplay. debugger-value + (or (main-thread-p) + (user-error "Debugging on non-main thread is not yet supported")) (unless noninteractive (message "Entering debugger...")) (let (debugger-value --- doc/lispref/threads.texi~0 2018-01-03 13:08:46.000000000 +0200 +++ doc/lispref/threads.texi 2018-06-05 17:29:47.030735200 +0300 @@ -122,6 +122,12 @@ Return the current thread. @end defun +@defun main-thread-p &optional thread +This function returns non-@code{nil} if @var{thread} is the main +thread. If @var{thread} is @code{nil} or omitted, it defaults to the +current thread. +@end defun + @defun all-threads Return a list of all the live thread objects. A new list is returned by each invocation. --- etc/NEWS~ 2018-03-14 06:39:58.000000000 +0200 +++ etc/NEWS 2018-06-05 17:37:13.301233500 +0300 @@ -361,6 +361,11 @@ * Lisp Changes in Emacs 27.1 +++ +** New primitive 'main-thread-p'. +This can be used in code which needs to work differently when it runs +in threads other than the main thread. + ++++ ** New function assoc-delete-all. ** 'print-quoted' now defaults to t, so if you want to see