summaryrefslogtreecommitdiff
path: root/devdocs/elisp/instrumenting.html
blob: 04d6c54c9c08676a7d52cc289c8492ee992954c0 (plain)
1
2
3
4
5
6
7
8
 <h4 class="subsection">Instrumenting for Edebug</h4>  <p>In order to use Edebug to debug Lisp code, you must first <em>instrument</em> the code. Instrumenting code inserts additional code into it, to invoke Edebug at the proper places. </p>   <p>When you invoke command <kbd>C-M-x</kbd> (<code>eval-defun</code>) with a prefix argument on a function definition, it instruments the definition before evaluating it. (This does not modify the source code itself.) If the variable <code>edebug-all-defs</code> is non-<code>nil</code>, that inverts the meaning of the prefix argument: in this case, <kbd>C-M-x</kbd> instruments the definition <em>unless</em> it has a prefix argument. The default value of <code>edebug-all-defs</code> is <code>nil</code>. The command <kbd>M-x edebug-all-defs</kbd> toggles the value of the variable <code>edebug-all-defs</code>. </p>    <p>If <code>edebug-all-defs</code> is non-<code>nil</code>, then the commands <code>eval-region</code>, <code>eval-current-buffer</code>, and <code>eval-buffer</code> also instrument any definitions they evaluate. Similarly, <code>edebug-all-forms</code> controls whether <code>eval-region</code> should instrument <em>any</em> form, even non-defining forms. This doesn’t apply to loading or evaluations in the minibuffer. The command <kbd>M-x edebug-all-forms</kbd> toggles this option. </p>   <p>Another command, <kbd>M-x edebug-eval-top-level-form</kbd>, is available to instrument any top-level form regardless of the values of <code>edebug-all-defs</code> and <code>edebug-all-forms</code>. <code>edebug-defun</code> is an alias for <code>edebug-eval-top-level-form</code>. </p> <p>While Edebug is active, the command <kbd>I</kbd> (<code>edebug-instrument-callee</code>) instruments the definition of the function or macro called by the list form after point, if it is not already instrumented. This is possible only if Edebug knows where to find the source for that function; for this reason, after loading Edebug, <code>eval-region</code> records the position of every definition it evaluates, even if not instrumenting it. See also the <kbd>i</kbd> command (see <a href="jumping">Jumping</a>), which steps into the call after instrumenting the function. </p> <p>Edebug knows how to instrument all the standard special forms, <code>interactive</code> forms with an expression argument, anonymous lambda expressions, and other defining forms. However, Edebug cannot determine on its own what a user-defined macro will do with the arguments of a macro call, so you must provide that information using Edebug specifications; for details, see <a href="edebug-and-macros">Edebug and Macros</a>. </p> <p>When Edebug is about to instrument code for the first time in a session, it runs the hook <code>edebug-setup-hook</code>, then sets it to <code>nil</code>. You can use this to load Edebug specifications associated with a package you are using, but only when you use Edebug. </p>  <p>If Edebug detects a syntax error while instrumenting, it leaves point at the erroneous code and signals an <code>invalid-read-syntax</code> error. Example: </p> <div class="example"> <pre class="example">error→ Invalid read syntax: "Expected lambda expression"
</pre>
</div> <p>One potential reason for such a failure to instrument is that some macro definitions are not yet known to Emacs. To work around this, load the file which defines the function you are about to instrument. </p>  <p>To remove instrumentation from a definition, simply re-evaluate its definition in a way that does not instrument. There are two ways of evaluating forms that never instrument them: from a file with <code>load</code>, and from the minibuffer with <code>eval-expression</code> (<kbd>M-:</kbd>). </p>  <p>A different way to remove the instrumentation from a definition is to use the <code>edebug-remove-instrumentation</code> command. It also allows removing the instrumentation from everything that has been instrumented. </p> <p>See <a href="edebug-eval">Edebug Eval</a>, for other evaluation functions available inside of Edebug. </p><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/Instrumenting.html" class="_attribution-link">https://www.gnu.org/software/emacs/manual/html_node/elisp/Instrumenting.html</a>
  </p>
</div>