None of the other answers work for me. When my emacs hangs, I can only bring it back by killing and restarting it, but then after a while it hangs again. So there has to be a way to find out the reason.
One of the method that I used was to attach it to gdb. When emacs hangs, I executed the following command to attach gdb to Emacs:
sudo gdb attach 967
967
is the PID of emacs(which can be found by running ps -aux | grep emacs
). When you see the (gdb)
prompt, input bt full
to get the backtrace. For example, when my emacs hangs, my backtrace is:
(gdb) bt full
#0 0x00007f569cd2046f in poll () at /usr/lib/libc.so.6
#1 0x00007f569dfd263b in () at /usr/lib/libxcb.so.1
#2 0x00007f569dfd437b in xcb_wait_for_event () at /usr/lib/libxcb.so.1
#3 0x00007f569e038209 in _XReadEvents () at /usr/lib/libX11.so.6
#4 0x00007f569e01f396 in XIfEvent () at /usr/lib/libX11.so.6
#5 0x00007f569e068ca0 in () at /usr/lib/libX11.so.6
#6 0x00007f569e0699d2 in () at /usr/lib/libX11.so.6
#7 0x00007f569e069c6c in _XimRead () at /usr/lib/libX11.so.6
#8 0x00007f569e0583ce in () at /usr/lib/libX11.so.6
#9 0x00007f569e045955 in XSetICValues () at /usr/lib/libX11.so.6
#10 0x0000561ace6df9b3 in ()
#11 0x0000561ace6627a7 in ()
#12 0x0000561ace61e5a5 in ()
#13 0x0000561ace61eb33 in ()
#14 0x0000561ace61ffdb in ()
#15 0x0000561ace6201fb in ()
#16 0x0000561ace659154 in ()
#17 0x0000561ace65a6b5 in ()
#18 0x0000561ace7054ff in ()
#19 0x0000561ace7bc9e0 in ()
#20 0x0000561ace6210d3 in ()
#21 0x0000561ace707efd in ()
#22 0x0000561ace708928 in ()
#23 0x0000561ace70a06f in ()
#24 0x0000561ace7779e7 in ()
#25 0x0000561ace6fae65 in ()
#26 0x0000561ace777942 in ()
#27 0x0000561ace6fadfd in ()
#28 0x0000561ace70040b in ()
#29 0x0000561ace700734 in ()
#30 0x0000561ace616de1 in ()
#31 0x00007f569cc53152 in __libc_start_main () at /usr/lib/libc.so.6
#32 0x0000561ace61753e in ()
Something seems to be wrong with xcb
, then I googled for xcb_wait_for_event emacs
and found this post which solves my problem after I followed its solution: https://gitlab.freedesktop.org/xorg/lib/libx11/-/issues/35
I'm not a expert in gdb
or emacs
or c
, but at least gdb
gave me a clue about what should I look at. I suggest you try do the same if neither C-g
nor kill -SIGUSR2
works for you.
M-x debug-on-entry THE-COMMAND
, then step through the debugger usingd
(or sometimesc
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, usingM-x report-emacs-bug
.