Function: backtrace-get-frames
backtrace-get-frames is a byte-compiled function defined in
backtrace.el.gz.
Signature
(backtrace-get-frames &optional BASE &key (CONSTRUCTOR #'backtrace-make-frame))
Documentation
Collect all frames of current backtrace into a list.
The list will contain objects made by CONSTRUCTOR, which
defaults to backtrace-make-frame and which, if provided, should
be the constructor of a structure which includes
backtrace-frame. If non-nil, BASE should be a function, and
frames before its nearest activation frame are discarded.
Source Code
;; Defined in /usr/src/emacs/lisp/emacs-lisp/backtrace.el.gz
(cl-defun backtrace-get-frames
(&optional base &key (constructor #'backtrace-make-frame))
"Collect all frames of current backtrace into a list.
The list will contain objects made by CONSTRUCTOR, which
defaults to `backtrace-make-frame' and which, if provided, should
be the constructor of a structure which includes
`backtrace-frame'. If non-nil, BASE should be a function, and
frames before its nearest activation frame are discarded."
(let ((frames nil)
(eval-buffers eval-buffer-list))
(mapbacktrace (lambda (evald fun args flags)
(push (funcall constructor
:evald evald :fun fun
:args args :flags flags)
frames))
(or base 'backtrace-get-frames))
(setq frames (nreverse frames))
;; Add local variables to each frame, and the buffer position
;; to frames containing eval-buffer or eval-region.
(dotimes (idx (length frames))
(let ((frame (nth idx frames)))
;; `backtrace--locals' gives an error when idx is 0. But the
;; locals for frame 0 are not needed, because when we get here
;; from debug-on-entry, the locals aren't bound yet, and when
;; coming from Edebug or ERT there is an Edebug or ERT
;; function at frame 0.
(when (> idx 0)
(setf (backtrace-frame-locals frame)
(backtrace--locals idx (or base 'backtrace-get-frames))))
(when (and eval-buffers (memq (backtrace-frame-fun frame)
'(eval-buffer eval-region)))
;; This will get the wrong result if there are two nested
;; eval-region calls for the same buffer. That's not a very
;; useful case.
(with-current-buffer (pop eval-buffers)
(setf (backtrace-frame-buffer frame) (current-buffer))
(setf (backtrace-frame-pos frame) (point))))))
frames))