I was expecting to find tools I can use to to e.g. prettify the stack trace, or e.g. show all variables that are bound at each level of the stack trace as you navigate, but haven't found anything. Do any tools to improve the debugging experience exist?

No hits on melpa: https://melpa.org/#/?q=debug%20elisp

  • 1
    Here is a related thread (maybe sufficiently related to make this current thread a potential duplicate) -- "Can emacs show formatted backtraces?": emacs.stackexchange.com/questions/54311/… – lawlist May 27 '20 at 6:19
  • A good link. I'd mark it as a duplicate if it were just about the formatting, but I think the scope of this question is broader. – phils May 27 '20 at 10:53
  • This is very useful to know, though perhaps not a duplicate since the scope of this question is broader; around how to find tools for improving the debugging experience. That said, I realize now this may be a bit of an edgy question for SO since it really is requesting a list, instead of a single answer; but the hope was that there is a single resource that is maintaining that list. (Or at least it is a suggestion for anyone who wants to make such a list and link to it!) – avv May 27 '20 at 17:43

Emacs 27: C-hig (elisp)Backtraces

18.1.7 Backtraces

Debugger mode is derived from Backtrace mode, which is also used to show backtraces by Edebug and ERT. (*note Edebug::, and *note the ERT manual: (ert)Top.)

The backtrace buffer shows you the functions that are executing and their argument values. When a backtrace buffer is created, it shows each stack frame on one, possibly very long, line. (A stack frame is the place where the Lisp interpreter records information about a particular invocation of a function.) The most recently called function will be at the top.

In a backtrace you can specify a stack frame by moving point to a line describing that frame. The frame whose line point is on is considered the “current frame”.

If a function name is underlined, that means Emacs knows where its source code is located. You can click with the mouse on that name, or move to it and type , to visit the source code. You can also type while point is on any name of a function or variable which is not underlined, to see help information for that symbol in a help buffer, if any exists. The ‘xref-find-definitions’ command, bound to , can also be used on any identifier in a backtrace (*note (emacs)Looking Up Identifiers::).

In backtraces, the tails of long lists and the ends of long strings, vectors or structures, as well as objects which are deeply nested, will be printed as underlined “...”. You can click with the mouse on a “...”, or type while point is on it, to show the part of the object that was hidden. To control how much abbreviation is done, customize ‘backtrace-line-length’.

Here is a list of commands for navigating and viewing backtraces:

‘v’ Toggle the display of local variables of the current stack frame.

‘p’ Move to the beginning of the frame, or to the beginning of the previous frame.

‘n’ Move to the beginning of the next frame.

‘+’ Add line breaks and indentation to the top-level Lisp form at point to make it more readable.

‘-’ Collapse the top-level Lisp form at point back to a single line.

‘#’ Toggle ‘print-circle’ for the frame at point.

‘:’ Toggle ‘print-gensym’ for the frame at point.

‘.’ Expand all the forms abbreviated with “...” in the frame at point.

  • I remark that much of this is new in emacs 27: in particular, the helpful + to pretty print the frame is not available, as far as I can see, in 26.3. – Fran Burstall May 27 '20 at 10:24
  • Indeed, my intention here was to advertise that many of the requested features have been implemented for this upcoming release. – phils May 27 '20 at 10:47
  • 2
    The user option debugger-stack-frame-as-list is also worth highlighting, I think. – phils May 27 '20 at 10:50

It's possible to format backtraces differently using mapbacktrace with a custom function. One such example is always printing the items as list, I've contributed a patch introducing the debugger-stack-frame-as-list customizable that does that. Check out the implementation of backtrace in Emacs 26.1 or newer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.