Sometimes emacsclient fails with an error like:
$ emacsclient .gitlab-ci.yml Waiting for Emacs... *ERROR*: Args out of range: 63695, 1, 1173
How can I debug this?
emacsclient has no debug option, no backtrace is shown, and nothing is logged in the
*Messages* buffer. Running the daemon with
--debug-init does not help.
strace shows what the client sends the server over the socket, so if there is a bug, it is probably on the server side:
$ strace --trace=sendto,recvfrom -s 100 emacsclient ../.gitlab-ci.yml sendto(3, "-dir /home/sam/Downloads/emacs/lisp/ -current-frame -file ../.gitlab-ci.yml \n", 77, 0, NULL, 0) = 77 Waiting for Emacs... recvfrom(3, "-emacs-pid 33810\n-error Args&_out&_of&_range:&_116433,&_1,&_1173", 8192, 0, NULL, NULL) = 64 *ERROR*: Args out of range: 116433, 1, 1173 +++ exited with 1 +++
I ran the daemon in GDB with breakpoints on
xsignal3. Then when I invoke the
emacsclient, I get:
(gdb) bt #0 0x00000000004248da in xsignal3 () #1 0x0000000000423bc4 in args_out_of_range_3 () #2 0x0000000000597ade in Fline_number_at_pos () #3 0x0000000000590b6b in Ffuncall () #4 0x00000000005cc740 in exec_byte_code () #5 0x0000000000593480 in funcall_lambda () #6 0x0000000000590a97 in Ffuncall () #7 0x00000000005cc740 in exec_byte_code () #8 0x0000000000593480 in funcall_lambda () #9 0x0000000000590a97 in Ffuncall () #10 0x0000000000590b79 in funcall_nil () #11 0x000000000059026d in run_hook_with_args () #12 0x0000000000590378 in run_hook () ...snip... #40 0x0000000000429f56 in main ()
The problem is that I am invoking
emacsclient from inside
*ansi-term* inside emacs. For some reason, the emacs server tries to use the position in the
*ansi-term* buffer (63695) in the input file (only 1173 bytes).
This can be fixed by running:
$ emacsclient --eval '(find-file ".gitlab-ci.yml")'
find-file doesn't wait for the file to be closed, so I still want to find out the root of the problem.
It appears (from the stacktrace) some hook, perhaps
'server-after-make-frame-hook, is causing the faulty behavior. But Emacs in my distro is not compiled with debug symbols, so I can't poke around in that frame easily. Is there an elisp way of seeing what functions are bound to a hook?
The problem seems to go away when I disable
(indent-guide-global-mode), but I'm not sure why.