Subject: bug#40088: 27.0.90; Symbol’s value as variable is void: debugger-outer-match-data

From: Noam Postavsky <[email-masked]>
Date: Wed, 18 Mar 2020 20:04:56 -0400

Noam Postavsky <[email-masked]> writes:

>>> *** Eval error ***  Symbol’s value as variable is void:
>>> debugger-outer-match-data

A simpler reproducer (although it only reproduces once per-session) is

    (make-local-variable 'xx)
    (let ((xx 1))
      (backtrace--locals 1))

In Emacs 26, this gives

Debugger entered--Lisp error: (void-variable xx)
  backtrace--locals(1)
  (let ((xx 1)) (backtrace--locals 1))
  ...
  eval-defun(nil)
  ...

The error shouldn't happen, but it's not as severe as in Emacs 27.  I
think because in v27, the debugger display code got more fancy, and
recursively triggers the problem.

Since the void-variable is getting triggered from
backtrace_eval_unrewind, I tried the patch below, which almost seems to
fix the problem, but after continuing from the debugger there's a
segfault in GC, so it's definitely not the Right Thing.  I think this is
a bit over my head.  Ccing Stefan, any ideas?

diff --git i/src/data.c w/src/data.c
index b153068846..5ce5e360ab 100644
--- i/src/data.c
+++ w/src/data.c
@@ -1573,7 +1573,7 @@ notify_variable_watchers (Lisp_Object symbol,
 /* Return the default value of SYMBOL, but don't check for voidness.
    Return Qunbound if it is void.  */
 
-static Lisp_Object
+Lisp_Object
 default_value (Lisp_Object symbol)
 {
   struct Lisp_Symbol *sym;
diff --git i/src/eval.c w/src/eval.c
index 4559a0e1f6..78a787c4ff 100644
--- i/src/eval.c
+++ w/src/eval.c
@@ -3816,7 +3816,7 @@ backtrace_eval_unrewind (int distance)
 	  {
 	    Lisp_Object sym = specpdl_symbol (tmp);
 	    Lisp_Object old_value = specpdl_old_value (tmp);
-	    set_specpdl_old_value (tmp, Fdefault_value (sym));
+	    set_specpdl_old_value (tmp, default_value (sym));
 	    Fset_default (sym, old_value);
 	  }
 	  break;
@@ -3832,7 +3832,7 @@ backtrace_eval_unrewind (int distance)
 	    if (!NILP (Flocal_variable_p (symbol, where)))
 	      {
 		set_specpdl_old_value
-		  (tmp, Fbuffer_local_value (symbol, where));
+		  (tmp, buffer_local_value (symbol, where));
                 set_internal (symbol, old_value, where, SET_INTERNAL_UNBIND);
 	      }
 	  }