The Debugger

Emacs Lisp has a built-in debugging mode that can be invoked automatically under certain circumstances. Entering the debugger is controlled as follows.

debug-on-entry

This is a command. It prompts (with completion) for the name of a function. Whenever that function is invoked, Emacs will enter the debugger.

debug-on-error

This is a variable. If it is non-nil, then Emacs will enter the debugger whenever an error is signaled.

debug-on-next-call

This is a variable. If it is non-nil, Emacs will enter the debugger the very next time an expression is to be evaluated.

debug-on-quit

This is a variable. If it is non-nil, Emacs will enter the debugger whenever a "quit" is signaled (e.g., when the user presses C-g).

When the debugger is invoked, a window displaying the Lisp stack appears. In this buffer, called *Backtrace*, each line represents a pending function call, with the top lines representing more recent calls. You can see the pending Lisp expressions, test the values of variables and other expressions in different contexts, and force a function to return a certain value.

These are the useful debugging-mode commands.

c

Leave the debugger, continuing whatever code was interrupted by entering it. This isn't possible when the debugger was invoked because of an error.

q

Leave the debugger, aborting the pending computation.

d

Continue execution until the next function call, then reenter the debugger.

e

Prompt for a Lisp expression to evaluate in the context of the topmost stack "frame."

b

"Break" ...

Get Writing GNU Emacs Extensions now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.