6
votes

I work a lot with Asciidoc in emacs (adoc-mode). I believe it has a bug that occurs when editing inlined source code. What happens is emacs freezes, CPU consumption goes to 100%. I can reproduce this behaviour easily.

How do I actually establish what script is causing emacs to hang like that?? And preferably produce a backtrace?

Since emacs freezes while typing within the buffer, rather than after executing a command, stuff like toggle-debug-on-quit or debug-on-entry are useless.

I suppose I could mark every single defun in adoc-mode.el with printfs, but I'm hoping there's an easier way :)

EDIT: So, I ended up grepping my ~/.emacs.d/lisp for ALL defuns and trace-function each one. I was able to narrow down the problem and created a small test case.

These 3 files are required:

$ find /home/victor/.emacs.d/
/home/victor/.emacs.d/
/home/victor/.emacs.d/lisp
/home/victor/.emacs.d/lisp/doc-mode.el
/home/victor/.emacs.d/lisp/adoc-mode.el
/home/victor/.emacs.d/lisp/markup-faces.el

My .emacs:

$ cat .emacs
(setq inhibit-startup-message t)
(add-to-list 'load-path "~/.emacs.d/lisp/")
(require 'adoc-mode)
(switch-to-buffer (find-file "test.doc"))
(adoc-mode)
(goto-char 29)
(delete-backward-char 5)
;; now (adoc-kwf-attriblist) is in endless loop!!

And the testcase is (word "shell" is deleted by elisp):

$ cat test.doc 
blah blah blah
[source,shell]
foo
bar

Now, run emacs and it will hang in (adoc-kwf-attriblist). I don't know much about emacs programming, but seems this thing does not eventually move the point to end position.

 (goto-char (or (text-property-not-all (point) end 'adoc-attribute-list nil)
             end))
2
when emacs freezes, can you interrupt it with C-g?François Févotte
@Francesco: when emacs freezes, it can't be interrupted by \C-g\. Emacs just stays there hanging, not responding events (typing, clicking to close window, etc).Stéphane Gourichon
You are correct -- there is an assumption that if text-property-not-all returns, it returns something greater than point. Unfortunately, it can return the same as point, and so it loops. I've put a fix on githubPhil Lord

2 Answers

1
votes

debug-on-entry might help, if you can identify a function in the sequence that reaches the looper.

Have you tried "apropos" "debug"?

Not sure about debug-on-signal or debug-on-quit. If using Unix "kill" or Windows Task Manager "End Task" sends a signal to emacs, you might intercept it with debug-on-signal.

And search for "debug loop" at https://groups.google.com/forum/#!forum/gnu.emacs.help

Also, you could compile some functins in adoc-mode.el "debug" with edebug-defun.

(I hope I haven't fuddled this topic. I'm new here, and not familiar with "Answer" vs "Comment.)

0
votes

Here is how I would debug it. The freezing might be happening because of some minor mode. You can do C-hm to get a list to the minor modes active. Then start emacs with emacs -Q and load adoc-mode, then load each of the minor modes one by one each time trying to reproduce the issue. This may lead you to the culprit.