Move 'backtrace' from subr.el to backtrace.el

* lisp/subr.el (backtrace, backtrace--print-frame): Remove functions.
* lisp/emacs-lisp/backtrace.el (backtrace-backtrace): Remove function.
(backtrace): New function.
(backtrace-to-string): Make argument optional.
* doc/lispref/debugging.texi (Internals of Debugger): Update
description of 'backtrace' function.
This commit is contained in:
Gemini Lasswell 2018-07-18 08:30:45 -07:00
parent ca98377280
commit 83af893fc0
3 changed files with 17 additions and 33 deletions

View file

@ -678,20 +678,19 @@ of @code{debug} (@pxref{Invoking the Debugger}).
@cindex run time stack @cindex run time stack
@cindex call stack @cindex call stack
This function prints a trace of Lisp function calls currently active. This function prints a trace of Lisp function calls currently active.
This is the function used by @code{debug} to fill up the The trace is identical to the one that @code{debug} would show in the
@file{*Backtrace*} buffer. It is written in C, since it must have access @file{*Backtrace*} buffer. The return value is always nil.
to the stack to determine which function calls are active. The return
value is always @code{nil}.
In the following example, a Lisp expression calls @code{backtrace} In the following example, a Lisp expression calls @code{backtrace}
explicitly. This prints the backtrace to the stream explicitly. This prints the backtrace to the stream
@code{standard-output}, which, in this case, is the buffer @code{standard-output}, which, in this case, is the buffer
@samp{backtrace-output}. @samp{backtrace-output}.
Each line of the backtrace represents one function call. The line shows Each line of the backtrace represents one function call. The line
the values of the function's arguments if they are all known; if they shows the function followed by a list of the values of the function's
are still being computed, the line says so. The arguments of special arguments if they are all known; if they are still being computed, the
forms are elided. line consists of a list containing the function and its unevaluated
arguments. Long lists or deeply nested structures may be elided.
@smallexample @smallexample
@group @group
@ -708,7 +707,7 @@ forms are elided.
@group @group
----------- Buffer: backtrace-output ------------ ----------- Buffer: backtrace-output ------------
backtrace() backtrace()
(list ...computing arguments...) (list 'testing (backtrace))
@end group @end group
(progn ...) (progn ...)
eval((progn (1+ var) (list 'testing (backtrace)))) eval((progn (1+ var) (list 'testing (backtrace))))
@ -739,7 +738,7 @@ example would look as follows:
@group @group
----------- Buffer: backtrace-output ------------ ----------- Buffer: backtrace-output ------------
(backtrace) (backtrace)
(list ...computing arguments...) (list 'testing (backtrace))
@end group @end group
(progn ...) (progn ...)
(eval (progn (1+ var) (list 'testing (backtrace)))) (eval (progn (1+ var) (list 'testing (backtrace))))

View file

@ -891,14 +891,18 @@ followed by `backtrace-print-frame', once for each stack frame."
;;; Backtrace printing ;;; Backtrace printing
(defun backtrace-backtrace () ;;;###autoload
(defun backtrace ()
"Print a trace of Lisp function calls currently active. "Print a trace of Lisp function calls currently active.
Output stream used is value of `standard-output'." Output stream used is value of `standard-output'."
(princ (backtrace-to-string (backtrace-get-frames 'backtrace-backtrace)))) (princ (backtrace-to-string (backtrace-get-frames 'backtrace)))
nil)
(defun backtrace-to-string(frames) (defun backtrace-to-string(&optional frames)
"Format FRAMES, a list of `backtrace-frame' objects, for output. "Format FRAMES, a list of `backtrace-frame' objects, for output.
Return the result as a string." Return the result as a string. If FRAMES is nil, use all
function calls currently active."
(unless frames (setq frames (backtrace-get-frames 'backtrace-to-string)))
(let ((backtrace-fontify nil)) (let ((backtrace-fontify nil))
(with-temp-buffer (with-temp-buffer
(backtrace-mode) (backtrace-mode)

View file

@ -4687,25 +4687,6 @@ The properties used on SYMBOL are `composefunc', `sendfunc',
(put symbol 'hookvar (or hookvar 'mail-send-hook))) (put symbol 'hookvar (or hookvar 'mail-send-hook)))
(defun backtrace--print-frame (evald func args flags)
"Print a trace of a single stack frame to `standard-output'.
EVALD, FUNC, ARGS, FLAGS are as in `mapbacktrace'."
(princ (if (plist-get flags :debug-on-exit) "* " " "))
(cond
((and evald (not debugger-stack-frame-as-list))
(cl-prin1 func)
(if args (cl-prin1 args) (princ "()")))
(t
(cl-prin1 (cons func args))))
(princ "\n"))
(defun backtrace ()
"Print a trace of Lisp function calls currently active.
Output stream used is value of `standard-output'."
(let ((print-level (or print-level 8))
(print-escape-control-characters t))
(mapbacktrace #'backtrace--print-frame 'backtrace)))
(defun backtrace-frames (&optional base) (defun backtrace-frames (&optional base)
"Collect all frames of current backtrace into a list. "Collect all frames of current backtrace into a list.
If non-nil, BASE should be a function, and frames before its If non-nil, BASE should be a function, and frames before its