0

When using edebug, stepping into a function call works.

But if I change the function call from

(foo args)

to

(apply '#foo args)

edebug says apply is built-in function and won't let me step into.

I can find the definition of foo and "instrument" it (by edebug-defun).
But wonder if there's a better way

eugene
  • 481
  • 1
  • 5
  • 11

2 Answers2

1

Edebug works by instrumenting the definition of a function at the Lisp level: it cannot work on a built-in function like apply because there is no Lisp definition that it can get its hands on to instrument.

If you are trying to debug apply, you have to do it by running Emacs under a debugger like GDB and putting a breakpoint on the C function that is called apply at the Lisp level. Do C-h f apply, follow the link and you'll see that the C function is called Fapply. So, start Emacs under GDB, put a breakpoint on Fapply, start the program (i.e. Emacs) from the debugger and call apply from Lisp: it will stop at the first statement of Fapply and you can single step (in the C code) from there.

See the GDB manual for details. The point is that GNU Emacs is a C program, not a Lisp program, despite the fact that most of its functionality is implemented in Lisp: the core of it is written in C.

NickD
  • 27,023
  • 3
  • 23
  • 42
  • 1
    Maybe OP also needs to configure Emacs with `-Og` and then rebuild it for a better debugging experience. – shynur Sep 02 '23 at 13:22
  • @shynur oh, I think " --with-debug " (of emacs-plus) does add that flag, what does it buy you? (would it make my emacs go slower when not doing debugging?) I guess that enables me to debug the "C" part of the emacs .. Well if that indeed helps to debug elisp code (cause instrumenting dynamically loaded function by apply is tiresome), I could try. But If it means going back and force between gdb and edebugger, I doubt it'll be any more pleasant – eugene Sep 02 '23 at 14:02
  • It will be difficult to use GDB in order to debug Lisp code: you need to know a whole lot. So if you want to debug Lisp code, use Edebug (or the built-in debugger). E.g if you instrument the Lisp function `foo` with Edebug, you can call it with `apply` and it will stop when `apply` calls `foo`. – NickD Sep 02 '23 at 18:52
0

You're applying apply wrong. If you want to apply your function foo to zero arguments then you pass apply a list of zero arguments as the second argument:

(apply #'foo ())
Drew
  • 75,699
  • 9
  • 109
  • 225
  • 1
    oh, right, I was actually using argument in my code.. but didn't know it requires zero arguments list. – eugene Sep 02 '23 at 03:57