3

I am trying to debug a problem with the alert.el package using edebug. However, I am unable to step through the alert function.

I expect the debugger to enter the function and allow me to step through. Instead, it terminates.

Here is what I'm doing:

  1. Open an Emacs instance opened with emacs -Q
  2. Evaluate (package-initialize)
  3. Call C-u C-M-x on (alert "Hello, world!")

At this point, I see an indicator in my fringe.

On the fringe

  1. Press i to step into the function call

On pressing i, I quickly see "Go..." printed to the minibuffer and the fringe indicator disappears.

I am no longer debugging.


Checking C-h f alert shows me that it is an autoloaded function. Might this be affecting my ability to step into it?

I have tried toggling (debug-on-error) and stepping through with d. However, I can't see the source code while stepping. Whenever I try to open another buffer with the source code in it, pressing d in the *Backtrace* closes the source code buffer. Is there a way to use (debug-on-error) and see the source code while stepping through execution?

Any advice you have for debugging is welcome.

Lorem Ipsum
  • 4,327
  • 2
  • 14
  • 35
  • You can explicitly load `alert.el` with `load-library` or `require`. – Tobias Aug 02 '19 at 19:23
  • That was something I tried, running `(require 'alert)` after Step 2. When I did that, I experienced the same behavior with `edebug`. I did notice however that the help description changes to say `"alert is an autoloaded Lisp closure..."`. Might that affect `edebug`'s behavior? I noticed this line in the documentation: "Most Emacs Lisp programs, however, should not interact directly with lexical environments in this way; only specialized programs like debuggers." https://www.gnu.org/software/emacs/manual/html_node/elisp/Lexical-Binding.html#Lexical-Binding – Lorem Ipsum Aug 02 '19 at 19:46
  • 2
    Step 3 i s wrong: you need to do `C-u C-M-x` on the *definition* of the alert function, not on its use. – NickD Aug 02 '19 at 20:29
  • @NickD, I think you answered this question, which seems to have really been about the use of the `eval-defun` or `edebug-eval-defun`. It so happens that the definition of `alert` is simply `(defgroup alert nil :group 'emacs)`. I have questions about how to debug this, but that's probably better suited for a separate question. I'll polish up this post to better reflect the question it's asking. You post your comment as an answer and I'll accept it. Thank you! – Lorem Ipsum Aug 02 '19 at 20:46
  • 1
    That's not true: there is a customization *group* called `alert` and there is a *function* called `alert`: go to line 1022 of `alert.el` to see it. It's the latter that you want to apply `C-u C-M-x` to. – NickD Aug 02 '19 at 20:56
  • 1
    Strange xref-find-definition brings you to the defgroup but should prolly take you to `(cl-defun alert ...` at line 1023. If you debug the cl-defun it works as expected. – Hubisan Aug 02 '19 at 20:58

2 Answers2

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 function on line 1022 or thereabouts. That's where you want to do C-u C-M-x.

NickD
  • 27,023
  • 3
  • 23
  • 42
0

For anyone using a framework like doom emacs C-u C-M-x is edebug-defun and it doesn't have any keybinding by default (using edebug in doom emacs isn't documented at all as a matter of fact so you are on your own when trying to debug emacs lisp).