Subject: Re: bug#31671: 26.1; edebug-defun doesn't step if functions run in a separate thread

From: Eli Zaretskii <[email-masked]>
Date: Mon, 04 Jun 2018 19:56:28 +0300

> From: Raimon Grau <[email-masked]>
> Date: Thu, 31 May 2018 18:37:17 +0100
> 
> Using edebug-defun to instrument a function and running that function in
> a separate thread using `make-thread' makes triggers the breakpoint but
> leaves the bufer in read-only-mode but the user can't interact with
> edebug in any way.
> 
> Steps to reproduce (ubuntu 16.04):
> - start emacs with emacs -Q  . 
> - in the *scratch* buffer, write:
> (defun foo ()
>   (message "hi"))
> 
> (make-thread 'foo)
> - edebug-defun function foo
> - c-x c-e the (make-thread 'foo) sexp
> - *scratch* buffer point moves to the beginning of function foo
> - press `n` and the minibuffers says: "No catch for tag: exit, nil". The
>   whole buffer is in read-only mode. modeline has
>   "(Lisp Interaction *Debugging* ElDoc)"

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.