Next: , Previous: , Up: Debugging   [Index]


K.3 Edebug

Edebug is a source level debugger for EmacsLisp. It instruments code. This means that Emacs adds special instructions to the code when it is evaluated, to invoke Edebug at the proper places.

edebug-defun (‘C-u C-M-x’)

is the main entry point to Edebug. Use it instead of ‘C-x C-e’ or ‘C-M-x’ to evaluate a ‘defun’ and instrument it for debugging. When you invoke command ‘C-u C-M-x’ (eval-defun with a prefix argument) on a function definition, it instruments the definition before evaluating it.

See the variables:

to control how ~eval-defun~ operates.

See also the commands:

edebug-defun must be able to read your code. It expects all function definitions to start in column 0. If they do not, hitting ‘C-u C-M-x’ will show you the wrong function name in the echo area.

Instrumented Source Code

Once a function is instrumented, any call to the function activates Edebug. The action that occurs depends on which execution mode is active. The default execution mode is ‘step’, which stops execution. You will be viewing a read-only buffer of the source code that is being debugged (the source code buffer). An arrow in the left fringe indicates the line where the function is executing. The special commands of Edebug are available in the source code buffer in addition to the commands of Emacs Lisp mode.

Stop Points

The places within a function where Edebug can stop execution are called “stop points”. These occur both before and after each subexpression that is a list, and also after each variable reference. When Edebug stops execution after an expression, it displays the expression’s value in the echo area.

Commanly Used Edebug Commands

SPC

execute until the next stop point

b

set a breakpoint at a stop point

g

execute until a breakpoint is reached

q

exit Edebug

?

display a l ist of all Edebug commands

Interrupt Edebug Execution

While executing or tracing, you can interrupt the execution by typing any Edebug command. Edebug stops the program at the next stop point and then executes the command you typed. For example, typing ‘t’ during execution switches to trace mode at the next stop point. You can use ‘S’ to stop execution without doing anything else.


Next: Debug Messages, Previous: Debugger Mode, Up: Debugging   [Index]