debug-on-entry
A second way to start debug
on a function is to enter the
debugger when you call the function. You can do this by calling
debug-on-entry
.
Type:
M-x debug-on-entry RET triangle-bugged RET
Now, evaluate the following:
(triangle-bugged 5)
Emacs will create a `*Backtrace*' buffer and tell you that it is
beginning to evaluate the triangle-bugged
function:
---------- Buffer: *Backtrace* ---------- Entering: * triangle-bugged(5) eval((triangle-bugged 5)) eval-last-sexp(nil) * call-interactively(eval-last-sexp) ---------- Buffer: *Backtrace* ----------
In the `*Backtrace*' buffer, type d. Emacs will evaluate
the first expression in triangle-bugged
; the buffer will look
like this:
---------- Buffer: *Backtrace* ---------- Beginning evaluation of function call form: * (let ((total 0)) (while (> number 0) (setq total ...) (setq number ...)) total)) triangle-bugged(5) * eval((triangle-bugged 5)) eval-last-sexp(nil) * call-interactively(eval-last-sexp) ---------- Buffer: *Backtrace* ----------
Now, type d again, eight times, slowly. Each time you type d, Emacs will evaluate another expression in the function definition. Eventually, the buffer will look like this:
---------- Buffer: *Backtrace* ---------- Beginning evaluation of function call form: * (setq number (1= number))) * (while (> number 0) (setq total (+ total number)) (setq number (1= number)))) * (let ((total 0)) (while (> number 0) (setq total ...) (setq number ...)) total)) triangle-bugged(5) * eval((triangle-bugged 5)) eval-last-sexp(nil) * call-interactively(eval-last-sexp) ---------- Buffer: *Backtrace* ----------
Finally, after you type d two more times, Emacs will reach the error, and the top two lines of the `*Backtrace*' buffer will look like this:
---------- Buffer: *Backtrace* ---------- Signalling: (void-function 1=) * (1= number)) ... ---------- Buffer: *Backtrace* ----------
By typing d, you were able to step through the function.
You can quit a `*Backtrace*' buffer by typing q; this quits
the trace, but does not cancel debug-on-entry
.
To cancel the effect of debug-on-entry
, call
cancel-debug-on-entry
and the name of the function, like this:
M-x cancel-debug-on-entry RET triangle-debugged RET
(If you are reading this in Info, cancel debug-on-entry
now.)
Go to the first, previous, next, last section, table of contents.