binutils-gdb/gdb/tui
Pedro Alves f8e5e23e3d TUI: resize windows to new terminal size before displaying them
If the user:

   #1 - disables the TUI
   #2 - resizes the terminal
   #3 - and then re-enables the TUI

the next wgetch() returns KEY_RESIZE.  This indicates to the ncurses
client that ncurses detected that the terminal has been resized.  We
don't handle KEY_RESIZE anywhere, so it gets passed on to readline
which interprets it as a multibyte character, and then the end result
is that the first key press after enabling the TUI is misinterpreted.

We shouldn't really need to handle KEY_RESIZE (and not all ncurses
implementations have that).  We have our own SIGWINCH handler, and,
when we re-enable the TUI, we explicitly detect terminal resizes and
resize all windows.  The reason ncurses currently does detects a
resize is that something within tui_enable forces a refresh/display of
some window before we get to do the actual resizing.  Setting a break
on ncurses' 'resizeterm' function helps find the culprit(s):

 (top-gdb) bt
 #0  resizeterm (ToLines=28, ToCols=114) at ../../ncurses/base/resizeterm.c:462
 #1  0x0000003b42812f3f in _nc_update_screensize (sp=0x2674730) at ../../ncurses/tinfo/lib_setup.c:443
 #2  0x0000003b0821cbe0 in doupdate () at ../../ncurses/tty/tty_update.c:726
 #3  0x0000003b08215539 in wrefresh (win=0x2a7bc00) at ../../ncurses/base/lib_refresh.c:65
 #4  0x00000000005257cb in tui_refresh_win (win_info=0xd73d60 <_locator>) at /home/pedro/gdb/mygit/src/gdb/tui/tui-wingeneral.c:60
 #5  0x000000000052265b in tui_show_locator_content () at /home/pedro/gdb/mygit/src/gdb/tui/tui-stack.c:269
 #6  0x00000000005273a6 in tui_set_key_mode (mode=TUI_COMMAND_MODE) at /home/pedro/gdb/mygit/src/gdb/tui/tui.c:321
 #7  0x00000000005278c7 in tui_enable () at /home/pedro/gdb/mygit/src/gdb/tui/tui.c:494
 #8  0x0000000000527011 in tui_rl_switch_mode (notused1=1, notused2=1) at /home/pedro/gdb/mygit/src/gdb/tui/tui.c:108

That is, tui_enable calls tui_set_key_mode before we've resized all
windows, and that refreshes a window as side effect.

And if we're already debugging something (there's a frame), then we'll
instead show a window from within tui_show_frame_info:

 (top-gdb) bt
 #0  resizeterm (ToLines=28, ToCols=114) at ../../ncurses/base/resizeterm.c:462
 #1  0x0000003b42812f3f in _nc_update_screensize (sp=0x202e6c0) at ../../ncurses/tinfo/lib_setup.c:443
 #2  0x0000003b0821cbe0 in doupdate () at ../../ncurses/tty/tty_update.c:726
 #3  0x0000003b08215539 in wrefresh (win=0x2042890) at ../../ncurses/base/lib_refresh.c:65
 #4  0x00000000005257cb in tui_refresh_win (win_info=0xd73d60 <_locator>) at /home/pedro/gdb/mygit/src/gdb/tui/tui-wingeneral.c:60
 #5  0x000000000052265b in tui_show_locator_content () at /home/pedro/gdb/mygit/src/gdb/tui/tui-stack.c:269
 #6  0x0000000000522931 in tui_show_frame_info (fi=0x16b9cc0) at /home/pedro/gdb/mygit/src/gdb/tui/tui-stack.c:364
 #7  0x00000000005278ba in tui_enable () at /home/pedro/gdb/mygit/src/gdb/tui/tui.c:491
 #8  0x0000000000527011 in tui_rl_switch_mode (notused1=1, notused2=1) at /home/pedro/gdb/mygit/src/gdb/tui/tui.c:108

The fix is to resize windows earlier.

gdb/ChangeLog:
2015-02-17  Pedro Alves  <palves@redhat.com>

	* tui/tui.c (tui_enable): Resize windows before anything
	might show a window.
2015-02-17 10:05:52 +00:00
..
ChangeLog-1998-2003
tui-command.c Speed up GDB's TUI output 2015-02-04 12:27:28 +01:00
tui-command.h Speed up GDB's TUI output 2015-02-04 12:27:28 +01:00
tui-data.c
tui-data.h Leave more space in TUI mode for thread ID. 2015-01-16 13:24:20 +02:00
tui-disasm.c
tui-disasm.h
tui-file.c Speed up GDB's TUI output 2015-02-04 12:27:28 +01:00
tui-file.h
tui-hooks.c
tui-hooks.h
tui-interp.c
tui-io.c Fix a pair of screen-resizing issues in TUI 2015-02-10 19:06:49 -05:00
tui-io.h Make sure TABs are expanded in TUI windows on MS-Windows. 2015-01-31 10:47:14 +02:00
tui-layout.c
tui-layout.h
tui-out.c
tui-regs.c Make sure TABs are expanded in TUI windows on MS-Windows. 2015-01-31 10:47:14 +02:00
tui-regs.h
tui-source.c
tui-source.h
tui-stack.c
tui-stack.h
tui-win.c Fix an erroneous commentary. 2015-01-16 18:32:42 +02:00
tui-win.h Really add a prototype for tui_rehighlight_all. 2015-01-16 19:58:04 +02:00
tui-windata.c
tui-windata.h
tui-wingeneral.c
tui-wingeneral.h
tui-winsource.c
tui-winsource.h
tui.c TUI: resize windows to new terminal size before displaying them 2015-02-17 10:05:52 +00:00
tui.h