While debugging a minor mode (separate issue), I wanted to generate a stack trace of the message function so I thought I would just enter

M-x debug-on-entry RET message

I was quite surprised to see that this method did not work. No stack trace was generated instead I started to get the error

Lisp nesting exceeds `max-lisp-eval-depth'

Which probably means that the message function was being called from the debugger, and debugger was calling message again making an infinite loop. Is there a more fool-proof way of generating full traces of who called the message function ?


You want to use the debug-on-message variable in this situation.

If non-nil, debug if a message matching this regexp is displayed.
  • Good answer, was it easy to find in the docs ? I tried apropos but gave up maybe too quickly.
    – Pushpendre
    Mar 18 '15 at 3:40
  • 1
    It's certainly easy if you already know it's there :) I first spotted it in the NEWS file when 24.3 was released. Searching for "debug" with apropos finds it quickly enough, I think? In the manual you can find it under both (elisp) Error Debugging and also (elisp) Explicit Debug, and a repeated isearch for "message" in the debugger section turns it up pretty soon. So yeah... you probably gave up a bit early in this instance.
    – phils
    Mar 18 '15 at 6:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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