Skip to content

Commit f8e5e23

Browse files
committed
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 <[email protected]> * tui/tui.c (tui_enable): Resize windows before anything might show a window.
1 parent 9f2e072 commit f8e5e23

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

gdb/ChangeLog

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2015-02-17 Pedro Alves <[email protected]>
2+
3+
* tui/tui.c (tui_enable): Resize windows before anything
4+
might show a window.
5+
16
2015-02-17 Max Ostapenko <[email protected]>
27

38
PR gdb/17984

gdb/tui/tui.c

+10-6
Original file line numberDiff line numberDiff line change
@@ -487,18 +487,22 @@ tui_enable (void)
487487
tui_setup_io (1);
488488

489489
tui_active = 1;
490-
if (deprecated_safe_get_selected_frame ())
491-
tui_show_frame_info (deprecated_safe_get_selected_frame ());
492490

493-
/* Restore TUI keymap. */
494-
tui_set_key_mode (tui_current_key_mode);
495-
496-
/* Resize and refresh the screen. */
491+
/* Resize windows before anything might display/refresh a
492+
window. */
497493
if (tui_win_resized ())
498494
{
499495
tui_resize_all ();
500496
tui_set_win_resized_to (FALSE);
501497
}
498+
499+
if (deprecated_safe_get_selected_frame ())
500+
tui_show_frame_info (deprecated_safe_get_selected_frame ());
501+
502+
/* Restore TUI keymap. */
503+
tui_set_key_mode (tui_current_key_mode);
504+
505+
/* Refresh the screen. */
502506
tui_refresh_all_win ();
503507

504508
/* Update gdb's knowledge of its terminal. */

0 commit comments

Comments
 (0)