emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Early backtrace.


From: Alan Mackenzie
Subject: Early backtrace.
Date: Mon, 10 Jan 2022 20:34:08 +0000

Hello, Emacs.

In the course of debugging a recent bug, I found myself needing to get a
Lisp backtrace.  This was early on in the bootstrap process, where the
standard backtrace.el cannot work, since it requires several files.el
which are only loaded later.

So I came up with the following, which has no Lisp dependencies.  That
is, absolutely none.  I have used it as the first Lisp file loaded,
immediately before byte-run.el.

So, how about including this file in Emacs, amending eval.c to use it if
backtrace.el isn't yet avaiable?  Comments and criticism are welcome.

lisp/emacs-lisp/early-debug.el:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defalias 'early-backtrace
  #'(lambda ()
  "Print a trace of Lisp function calls currently active.
The output stream used is the value of `standard-output'.

This is a simplified version of the standard `backtrace'
function, intended for use in debugging the early parts
of the build process."
  (princ "\n")
  (mapbacktrace
   #'(lambda (evald func args _flags)
       (let ((args args))
         (if evald
             (progn
               (princ "  ")
               (prin1 func)
               (princ " (")
               (while args
                 (prin1 (car args))
                 (setq args (cdr args))
                 (if args
                     (princ " ")))
               (princ ")\n"))
           (while args
             (princ "  ")
             (prin1 (car args))
             (princ "\n")
             (setq args (cdr args)))))))))

(defalias 'early-debug
  #'(lambda (&rest args)
  "Print a trace of Lisp function calls currently active.
The output stream used is the value of `standard-output'.

There should be two ARGS, the symbol `error' and a cons of
the error symbol and its data.

This is a simplified version of `debug', intended for use
in debugging the early parts of the build process."
  (princ "\nError: ")
  (prin1 (car (car (cdr args))))        ; The error symbol.
  (princ " ")
  (prin1 (cdr (car (cdr args))))        ; The error data.
  (early-backtrace)))

(setq debugger #'early-debug)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

-- 
Alan Mackenzie (Nuremberg, Germany).



reply via email to

[Prev in Thread] Current Thread [Next in Thread]