binutils-gdb/gdb/tui
Tom de Vries deb1ba4e38 [gdb/tui] Fix TUI resizing for TERM=ansi
With TERM=ansi, when resizing a TUI window from LINES/COLUMNS 31/118
(maximized) to 20/78 (de-maximized), I get a garbled screen (that ^L doesn't
fix) and a message:
...
@@ resize done 0, size = 77x20
...
with the resulting width being 77 instead of the expected 78.

[ The discrepancy also manifests in CLI, filed as PR30346. ]

The discrepancy comes from tui_resize_all, where we ask readline for the
screen size:
...
   rl_get_screen_size (&screenheight, &screenwidth);
...

As it happens, when TERM is set to ansi, readline decides that the terminal
cannot auto-wrap lines, and reserves one column to deal with that, and as a
result reports back one less than the actual screen width:
...
$ echo $COLUMNS
78
$ TERM=xterm gdb -ex "show width" -ex q
Number of characters gdb thinks are in a line is 78.
$ TERM=ansi  gdb -ex "show width" -ex q
Number of characters gdb thinks are in a line is 77.
...

In tui_resize_all, we need the actual screen width, and using a screenwidth of
one less than the actual value garbles the screen.

This is currently not causing trouble in testing because we have a workaround
in place in proc Term::resize.  If we disable the workaround:
...
-       stty columns [expr {$_cols + 1}] < $::gdb_tty_name
+       stty columns $_cols < $::gdb_tty_name
...
and dump the screen we get the same type of screen garbling:
...
    0 +---------------------------------------+|
    1                                         ||
    2                                         ||
    3                                         ||
...

Another way to reproduce the problem is using command "maint info screen".
After starting gdb with TERM=ansi, entering TUI, and issuing the command, we
get:
...
Number of characters curses thinks are in a line is 78.
...
and after maximizing and demaximizing the window we get:
...
Number of characters curses thinks are in a line is 77.
...
If we use TERM=xterm, we do get the expected 78.

Fix this by:
- detecting when readline will report back less than the actual screen width,
- accordingly setting a new variable readline_hidden_cols,
- using readline_hidden_cols in tui_resize_all to fix the resize problem, and
- removing the workaround in Term::resize.

The test-case gdb.tui/empty.exp serves as regression test.

I've applied the same fix in tui_async_resize_screen, the new test-case
gdb.tui/resize-2.exp serves as a regression test for that change.  Without
that fix, we have:
...
FAIL: gdb.tui/resize-2.exp: again: gdb width 80
...

Tested on x86_64-linux.

PR tui/30337
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30337
2023-04-30 13:06:23 +02:00
..
ChangeLog-1998-2003
tui-command.c
tui-command.h
tui-data.c
tui-data.h
tui-disasm.c
tui-disasm.h
tui-file.c
tui-file.h
tui-hooks.c
tui-hooks.h
tui-interp.c Simplify interp::exec / interp_exec - let exceptions propagate 2023-02-08 17:28:42 +00:00
tui-io.c Forced quit cases handled by resetting sync_quit_force_run 2023-02-27 16:20:39 -07:00
tui-io.h
tui-layout.c gdb: Fix building with latest libc++ 2023-04-29 00:35:11 -07:00
tui-layout.h gdb/tui: improve errors from tui focus command 2023-01-27 16:20:10 +00:00
tui-location.c
tui-location.h
tui-out.c
tui-out.h
tui-regs.c Remove a use of pagination_enabled 2023-02-14 13:54:44 -07:00
tui-regs.h
tui-source.c [gdb/tui] Revert workaround in tui_source_window::show_line_number 2023-04-13 00:18:12 +02:00
tui-source.h
tui-stack.c [gdb/tui] Fix length of status line string 2023-04-26 18:15:56 +02:00
tui-stack.h
tui-win.c [gdb/tui] Fix TUI resizing for TERM=ansi 2023-04-30 13:06:23 +02:00
tui-win.h [gdb/tui] Add maint set/show tui-left-margin-verbose 2023-04-13 00:18:12 +02:00
tui-wingeneral.c
tui-wingeneral.h
tui-winsource.c gdb: Fix building with latest libc++ 2023-04-29 00:35:11 -07:00
tui-winsource.h [gdb/tui] Fix left margin in disassembly window 2023-04-13 00:18:12 +02:00
tui.c Forced quit cases handled by resetting sync_quit_force_run 2023-02-27 16:20:39 -07:00
tui.h gdb/tui: more debug output 2023-01-27 16:20:10 +00:00