My work flow to debug emacs plugin

  |   Source

Author: Chen Bin <chenbin.sh AT gmail DOT com> Created: 2013-03-30 Sat

This is my quick guide on how to start debugging elisp. It's written for developers who are already experienced on debugging program but too lazy to read the Edebug manual.

The most critical set up for the debugging is to set the hot key "C-h C-f" to the command "find-function" so you can jump the definition of the function easily.

(global-set-key (kbd "C-h C-f") 'find-function)

Here is my workflow.

start the debugging

  • Jump to the definition of the command (The hot key is "C-h C-f", as I mentioned before).
  • Run "M-x edebug-defun" . This will set the breakpoint into the entry of the command. BTW, I run "M-x eval-defun" in the function body to undo "edebug-defun".
  • Run the command to be debugged from Emacs
  • Press "space" key (M-x edebug-step-mode) to debug the program step by step
  • Watch the value of expression in the mini-buffer when you press "space" key

basic debug operation

  • Press "i" key (M-x edebug-step-in) to step in
  • Press "o" key (M-x edebug-step-out) to step out
  • Press "b" key (M-x edebug-set-breakpoint) to set the break point (press "u" key unset break point. I don't use this though)
  • Press "g" key (M-x edebug-go-mode) to continue
  • Press "h" key (M-x edebug-goto-here) to proceed until at the current line

Watch the variable and functions

  • Press "e" key (M-x edebug-eval-expression) to run the expression in the context outside of Edebug. Basically it means print a variable's value. Very useful.
  • Press "C-x C-e" key (M-x edebug-eval-last-sexp) in the context outside of Edebug. Similar to "e", useful if you are lazy to input the expression manually.

"Outside of Edebug" means you are only watching the variable's value. You will NOT change the status of program being debugged

Set the variable

  • Press "M-:" key (M-x eval-expression) to evaluate the expression in the context of Edebug itself.

I usually don't do this. It's not my debugging style.

Comments powered by Disqus