Subject: Re: bug#18649: 25.0.50; Closing TTY menus on MS-Windows
From: Eli Zaretskii <[email-masked]>
To: [email-masked]
Cc: [email-masked]
Date: Wed, 08 Oct 2014 15:49:37 +0300
List-Id: <debbugs-submit.debbugs.gnu.org>

> Date: Wed, 08 Oct 2014 13:29:52 +0300
> From: Eli Zaretskii <[email-masked]>
> Cc: [email-masked]
> 
> > Date: Wed, 08 Oct 2014 11:32:31 +0200
> > From: martin rudalics <[email-masked]>
> > CC: [email-masked]
> > 
> >  > IOW, we throw to top level too early
> >  > or too radically.
> > 
> > Do you see any way to debug this?
> 
> If no other idea presents itself, the hard way: by stepping through
> the code in keyboard.c that processes keyboard input.

There _is_ a better way: set a breakpoint in process_quit_flag (which
is called as part of QUIT), and see who called it.  Using this method,
I was able to catch the villain in no time, see below.

> >  > Update: the problem is definitely caused by r117587; reverting it
> >  > fixes the problem.  I reviewed the diffs, more than once, and I cannot
> >  > see what could be the reason.  Martin, your help will be appreciated.
> > 
> > I'm just as lost as you are.  I tried to partially revert changes that
> > could have affected this on w32 but with no luck.
> 
> Sigh.  I guess that commit just exposed some other bug, then.

It wasn't an old bug, it was indeed caused by the pixel-wise changes.
Specifically, the fact that as part of the call to change_frame_size,
we can now call Lisp (in frame_windows_min_size).  The other part of
the puzzle is that w32_console_read_socket calls change_frame_size
unconditionally on every event it reads, because Windows doesn't tell
us about resizes of the console window.

So what happened was that we read the C-g key, called
kbd_buffer_store_event for it, which set Vquit_flag, and then we
called change_frame_size, which did QUIT when frame_windows_min_size
called Lisp.

I fixed that by passing a non-zero DELAY argument to
change_frame_size, so that it delays the actual resize to the next
opportunity, like the next redisplay cycle.

I'm closing this bug.

For the record, here's the backtrace I obtained from the breakpoint
set in process_quit_flag:

  #0  process_quit_flag () at eval.c:1440
  #1  0x0118e71f in Ffuncall (nargs=4, args=0x82e780) at eval.c:2659
  #2  0x0118e5bd in call3 (fn=22541890, arg1=22499637, arg2=22425250,
      arg3=22425250) at eval.c:2592
  #3  0x01010acd in frame_windows_min_size (frame=22499637,
      horizontal=22425250, pixelwise=22425250) at frame.c:333
  #4  0x01010cce in adjust_frame_size (f=0x1575130 <dumped_data+85776>,
      new_width=80, new_height=56, inhibit=5, pretend=false) at frame.c:409
  #5  0x0100e9a2 in change_frame_size_1 (f=0x1575130 <dumped_data+85776>,
      new_width=80, new_height=56, pretend=false, delay=false, safe=false,
      pixelwise=false) at dispnew.c:5531
  #6  0x0100ea00 in change_frame_size (f=0x1575130 <dumped_data+85776>,
      new_width=80, new_height=56, pretend=false, delay=false, safe=false,
      pixelwise=false) at dispnew.c:5562
  #7  0x0123c934 in maybe_generate_resize_event () at w32inevt.c:605
  #8  0x0123cc99 in w32_console_read_socket (
      terminal=0x18fd358 <dumped_data+3789112>, hold_quit=0x82e9ac)
      at w32inevt.c:795
  #9  0x0110a875 in gobble_input () at keyboard.c:6911
  #10 0x01104e33 in kbd_buffer_get_event (kbp=0x82eac4,
      used_mouse_menu=0x82ed93, end_time=0x0) at keyboard.c:3957
  #11 0x011011f4 in read_event_from_main_queue (end_time=0x0,
      local_getcjmp=0x82ebec, used_mouse_menu=0x82ed93) at keyboard.c:2254
  #12 0x01101430 in read_decoded_event_from_main_queue (end_time=0x0,
      local_getcjmp=0x82ebec, prev_event=22425218, used_mouse_menu=0x82ed93)
      at keyboard.c:2319
  #13 0x01102886 in read_char (commandflag=0, map=24485206,
      prev_event=22425218, used_mouse_menu=0x82ed93, end_time=0x0)
      at keyboard.c:2916
  #14 0x0110f4cb in read_key_sequence (keybuf=0x82eeb4, bufsize=30,
      prompt=19897305, dont_downcase_last=false, can_return_switch_frame=false,
      fix_current_buffer=false, prevent_redisplay=false) at keyboard.c:9171
  #15 0x01110bf6 in read_key_sequence_vs (prompt=19897305,
      continue_echo=22425218, dont_downcase_last=22425218,
      can_return_switch_frame=22425218, cmd_loop=22425218, allow_string=true)
      at keyboard.c:9865
  #16 0x01110cad in Fread_key_sequence (prompt=19897305,
      continue_echo=22425218, dont_downcase_last=22425218,
      can_return_switch_frame=22425218, cmd_loop=22425218) at keyboard.c:9938
  #17 0x0118eaf4 in Ffuncall (nargs=2, args=0x82f014) at eval.c:2739
  #18 0x011d05f9 in exec_byte_code (bytestr=19897113, vector=19897141,
      maxdepth=16, args_template=22425218, nargs=0, args=0x0) at bytecode.c:920
  #19 0x011cfa56 in Fbyte_code (bytestr=19897113, vector=19897141, maxdepth=16)
      at bytecode.c:486
  #20 0x0118d70c in eval_sub (form=19897102) at eval.c:2184
  #21 0x0118cf0e in Feval (form=19897102, lexical=22425218) at eval.c:1993
  #22 0x01186634 in Fcall_interactively (function=24528330,
      record_flag=22425218, keys=22450893) at callint.c:379
  #23 0x0118ea75 in Ffuncall (nargs=4, args=0x82f56c) at eval.c:2730
  #24 0x011d05f9 in exec_byte_code (bytestr=19853809, vector=19853829,
      maxdepth=52, args_template=4100, nargs=1, args=0x82f8a0) at bytecode.c:920
  #25 0x0118f24d in funcall_lambda (fun=19853789, nargs=1, arg_vector=0x82f89c)
      at eval.c:2890
  #26 0x0118ec5a in Ffuncall (nargs=2, args=0x82f898) at eval.c:2772
  #27 0x0118e55d in call1 (fn=22471274, arg1=24528330) at eval.c:2576
  #28 0x010ffab9 in command_loop_1 () at keyboard.c:1569
  #29 0x0118b976 in internal_condition_case (bfun=0x10ff458 <command_loop_1>,
      handlers=22478818, hfun=0x10fecbd <cmd_error>) at eval.c:1344
  #30 0x010ff110 in command_loop_2 (ignore=22425218) at keyboard.c:1197
  #31 0x0118af11 in internal_catch (tag=22476146,
      func=0x10ff0ec <command_loop_2>, arg=22425218) at eval.c:1105
  #32 0x010ff0c6 in command_loop () at keyboard.c:1176
  #33 0x010fe85a in recursive_edit_1 () at keyboard.c:786
  #34 0x010fea16 in Frecursive_edit () at keyboard.c:857
  #35 0x010fcafd in main (argc=3, argv=0xa42808) at emacs.c:1643

  Lisp Backtrace:
  "read-key-sequence" (0x82f018)
  "byte-code" (0x82f298)
  "call-interactively" (0x82f570)
  "command-execute" (0x82f89c)