I am using mew for my e-mail. I need to use TLS with my email provider for SMTP. However, when I try to invoke that, Emacs freezes.

I would like to take this opportunity to learn more about Emacs packages. How would I go about debugging this issue? Is there some kind of built-in debugger, like in Common Lisp? Could I use logging?

  • 2
    How do you "invoke that"? If it is by using an Emacs command that is defined in Lisp then you can (1) load the source code that defines the command, (2) use M-x debug-on-entry THE-COMMAND, then step through the debugger using d (or sometimes c to skip through some steps). Keep the source code open in another frame, so you can follow what the debugger is doing. Report what you see here or, if you think it suggests an Emacs bug, using M-x report-emacs-bug. – Drew Oct 3 '14 at 4:41

Before resorting to gdb, if you're using a Unix-y operating system, you can try sending SIGUSR2 to the Emacs process, like documented in the DEBUG file mentioned in the other answer.

$ kill -SIGUSR2 <emacs_pid_goes_here>

This will make Emacs attempt to break out of its current loop into the Lisp debugger.

Or use this one liner without typing emacs pid manually:

$ ps aux | grep -ie emacs | grep -v grep | awk '{print $2}' | xargs kill -SIGUSR2

Alternatively, if killall is available:

$ killall -USR2 emacs
  • Had to do it twice (well, I could have waited more than 1 second before retrying :-). Anyway, it pinpointed the problem (a font-lock processing too slow for a long line). – Stéphane Gourichon Feb 28 '16 at 15:18
  • font-lock is known to hang Emacs -- if a matcher trigger but doesn't move the point forward, it will retrigger forever. – Lindydancer May 18 '16 at 11:13
  • wow, that was amazing. Still not sure what's causing my issue but that trick is a lifesaver, thank you! – Matt Dec 23 '16 at 14:32
  • 2
    On my system the oneliner can be simplified to ‘killall -USR2 emacs’ (avoid if you have multiple Emacs processes of course). – YoungFrog Mar 4 '17 at 7:20
  • 1
    Recommend htop (en.wikipedia.org/wiki/Htop) for this. / to search for emacs and k to send the signal. Activity Monitor on a Mac can also do it (from the menu: View | Send Signal to Process). – Lassi Sep 8 at 9:59

If the freeze goes away when you hit C-g, then you can use the built-in debugger. Type M-x toggle-debug-on-quit before sending the message, hit C-g when it freezes, and inspect the *Backtrace* buffer that comes up.

If C-g doesn't help, then the freeze probably happens in the C code, and you'll need to use an external debugger such as gdb. Hit C-h C-d to see the DEBUG file which gives some hints about how to do that. (You can also read the DEBUG file in the Emacs repository web interface.) This answer goes into more details about how to use gdb with Emacs.

  • You might have to hit C-g several times: C-g C-g C-g. – Drew Oct 3 '14 at 4:37
  • @Drew I've also noticed that hitting it several times is necessary. Do you know why? – Wilfred Hughes Oct 3 '14 at 8:21
  • 2
    Yes. See the Emacs manual, node Quitting. How did I find that? C-h r i, then type "C-g" and hit RET. – Drew Oct 3 '14 at 15:12

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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