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

From: Live System User <[email-masked]>
Date: Thu, 04 Jan 2018 09:37:31 -0500

Noam Postavsky <[email-masked]> writes:

> Live System User <[email-masked]> writes:
>
>> (gdb) define print_terminal_list
>> Type commands for definition of "print_terminal_list".
>> End with a line saying just "end".
>>>set $t = terminal_list
>>>while $t
>>  >print *$t
>>  >set $t = $t->next_terminal
>>  >end
>>>end
>> (gdb) print_terminal_list
>> $1 = {
>>   header = {
>>     size = 4611686018561773572
>>   }, 
>>   param_alist = XIL(0x2bfe553), 
>>   charset_list = XIL(0x102ec33), 
>>   Vselection_alist = XIL(0), 
>>   glyph_code_table = XIL(0), 
>>   next_terminal = 0x363e3d8, 
>>   id = 5, 
>>   reference_count = 0, 
>>   type = output_termcap, 
>>   name = 0x0, 
>
> As far as I can tell, the only place that sets a terminals 'name' field
> to NULL is in delete_terminal:
>
>     delete_terminal (struct terminal *terminal)
>     {
>       ...
>       terminal->name = NULL;
>
>       [...]
>       *tp = terminal->next_terminal;
>       ...
>
> Something must have happened in the [...] to prevent the terminal from
> being removed from the terminal list.  There is a lot code in that
> [...], with a lot of conditional, recursive calls so it's hard to say
> what could be the problem.  One thing I see, is that it calls
> Fframe_parameter which uses Fassq which checks for quit signals.  Not
> sure how plausible it is that you could have managed to quit just at the
> right time though.

  Here's a new occurrance (see below):

  One thing I noticed is that when it happen this time when doing a
  "emacsclient -c" "is that a blank GUI frame quickly flashed on
  the screen and disappeated before printing the error:

*ERROR*: Invalid argument #<terminal 10> in ‘get-device-terminal’

  When I invoke "emacsclient -t" that error message does NOT
  appear -- Emacs still just doesn't do anything (the emacsclient
  command executed (?) and returned to the system prompt).

  As you noticed that when it's in this state, the "name" field
  appears invalid and its "reference count" is 0 (is it because
  it's deleted/dead/invalid?):

  id = 10, 
  reference_count = 0, 
  type = output_termcap, 
  name = 0x0, 

  Whereas in a working instance it looks like this:

  id = 2, 
  reference_count = 1, 
  type = output_termcap, 
  name = 0x33d5bc0 "/dev/pts/23", 

  Thanks.

(gdb) print_terminal_list
$1 = {
  header = {
    size = 4611686018561773572
  }, 
  param_alist = XIL(0x8793ef3), 
  charset_list = XIL(0x102ec33), 
  Vselection_alist = XIL(0), 
  glyph_code_table = XIL(0), 
  next_terminal = 0xc2b460, 
  id = 10, 
  reference_count = 0, 
  type = output_termcap, 
  name = 0x0, 
  kboard = 0x54ade00, 
  image_cache = 0x0, 
  display_info = {
    tty = 0x9d4e190, 
    x = 0x9d4e190, 
    w32 = 0x9d4e190, 
    ns = 0x9d4e190
  }, 
  terminal_coding = 0x802de00, 
  keyboard_coding = 0x8e3e1b0, 
---Type <return> to continue, or q <return> to quit---
  rif = 0x0, 
  cursor_to_hook = 0x4b3aa0 <tty_cursor_to>, 
  raw_cursor_to_hook = 0x4b39f0 <tty_raw_cursor_to>, 
  clear_to_end_hook = 0x4b1160 <tty_clear_to_end>, 
  clear_frame_hook = 0x4b1ce0 <tty_clear_frame>, 
  clear_end_of_line_hook = 0x4b38b0 <tty_clear_end_of_line>, 
  ins_del_lines_hook = 0x4b0e50 <tty_ins_del_lines>, 
  insert_glyphs_hook = 0x4b4820 <tty_insert_glyphs>, 
  write_glyphs_hook = 0x4b4500 <tty_write_glyphs>, 
  delete_glyphs_hook = 0x4b3720 <tty_delete_glyphs>, 
  ring_bell_hook = 0x4b0bb0 <tty_ring_bell>, 
  toggle_invisible_pointer_hook = 0x0, 
  reset_terminal_modes_hook = 0x4b3600 <tty_reset_terminal_modes>, 
  set_terminal_modes_hook = 0x4b0d00 <tty_set_terminal_modes>, 
  update_begin_hook = 0x0, 
  update_end_hook = 0x4b35a0 <tty_update_end>, 
  set_terminal_window_hook = 0x4b0790 <tty_set_terminal_window>, 
  mouse_position_hook = 0x0, 
  frame_rehighlight_hook = 0x0, 
  frame_raise_lower_hook = 0x0, 
  fullscreen_hook = 0x0, 
  menu_show_hook = 0x4b2ab0 <tty_menu_show>, 
  popup_dialog_hook = 0x0, 
---Type <return> to continue, or q <return> to quit---
  set_vertical_scroll_bar_hook = 0x0, 
  set_horizontal_scroll_bar_hook = 0x0, 
  condemn_scroll_bars_hook = 0x0, 
  redeem_scroll_bar_hook = 0x0, 
  judge_scroll_bars_hook = 0x0, 
  read_socket_hook = 0x4f8cf0 <tty_read_avail_input>, 
  frame_up_to_date_hook = 0x0, 
  delete_frame_hook = 0x4b0130 <tty_free_frame_resources>, 
  delete_terminal_hook = 0x4aff70 <delete_tty>
}
$2 = {
  header = {
    size = 4611686018561773572
  }, 
  param_alist = XIL(0x13a3b23), 
  charset_list = XIL(0x102ec33), 
  Vselection_alist = XIL(0), 
  glyph_code_table = XIL(0), 
  next_terminal = 0x0, 
  id = 0, 
  reference_count = 1, 
  type = output_initial, 
  name = 0xbf45e0 "initial_terminal", 
---Type <return> to continue, or q <return> to quit---
  kboard = 0xc26e30, 
  image_cache = 0x0, 
  display_info = {
    tty = 0x0, 
    x = 0x0, 
    w32 = 0x0, 
    ns = 0x0
  }, 
  terminal_coding = 0xc2dbf0, 
  keyboard_coding = 0xc2d980, 
  rif = 0x0, 
  cursor_to_hook = 0x0, 
  raw_cursor_to_hook = 0x0, 
  clear_to_end_hook = 0x0, 
  clear_frame_hook = 0x0, 
  clear_end_of_line_hook = 0x0, 
  ins_del_lines_hook = 0x0, 
  insert_glyphs_hook = 0x0, 
  write_glyphs_hook = 0x0, 
  delete_glyphs_hook = 0x0, 
  ring_bell_hook = 0x0, 
  toggle_invisible_pointer_hook = 0x0, 
  reset_terminal_modes_hook = 0x0, 
---Type <return> to continue, or q <return> to quit---
  set_terminal_modes_hook = 0x0, 
  update_begin_hook = 0x0, 
  update_end_hook = 0x0, 
  set_terminal_window_hook = 0x0, 
  mouse_position_hook = 0x0, 
  frame_rehighlight_hook = 0x0, 
  frame_raise_lower_hook = 0x0, 
  fullscreen_hook = 0x0, 
  menu_show_hook = 0x0, 
  popup_dialog_hook = 0x0, 
  set_vertical_scroll_bar_hook = 0x0, 
  set_horizontal_scroll_bar_hook = 0x0, 
  condemn_scroll_bars_hook = 0x0, 
  redeem_scroll_bar_hook = 0x0, 
  judge_scroll_bars_hook = 0x0, 
  read_socket_hook = 0x0, 
  frame_up_to_date_hook = 0x0, 
  delete_frame_hook = 0x4b6ea0 <initial_free_frame_resources>, 
  delete_terminal_hook = 0x4b7690 <delete_initial_terminal>
}
(gdb)