Hot answers tagged

19

From (info "(elisp) Instrumenting") : 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 `load', and from the minibuffer with `eval-expression' (`M-:'). IOW, the easy way is to use C-M-x without prefix ...


16

Emacs provides a good amount of debugging facilities including M-x toggle-debug-on-error, M-x toggle-debug-on-quit, debug on signal (which can be used by sending USR2 to Emacs from outside), debug-on-entry (of a function), debug-on-message (when seeing a specific regexp match of a message) and finally, debug itself as alternative to instrumenting a function ...


9

In other words, how do I rescind the directive that causes edebug to enter debugging mode when a particular function is invoked? You can get this effect without removing instrumentation by setting edebug-initial-mode to go. This way, you will only get stopped in edebug if there is a breakpoint set. As of Emacs 25.1, you can do this quickly with edebug-set-...


9

When you call edebug-defun it debugs the top-level form, which in this case is (use-package ...). You can use debug-on-entry to debug a named function.


8

This is still under development, but in Emacs 26.1 (assuming nothing goes wrong) you will be able to do M-x debug-watch <variable> RET and then any change to the variable will land in the debugger with a backtrace. You can get the patchset now, at https://debbugs.gnu.org/cgi/bugreport.cgi?bug=24923. Does your patch enable attaching arbitrary code ...


6

Consensus seems to be that there is no such function built-in. Since edebug instrumentation data is stored on the target symbols, I have been using the following basic function: (defun ebpa/edebug-remove-all-instrumentation () "Remove all edebug instrumentation by visiting each function definition and running `eval-defun`." (interactive) (mapatoms ...


6

Edebug does not support instrumenting code constructed at runtime. If you try to instrument create-function, then the stepping will occur when you evaluate (create-function 2), not when you execute square-two. Edebug does support instrumenting lambda forms though, so you can rewrite your example using lexical binding: ;;; -*- lexical-binding: t -*- (defun ...


6

Maybe because it's 2018 now, but in my case, I only had to turn on debugging like wasamasa suggested: M-x toggle-debug-on-error After this, M-x eval-buffer on my faulty Elisp file gave context by providing the position of the error, like this: Debugger entered--Lisp error: (invalid-read-syntax ")") eval-buffer() ; Reading at buffer position 523 ...


4

So it appears that the problem in this case was related to the function being declared in a buffer which doesn't have a file associated with it, thus Emacs was unable to locate the definition. Here's how I discovered this: I started by looking into the definition of edebug-step-in (I figured out this is the function called in debug mode when I press i for ...


4

Mark the appropriate defun and call C-x nn (narrow-to-region) C-u C-M-x (edebug-defun) C-x nw (widen) If you like doing things quickly, lispy shortcut for this is N xe W.


4

True to form, I found the answer while asking the question. For anyone else who finds this useful: (view-buffer-other-window (current-buffer)) If you place this form anywhere in the form that's being instrumented, you'll see point move in real-time as you step through the code. For example, (defun fancy-stuff () (with-current-buffer (get-crazy-process-...


3

The reason for that behavior is simply that different interactive forms are used in edebug-eval-expression and eval-expression. You can just override the interactive form of edebug-eval-expression with a part of the interactive form of eval-expression. (Direct replacement of the interactive form does not work since that two functions differ in the number of ...


3

edebug-defun Thanks to @abo-abo for the tip to mark the defun first. Here is a quick way to enable/disable edebug-defun. This uses search-backward-regexp to edebug-instrument or eval the defun or defmacro name correctly, whether it is defined in use-package wrapper or not. ;; Edebug a defun or defmacro (defvar modi/fns-in-edebug nil "List of functions ...


3

You can step into bar (or any function call) with no previous preparation. eval-buffer (not necessary if everything's already defined). Invoke C-u C-M-x on foo to instrument it. Ivoke M-x foo and you'll be taken immediately into edebug, with point right before the (bar) expression. In edebug, with point right before a function call, you can hit i to ...


3

You may be able to do this by surrounding definitions of function you want to instrument with (edebug-all-defs). (edebug-all-defs) ;; this one is instrumented (defun foo () (bar)) ;; this one is, too (defun bar () (message "hi!")) (edebug-all-defs) ;; this one is not (defun baz () (bar)) Now foo and bar are instrumented, and baz is not. I found ...


2

I prefer to debug stuff with lispy instead of Edebug, possibly using Edebug for setup. For me, the biggest advantage is that I can keep the debug state around, without worrying that if I mistype something in Edebug, all the debug context that I've worked on for 10 minutes will vanish and I would have to start from scratch. It's also great for setting test ...


2

You can use the variable debugger-old-buffer to get the buffer where the debugger was entered.


2

This is Emacs Bug#24750, which is fixed in the master branch (what will become 26.1). For earlier versions, you can add ["using" (symbolp symbolp)] to cl-loop's edebug spec. (put 'cl-loop 'edebug-form-spec '(&rest &or [[&or "for" "as" "with" "and"] sexp] [[&or "from" "upfrom" "downfrom" "to" "...


2

There is a similar question there: Running Elisp code when a variable is changed that is closed as a duplicate. The feature is needed there for emacs 24.5. You get the backtrace at a setq of a critical symbol with the following code. Execute the code below and (debug-setq 'desktop-dirname) before you load the critical section of your lisp code. Please note ...


2

Add (debug) and you'll be thrown into a buffer showing you the backtrace and where you can examine the current state. See: Emacs Manual "Explicit Entry to the Debugger"


2

I found this question because I was having trouble debugging a function that used with-temp-buffer. Using edebug one can press p to temporarily switch to where point is, but this isn't much good because the temp buffer will be gone once edebug is finished. The easy way in this case is to replace (with-temp-buffer stuff) with (with-current-buffer (get-...


2

Yes. M-x debug-on-entry RET square-two RET M-: (square-two) RET Debugger entered--entering a function: * square-two() eval((square-two) nil) eval-expression((square-two) nil nil 127) funcall-interactively(eval-expression (square-two) nil nil 127) call-interactively(eval-expression nil nil) command-execute(eval-expression) Use d to step through ...


2

The REPL interaction mode you are looking for is probably met by ielm (Inferior Emacs Lisp mode). Here's the start of a solution†: Open ielm-mode with M-x ielm. Advise ielm-eval-input to wrap the expressions with edebug-eval-expression: (defun my/ielm-edebug-eval-input (orig-func input-string &rest args) "Wrapper function for evaluating expressions ...


2

You need to apply C-u C-M-x on the definition of a function in order to enable edebug to instrument it for debugging. Your step 3. applies it to the use of the function, which does not do anything useful. Download the alert.el file and load it with e.g. (load-file "/path/to/alert.el"), then open the file in emacs and navigate to the definition of the alert ...


2

Emacs 27: C-hig (elisp)Backtraces 18.1.7 Backtraces Debugger mode is derived from Backtrace mode, which is also used to show backtraces by Edebug and ERT. (*note Edebug::, and *note the ERT manual: (ert)Top.) The backtrace buffer shows you the functions that are executing and their argument values. When a backtrace buffer is created, it ...


2

Customize the user option C-hv edebug-initial-mode or use M-x edebug-set-initial-mode1 to set the value go instead of the default step. In the absence of relevant breakpoints, an instrumented function will now simply run to completion without interruption. Note that you can set breakpoints in an instrumented function with M-x edebug-set-breakpoint or M-x ...


2

If you are using messages to yourself while developing then: That's fine - nothing wrong with using message. You can also define a wrapper for such uses of message, which respects a global variable you define. That gives you a quick way to turn such messages on/off or otherwise affect them. An alternative is to use debug, to use the Emacs debugger: M-x ...


1

BTW, while npostavs's solution is the better option for your example, in those cases where you really do need to build the code manually with backquotes (e.g. inside defmacro), you can try: (defun create-function (number) (edebug-\` (lambda () (* ,number ,number))))


1

Edebug is arguably right: The tag is not evaluated and needs to be a symbol, not (quote foo).


Only top voted, non community-wiki answers of a minimum length are eligible