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

2 Answers 2

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.

4
  • 1
    Maybe OP also needs to configure Emacs with -Og and then rebuild it for a better debugging experience.
    – shynur
    Commented Sep 2, 2023 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
    Commented Sep 2, 2023 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
    Commented Sep 2, 2023 at 18:52
  • @NickD Thanks. I suspected so. I was hoping if there's a way to tell edebug how to instrument functions that I didn't specify . For instance, if I declare fn = 'foo then apply fn args, would edebug be able to pick up since it can see my code right here? or similar trick might exist I don't know about, so I was wondering.. Thank you anyway
    – eugene
    Commented Sep 3, 2023 at 11: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 ())
1
  • 1
    oh, right, I was actually using argument in my code.. but didn't know it requires zero arguments list.
    – eugene
    Commented Sep 2, 2023 at 3:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.