Subject: bug#54996: Emacs hangs when editing Python code with debug-on-error set to t

From: Lars Ingebrigtsen <[email-masked]>
Date: Mon, 18 Apr 2022 13:07:24 +0200

Eli Zaretskii <[email-masked]> writes:

> In Fsignal, I guess.  But it is strange that call_debugger doesn't
> trigger: do you see a *Backtrace* buffer popping up?

Nope, Emacs just hangs without popping up anything.

Breakpoing on Fsignal is called all the time, even without
debug-on-error, so it's too noisy to use.

#0  Fsignal (error_symbol=0x106b0, data=0x555556090af3) at eval.c:1649
#1  0x00005555555dcf9a in xsignal (data=<optimized out>, error_symbol=0x106b0)
    at /home/larsi/src/emacs/trunk/src/lisp.h:4514
#2  xsignal1 (error_symbol=error_symbol@entry=0x106b0, arg=arg@entry=0x2d1c30)
    at eval.c:1811
#3  0x00005555555dc6c8 in Fdefault_value (symbol=<optimized out>)
    at data.c:1952
#4  0x0000555555788478 in Fdefault_toplevel_value (symbol=0x2d1c30)
    at eval.c:709
#5  0x00005555557ced47 in exec_byte_code
    (fun=<optimized out>, args_template=<optimized out>, nargs=<optimized out>, args=<optimized out>) at bytecode.c:809
#6  0x00005555557d154b in Fbyte_code
    (bytestr=<optimized out>, vector=0x555555d537e5, maxdepth=0x2a)
    at bytecode.c:329
#7  0x000055555578a161 in eval_sub (form=<optimized out>) at eval.c:2388
#8  0x00005555557bbb15 in readevalloop

And that's because defcustom uses errors as control flow:

(defun custom-initialize-default (symbol exp)
  "Initialize SYMBOL with EXP.
This will do nothing if symbol already has a default binding.
Otherwise, if symbol has a `saved-value' property, it will evaluate
the car of that and use it as the default binding for symbol.
Otherwise, EXP will be evaluated and used as the default binding for
symbol."
  (condition-case nil
      (default-toplevel-value symbol)   ;Test presence of default value.
    (void-variable
     ;; The var is not initialized yet.
     (set-default-toplevel-value
      symbol (eval (let ((sv (get symbol 'saved-value)))
                     (if sv (car sv) exp))
                   t)))))

Which has bitten me before when trying to do debugging...  could we
rewrite that somehow to avoid this?

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no