]> git.eshelyaron.com Git - emacs.git/commitdiff
* lisp/emacs-lisp/debug.el (debug): Don't hang upon error in initial-frame.
authorStefan Monnier <monnier@iro.umontreal.ca>
Mon, 2 Apr 2018 04:23:20 +0000 (00:23 -0400)
committerStefan Monnier <monnier@iro.umontreal.ca>
Mon, 2 Apr 2018 04:23:20 +0000 (00:23 -0400)
lisp/emacs-lisp/debug.el

index f3a927f31cd82c9aacfcdb5ba1b82968250a3e82..e8a3015b8fba9a756b74cfead03aad7067d3d74e 100644 (file)
@@ -145,9 +145,29 @@ You may call with no args, or you may pass nil as the first arg and
 any other args you like.  In that case, the list of args after the
 first will be printed into the backtrace buffer."
   (interactive)
-  (if inhibit-redisplay
-      ;; Don't really try to enter debugger within an eval from redisplay.
-      debugger-value
+  (cond
+   (inhibit-redisplay
+    ;; Don't really try to enter debugger within an eval from redisplay.
+    debugger-value)
+   ((and (eq t (framep (selected-frame)))
+         (equal "initial_terminal" (terminal-name)))
+    ;; We're in the initial-frame (where `message' just outputs to stdout) so
+    ;; there's no tty or GUI frame to display the backtrace and interact with
+    ;; it: just dump a backtrace to stdout.
+    ;; This happens for example while handling an error in code from
+    ;; early-init.el with --debug-init.
+    (message "Error: %S" args)
+    (let ((print-escape-newlines t)
+          (print-escape-control-characters t)
+          (print-level 8)
+          (print-length 50)
+          (skip t))             ;Skip the first frame (i.e. the `debug' frame)!
+      (mapbacktrace (lambda (_evald func args _flags)
+                      (if skip
+                          (setq skip nil)
+                        (message "  %S" (cons func args))))
+                    'debug)))
+   (t
     (unless noninteractive
       (message "Entering debugger..."))
     (let (debugger-value
@@ -272,7 +292,7 @@ first will be printed into the backtrace buffer."
          (with-timeout-unsuspend debugger-with-timeout-suspend)
          (set-match-data debugger-outer-match-data)))
       (setq debug-on-next-call debugger-step-after-exit)
-      debugger-value)))
+      debugger-value))))
 \f
 (defun debugger--print (obj &optional stream)
   (condition-case err