Subject: Re: bug#29548: 25.2; How to DEBUG get-device-terminal

From: Live System User <[email-masked]>
Date: Wed, 06 Dec 2017 13:49:05 -0500

Noam Postavsky <[email-masked]> writes:

> Live System User <[email-masked]> writes:
>
>> Hi,
>>
>>         I currently have an Emacs (GUI) proceaa giving the
>>         error:
>>
>> get-device-terminal: Invalid argument #<terminal 5> in
>> 'get-device-terminal'
>> Error running timer battery-update-handler' (error Invalid argument
>> #<terminal 5> in 'get-device-terminal'")
>>
>>         I belive this happened in my setup after I did the following
>>         in conjuction with an Emacs daemon process:
>>
>>           (From a terminall shell prompt)
>>           $ emacsclient -c file1.txt
>>           (Emacs frame pops up)
>>
>>           From another terminal shell prompt::
>>           $ emacsclient -t file1.txt
>>           (terminal shows Emacs with file1.txt buffer)
>>           'C-x 5 0' "(delete-frame)" in Emacs (TTY)
>>           (terminal "clears" -- Emacs (TTY) mo longer on scree, as
>>           expected, but mot returned to system shell prompt)
>>           (Emacs (GUI) frame starts showing 'get-device-terminql'
>>           error messages abd is umresponsive to any keyboard input)
>>
>>           This Emacs process is still avaiable to GDB, if useful.
>
> Looks like that error comes from a condition-case-unless-debug handler
> (in timer-event-handler).  Can you set `debug-on-error' from an
> emacsclient and get a backtrace?  Otherwise I think 'break Fsignal' in
> GDB should give some info as well (make sure that src/.gdbinit is
> sourced so you get a lisp backtrace in addition to the C one).

$  emacsclient --eval "(setq debug-on-error t)"
emacsclient: can't find socket; have you started the server?
To start the server in Emacs, type "M-x server-start".
*ERROR*: Invalid argument #<terminal 5> in ‘get-device-terminal’

(gdb) source ~/.gdbinit.emacs-25 
Warning: /home/liveuser/../lwlib: No such file or directory.
SIGINT is used by the debugger.
Are you sure you want to change it? (y or n) [answered Y; input not from terminal]
DISPLAY = :0
TERM = gnome-256color
Breakpoint 1 at 0x4f17d0: file ../../src/emacs.c, line 353.
Temporary breakpoint 2 at 0x50a490: init_sys_modes. (3 locations)
(gdb) break Fsignal
Breakpoint 3 at 0x566a50: file ../../src/eval.c, line 1470.
(gdb) c
Continuing.

Thread 1 "emacs" hit Breakpoint 3, Fsignal (error_symbol=XIL(0x4b00), 
    data=XIL(0x2451413)) at ../../src/eval.c:1470
1470	{
(gdb) list
1465	See Info anchor `(elisp)Definition of signal' for some details on how this
1466	error message is constructed.
1467	If the signal is handled, DATA is made available to the handler.
1468	See also the function `condition-case'.  */)
1469	  (Lisp_Object error_symbol, Lisp_Object data)
1470	{
1471	  /* When memory is full, ERROR-SYMBOL is nil,
1472	     and DATA is (REAL-ERROR-SYMBOL . REAL-DATA).
1473	     That is a special case--don't do this in other situations.  */
1474	  Lisp_Object conditions;
(gdb) 
(gdb) bt
#0  Fsignal (error_symbol=XIL(0x4b00), data=XIL(0x2451413))
    at ../../src/eval.c:1470
#1  0x00000000005668d5 in Ffuncall (nargs=3, args=args@entry=0x7ffe5e974a90)
    at ../../src/eval.c:2702
#2  0x000000000059f173 in exec_byte_code (bytestr=<optimized out>, 
    vector=<optimized out>, maxdepth=<optimized out>, 
    args_template=<optimized out>, nargs=nargs@entry=2, args=<optimized out>, 
    args@entry=0x878274 <pure+104404>) at ../../src/bytecode.c:880
#3  0x0000000000566416 in funcall_lambda (fun=XIL(0x7ffe5e974ce0), 
    nargs=nargs@entry=2, arg_vector=0x878274 <pure+104404>, 
    arg_vector@entry=0x7ffe5e974c48) at ../../src/eval.c:2863
#4  0x00000000005666db in Ffuncall (nargs=3, args=args@entry=0x7ffe5e974c40)
    at ../../src/eval.c:2760
#5  0x000000000059f173 in exec_byte_code (bytestr=<optimized out>, 
    vector=<optimized out>, maxdepth=<optimized out>, 
    args_template=<optimized out>, nargs=nargs@entry=1, args=<optimized out>, 
    args@entry=0x97c484 <pure+1169892>) at ../../src/bytecode.c:880
#6  0x0000000000566416 in funcall_lambda (fun=XIL(0x7ffe5e974ea0), 
    nargs=nargs@entry=1, arg_vector=0x97c484 <pure+1169892>, 
    arg_vector@entry=0x7ffe5e974e08) at ../../src/eval.c:2863
#7  0x00000000005666db in Ffuncall (nargs=2, args=args@entry=0x7ffe5e974e00)
    at ../../src/eval.c:2760
#8  0x000000000059f173 in exec_byte_code (bytestr=<optimized out>, 
---Type <return> to continue, or q <return> to quit---
    vector=<optimized out>, maxdepth=<optimized out>, 
    args_template=<optimized out>, nargs=nargs@entry=1, args=<optimized out>, 
    args@entry=0x97c5d4 <pure+1170228>) at ../../src/bytecode.c:880
#9  0x0000000000566416 in funcall_lambda (fun=XIL(0x7ffe5e975040), 
    nargs=nargs@entry=1, arg_vector=0x97c5d4 <pure+1170228>, 
    arg_vector@entry=0x7ffe5e974fc0) at ../../src/eval.c:2863
#10 0x00000000005666db in Ffuncall (nargs=2, args=args@entry=0x7ffe5e974fb8)
    at ../../src/eval.c:2760
#11 0x000000000059f173 in exec_byte_code (bytestr=<optimized out>, 
    vector=<optimized out>, maxdepth=<optimized out>, 
    args_template=args_template@entry=XIL(0), nargs=nargs@entry=0, 
    args=<optimized out>, args@entry=0x0) at ../../src/bytecode.c:880
#12 0x00000000005662ed in funcall_lambda (fun=XIL(0x8a6a3d), 
    nargs=nargs@entry=1, arg_vector=arg_vector@entry=0x7ffe5e9751c8)
    at ../../src/eval.c:2929
#13 0x00000000005666db in Ffuncall (nargs=nargs@entry=2, 
    args=args@entry=0x7ffe5e9751c0) at ../../src/eval.c:2760
#14 0x00000000005669da in call1 (fn=fn@entry=XIL(0x8a6a3d), 
    arg1=<optimized out>) at ../../src/eval.c:2558
#15 0x000000000056daaa in mapcar1 (leni=leni@entry=3, 
    vals=vals@entry=0x7ffe5e975250, fn=fn@entry=XIL(0x8a6a3d), 
    seq=seq@entry=XIL(0x2452103)) at ../../src/fns.c:2522
#16 0x000000000056e175 in Fmapcar (function=XIL(0x8a6a3d), 
---Type <return> to continue, or q <return> to quit---
    sequence=XIL(0x2452103)) at ../../src/fns.c:2587
#17 0x00000000005668d5 in Ffuncall (nargs=3, args=args@entry=0x7ffe5e9753a0)
    at ../../src/eval.c:2702
#18 0x000000000059f173 in exec_byte_code (bytestr=<optimized out>, 
    vector=<optimized out>, maxdepth=<optimized out>, 
    args_template=args_template@entry=XIL(0), nargs=nargs@entry=0, 
    args=<optimized out>, args@entry=0x0) at ../../src/bytecode.c:880
#19 0x00000000005662ed in funcall_lambda (fun=XIL(0x8a69bd), 
    nargs=nargs@entry=0, arg_vector=arg_vector@entry=0x7ffe5e9755b0)
    at ../../src/eval.c:2929
#20 0x00000000005666db in Ffuncall (nargs=1, args=args@entry=0x7ffe5e9755a8)
    at ../../src/eval.c:2760
#21 0x000000000059f173 in exec_byte_code (bytestr=<optimized out>, 
    vector=<optimized out>, maxdepth=<optimized out>, 
    args_template=args_template@entry=XIL(0), nargs=nargs@entry=0, 
    args=<optimized out>, args@entry=0x0) at ../../src/bytecode.c:880
#22 0x00000000005662ed in funcall_lambda (fun=fun@entry=XIL(0x8acec5), 
    nargs=nargs@entry=3, arg_vector=arg_vector@entry=0x7ffe5e975710)
    at ../../src/eval.c:2929
#23 0x0000000000565768 in apply_lambda (fun=XIL(0x8acec5), 
    args=<optimized out>, count=count@entry=26) at ../../src/eval.c:2800
#24 0x0000000000565aca in eval_sub (form=<optimized out>)
    at ../../src/eval.c:2247
---Type <return> to continue, or q <return> to quit---
#25 0x000000000056645d in Fprogn (body=XIL(0x25d0603)) at ../../src/eval.c:431
#26 funcall_lambda (fun=XIL(0x25d05c3), nargs=nargs@entry=0, 
    arg_vector=arg_vector@entry=0x7ffe5e9759e8) at ../../src/eval.c:2922
#27 0x00000000005666db in Ffuncall (nargs=1, args=0x7ffe5e9759e0)
    at ../../src/eval.c:2760
#28 0x0000000000566939 in funcall_nil (nargs=<optimized out>, 
    args=<optimized out>) at ../../src/eval.c:2338
#29 0x0000000000564a55 in run_hook_with_args (nargs=1, args=0x7ffe5e9759e0, 
    funcall=0x566930 <funcall_nil>) at ../../src/eval.c:2515
#30 0x0000000000564c33 in run_hook_with_args (funcall=<optimized out>, 
    args=<optimized out>, nargs=<optimized out>) at ../../src/eval.c:2361
#31 Frun_hook_with_args (args=0x7ffe5e9759e0, nargs=1) at ../../src/eval.c:2380
#32 run_hook (hook=<optimized out>) at ../../src/eval.c:2528
#33 Frun_hooks (nargs=1, args=0x7ffe5e975ac8) at ../../src/eval.c:2362
#34 0x00000000005667e9 in Ffuncall (nargs=nargs@entry=2, 
    args=args@entry=0x7ffe5e975ac0) at ../../src/eval.c:2679
#35 0x00000000005669da in call1 (fn=<optimized out>, 
    arg1=arg1@entry=XIL(0x2e80)) at ../../src/eval.c:2558
#36 0x000000000051107a in Fget_buffer_create (buffer_or_name=<optimized out>)
    at ../../src/buffer.c:591
#37 0x00000000005668e0 in Ffuncall (nargs=2, args=args@entry=0x7ffe5e975bc0)
    at ../../src/eval.c:2699
#38 0x000000000059f173 in exec_byte_code (bytestr=<optimized out>, 
---Type <return> to continue, or q <return> to quit---
    vector=<optimized out>, maxdepth=<optimized out>, 
    args_template=<optimized out>, nargs=nargs@entry=1, args=<optimized out>, 
    args@entry=0x8c314c <pure+411308>) at ../../src/bytecode.c:880
#39 0x0000000000566416 in funcall_lambda (fun=XIL(0x7ffe5e975e30), 
    nargs=nargs@entry=1, arg_vector=0x8c314c <pure+411308>, 
    arg_vector@entry=0x7ffe5e975d60) at ../../src/eval.c:2863
#40 0x00000000005666db in Ffuncall (nargs=2, args=args@entry=0x7ffe5e975d58)
    at ../../src/eval.c:2760
#41 0x000000000059f173 in exec_byte_code (bytestr=<optimized out>, 
    vector=<optimized out>, maxdepth=<optimized out>, 
    args_template=args_template@entry=XIL(0), nargs=nargs@entry=0, 
    args=<optimized out>, args@entry=0x0) at ../../src/bytecode.c:880
#42 0x00000000005662ed in funcall_lambda (fun=XIL(0x1357aa5), 
    nargs=nargs@entry=0, arg_vector=arg_vector@entry=0x7ffe5e975fc0)
    at ../../src/eval.c:2929
#43 0x00000000005666db in Ffuncall (nargs=1, args=args@entry=0x7ffe5e975fb8)
    at ../../src/eval.c:2760
#44 0x000000000059f173 in exec_byte_code (bytestr=<optimized out>, 
    vector=<optimized out>, maxdepth=<optimized out>, 
    args_template=args_template@entry=XIL(0), nargs=nargs@entry=0, 
    args=<optimized out>, args@entry=0x0) at ../../src/bytecode.c:880
#45 0x00000000005662ed in funcall_lambda (fun=XIL(0x1355a05), 
    nargs=nargs@entry=0, arg_vector=arg_vector@entry=0x7ffe5e9761e0)
---Type <return> to continue, or q <return> to quit---
    at ../../src/eval.c:2929
#46 0x00000000005666db in Ffuncall (nargs=1, args=args@entry=0x7ffe5e9761d8)
    at ../../src/eval.c:2760
#47 0x000000000059f173 in exec_byte_code (bytestr=<optimized out>, 
    vector=<optimized out>, maxdepth=<optimized out>, 
    args_template=args_template@entry=XIL(0), nargs=nargs@entry=0, 
    args=<optimized out>, args@entry=0x0) at ../../src/bytecode.c:880
#48 0x00000000005662ed in funcall_lambda (fun=XIL(0x135594d), 
    nargs=nargs@entry=0, arg_vector=arg_vector@entry=0x7ffe5e976508)
    at ../../src/eval.c:2929
#49 0x00000000005666db in Ffuncall (nargs=nargs@entry=1, 
    args=args@entry=0x7ffe5e976500) at ../../src/eval.c:2760
#50 0x0000000000567d0c in Fapply (nargs=2, args=0x7ffe5e976500)
    at ../../src/eval.c:2280
#51 0x00000000005667e9 in Ffuncall (nargs=3, args=args@entry=0x7ffe5e9764f8)
    at ../../src/eval.c:2679
#52 0x000000000059f173 in exec_byte_code (bytestr=<optimized out>, 
    vector=<optimized out>, maxdepth=<optimized out>, 
    args_template=args_template@entry=XIL(0), nargs=nargs@entry=0, 
    args=<optimized out>, args@entry=0x0) at ../../src/bytecode.c:880
#53 0x00000000005662ed in funcall_lambda (fun=XIL(0x9b3855), 
    nargs=nargs@entry=1, arg_vector=arg_vector@entry=0x7ffe5e976718)
    at ../../src/eval.c:2929
---Type <return> to continue, or q <return> to quit---
#54 0x00000000005666db in Ffuncall (nargs=nargs@entry=2, 
    args=args@entry=0x7ffe5e976710) at ../../src/eval.c:2760
#55 0x00000000005669da in call1 (fn=fn@entry=XIL(0xb340), 
    arg1=arg1@entry=XIL(0x1356ac5)) at ../../src/eval.c:2558
#56 0x00000000004f7714 in timer_check_2 (idle_timers=<optimized out>, 
    timers=<optimized out>) at ../../src/keyboard.c:4432
#57 timer_check () at ../../src/keyboard.c:4494
#58 0x00000000005a9851 in wait_reading_process_output (
    time_limit=time_limit@entry=0, nsecs=nsecs@entry=0, 
    read_kbd=read_kbd@entry=-1, do_display=true, 
    wait_for_cell=wait_for_cell@entry=XIL(0), wait_proc=wait_proc@entry=0x0, 
    just_wait_proc=0) at ../../src/process.c:4600
#59 0x00000000004fc80c in kbd_buffer_get_event (end_time=0x0, 
    used_mouse_menu=0x7ffe5e9773cb, kbp=<synthetic pointer>)
    at ../../src/keyboard.c:3824
#60 read_event_from_main_queue (used_mouse_menu=0x7ffe5e9773cb, 
    local_getcjmp=0x7ffe5e976fe0, end_time=0x0) at ../../src/keyboard.c:2153
#61 read_decoded_event_from_main_queue (used_mouse_menu=<optimized out>, 
    prev_event=<optimized out>, local_getcjmp=<optimized out>, 
    end_time=<optimized out>) at ../../src/keyboard.c:2216
#62 read_char (commandflag=commandflag@entry=1, map=map@entry=XIL(0x1f9cd43), 
    prev_event=XIL(0), used_mouse_menu=used_mouse_menu@entry=0x7ffe5e9773cb, 
    end_time=end_time@entry=0x0) at ../../src/keyboard.c:2804
---Type <return> to continue, or q <return> to quit---
#63 0x00000000004fe62d in read_key_sequence (
    keybuf=keybuf@entry=0x7ffe5e9774c0, prompt=prompt@entry=XIL(0), 
    dont_downcase_last=dont_downcase_last@entry=false, 
    can_return_switch_frame=can_return_switch_frame@entry=true, 
    fix_current_buffer=fix_current_buffer@entry=true, 
    prevent_redisplay=prevent_redisplay@entry=false, bufsize=30)
    at ../../src/keyboard.c:9068
#64 0x0000000000500264 in command_loop_1 () at ../../src/keyboard.c:1370
#65 0x0000000000565002 in internal_condition_case (
    bfun=bfun@entry=0x500040 <command_loop_1>, 
    handlers=handlers@entry=XIL(0x4b00), hfun=hfun@entry=0x4f68c0 <cmd_error>)
    at ../../src/eval.c:1315
#66 0x00000000004f1cf4 in command_loop_2 (ignore=ignore@entry=XIL(0))
    at ../../src/keyboard.c:1112
#67 0x0000000000564fa3 in internal_catch (tag=tag@entry=XIL(0xb580), 
    func=func@entry=0x4f1cd0 <command_loop_2>, arg=arg@entry=XIL(0))
    at ../../src/eval.c:1080
#68 0x00000000004f1cb0 in command_loop () at ../../src/keyboard.c:1091
#69 0x00000000004f64b7 in recursive_edit_1 () at ../../src/keyboard.c:697
#70 0x00000000004f6808 in Frecursive_edit () at ../../src/keyboard.c:768
#71 0x000000000041a032 in main (argc=2, argv=0x7ffe5e977848)
    at ../../src/emacs.c:1629

---Type <return> to continue, or q <return> to quit---
Lisp Backtrace:
"signal" (0x5e974a98)
"error" (0x5e974c48)
"get-device-terminal" (0x5e974e08)
"frames-on-display-list" (0x5e974fc0)
0x8a6a38 PVEC_COMPILED
"mapcar" (0x5e9753a8)
"internal--before-save-selected-window" (0x5e9755b0)
"walk-windows" (0x5e975710)
0x25d05c0 Lisp type 3
"run-hooks" (0x5e975ac8)
"get-buffer-create" (0x5e975bc8)
"generate-new-buffer" (0x5e975d60)
"battery-linux-sysfs" (0x5e975fc0)
"battery-update" (0x5e9761e0)
"battery-update-handler" (0x5e976508)
"apply" (0x5e976500)
"timer-event-handler" (0x5e976718)