summaryrefslogtreecommitdiff
path: root/devdocs/elisp/function-debugging.html
blob: 822d3b7a6286c43c61f18bc2f1ffe82109126a7e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
 <h4 class="subsection">Entering the Debugger on a Function Call</h4>   <p>To investigate a problem that happens in the middle of a program, one useful technique is to enter the debugger whenever a certain function is called. You can do this to the function in which the problem occurs, and then step through the function, or you can do this to a function called shortly before the problem, step quickly over the call to that function, and then step through its caller. </p> <dl> <dt id="debug-on-entry">Command: <strong>debug-on-entry</strong> <em>function-name</em>
</dt> <dd>
<p>This function requests <var>function-name</var> to invoke the debugger each time it is called. </p> <p>Any function or macro defined as Lisp code may be set to break on entry, regardless of whether it is interpreted code or compiled code. If the function is a command, it will enter the debugger when called from Lisp and when called interactively (after the reading of the arguments). You can also set debug-on-entry for primitive functions (i.e., those written in C) this way, but it only takes effect when the primitive is called from Lisp code. Debug-on-entry is not allowed for special forms. </p> <p>When <code>debug-on-entry</code> is called interactively, it prompts for <var>function-name</var> in the minibuffer. If the function is already set up to invoke the debugger on entry, <code>debug-on-entry</code> does nothing. <code>debug-on-entry</code> always returns <var>function-name</var>. </p> <p>Here’s an example to illustrate use of this function: </p> <div class="example"> <pre class="example">(defun fact (n)
  (if (zerop n) 1
      (* n (fact (1- n)))))
     ⇒ fact
</pre>
<pre class="example">(debug-on-entry 'fact)
     ⇒ fact
</pre>
<pre class="example">(fact 3)
</pre>

<pre class="example">------ Buffer: *Backtrace* ------
Debugger entered--entering a function:
* fact(3)
  eval((fact 3))
  eval-last-sexp-1(nil)
  eval-last-sexp(nil)
  call-interactively(eval-last-sexp)
------ Buffer: *Backtrace* ------
</pre>

</div> </dd>
</dl> <dl> <dt id="cancel-debug-on-entry">Command: <strong>cancel-debug-on-entry</strong> <em>&amp;optional function-name</em>
</dt> <dd><p>This function undoes the effect of <code>debug-on-entry</code> on <var>function-name</var>. When called interactively, it prompts for <var>function-name</var> in the minibuffer. If <var>function-name</var> is omitted or <code>nil</code>, it cancels break-on-entry for all functions. Calling <code>cancel-debug-on-entry</code> does nothing to a function which is not currently set up to break on entry. </p></dd>
</dl><div class="_attribution">
  <p class="_attribution-p">
    Copyright &copy; 1990-1996, 1998-2022 Free Software Foundation, Inc. <br>Licensed under the GNU GPL license.<br>
    <a href="https://www.gnu.org/software/emacs/manual/html_node/elisp/Function-Debugging.html" class="_attribution-link">https://www.gnu.org/software/emacs/manual/html_node/elisp/Function-Debugging.html</a>
  </p>
</div>