public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug tui/30337] New: [gdb/tui] TUI in ansi terminal has one off width problem
@ 2023-04-12 11:15 vries at gcc dot gnu.org
  2023-04-12 11:15 ` [Bug tui/30337] [gdb/tui] TUI in ansi terminal has off-by-one " vries at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: vries at gcc dot gnu.org @ 2023-04-12 11:15 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=30337

            Bug ID: 30337
           Summary: [gdb/tui] TUI in ansi terminal has one off width
                    problem
           Product: gdb
           Version: HEAD
            Status: NEW
          Severity: normal
          Priority: P2
         Component: tui
          Assignee: unassigned at sourceware dot org
          Reporter: vries at gcc dot gnu.org
  Target Milestone: ---

I. Terminal used

I open a terminal, and can easily switch between maximized:
...
$ echo $COLUMNS 
118
$ echo $LINES
31
...
and non-maximized:
..
$ echo $COLUMNS 
78
$ echo $LINES
20
...


II. TERM=xterm

Now let's start gdb in TUI mode in maximized mode:
...
$ gdb \
    -ex "set tui border-kind ascii" \
    -ex "maint set tui-resize-message on" \
    -ex "tui enable"
...

That looks as expected (not posting, rather big).

Now let's resize to non-maximized:
...
+----------------------------------------------------------------------------+
|                                                                            |
|                                                                            |
|                                                                            |
|                                                                            |
|                                                                            |
|              [ No Source Available ]                                       |
|                                                                            |
|                                                                            |
|                                                                            |
|                                                                            |
+----------------------------------------------------------------------------+
None No process In:                                              L??   PC: ?? 
@@ resize done 0, size = 78x20
(gdb) 
...

OK, that looks good as well.


III. TERM=ansi

Now, let's repeat this, but with TERM set to ansi, as we do in the testsuite.

That looks ok, with the exception of "gdb)" appearing at the start of the line,
with the missing "(" glued to the end of the previous line.

Now, let's resize again to non-maximized:
...
+---------------------------------------------------------------------------||





              [ No Source Available ]                                      
|+---------------------------------------------------------------------------+No
ne No process In:                                             L??   PC: ?? |
|
|
|
|
@@ resize done 0, size = 77x20
(gdb) -----------------------------------------------------------------------




...

Well, the result looks a bit garbled, and the resize reports 77 instead of 78.

I tracked this down to readline underreporting the screen size, due to
_rl_term_autowrap == 0.

With this demonstrator patch:
...
diff --git a/gdb/tui/tui-win.c b/gdb/tui/tui-win.c
index 008189eb99b..995355e9ecc 100644
--- a/gdb/tui/tui-win.c
+++ b/gdb/tui/tui-win.c
@@ -528,6 +528,8 @@ tui_resize_all (void)
   int screenheight, screenwidth;

   rl_get_screen_size (&screenheight, &screenwidth);
+  screenwidth++;
+
   width_diff = screenwidth - tui_term_width ();
   height_diff = screenheight - tui_term_height ();
   if (height_diff || width_diff)
...
we get instead the expected and non-garbled:
...
+----------------------------------------------------------------------------+
|                                                                            |
|                                                                            |
|                                                                            |
|                                                                            |
|                                                                            |
|              [ No Source Available ]                                       |
|                                                                            |
|                                                                            |
|                                                                            |
|                                                                            |
+----------------------------------------------------------------------------+
None No process In:                                           L??   PC: ?? @@
resize done 0, size = 78x20
(gdb) 
...

The problem seems to be related to this comment in Term::resize:
...
        # Somehow the number of columns transmitted to gdb is one less          
        # than what we request from expect.  We hide this weird                 
        # details from the caller.                                              
        _do_resize $_rows $cols
        stty columns [expr {$_cols + 1}] < $::gdb_tty_name
...
and indeed, after dropping the +1 in {$_cols + 1} the test passes (and ...
without timeouts).

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug tui/30337] [gdb/tui] TUI in ansi terminal has off-by-one width problem
  2023-04-12 11:15 [Bug tui/30337] New: [gdb/tui] TUI in ansi terminal has one off width problem vries at gcc dot gnu.org
@ 2023-04-12 11:15 ` vries at gcc dot gnu.org
  2023-04-12 11:48 ` vries at gcc dot gnu.org
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: vries at gcc dot gnu.org @ 2023-04-12 11:15 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=30337

Tom de Vries <vries at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|[gdb/tui] TUI in ansi       |[gdb/tui] TUI in ansi
                   |terminal has one off width  |terminal has off-by-one
                   |problem                     |width problem

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug tui/30337] [gdb/tui] TUI in ansi terminal has off-by-one width problem
  2023-04-12 11:15 [Bug tui/30337] New: [gdb/tui] TUI in ansi terminal has one off width problem vries at gcc dot gnu.org
  2023-04-12 11:15 ` [Bug tui/30337] [gdb/tui] TUI in ansi terminal has off-by-one " vries at gcc dot gnu.org
@ 2023-04-12 11:48 ` vries at gcc dot gnu.org
  2023-04-12 12:45 ` vries at gcc dot gnu.org
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: vries at gcc dot gnu.org @ 2023-04-12 11:48 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=30337

--- Comment #1 from Tom de Vries <vries at gcc dot gnu.org> ---
(In reply to Tom de Vries from comment #0)
> The problem seems to be related to this comment in Term::resize:
> ...
>         # Somehow the number of columns transmitted to gdb is one less      
> 
>         # than what we request from expect.  We hide this weird             
> 
>         # details from the caller.                                          
> 
>         _do_resize $_rows $cols
>         stty columns [expr {$_cols + 1}] < $::gdb_tty_name
> ...
> and indeed, after dropping the +1 in {$_cols + 1} the test passes (and ...
> without timeouts).

With "the test" I meant gdb.tui/empty.exp.

Without the patch, the test-case times out here:
...
        _do_resize $rows $_cols
        stty rows $_rows < $::gdb_tty_name
        # Due to the strange column resizing behavior, and because we           
        # don't care about this intermediate resize, we don't check             
        # the size here.                                                        
        wait_for "@@ resize done $_resize_count"
        incr _resize_count
...
because due to the garbling, the "@@ resize done $_resize_count" line is spread
over two lines.

In other words, the problem filed in this PR is not sufficiently worked around
in Term::resize.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug tui/30337] [gdb/tui] TUI in ansi terminal has off-by-one width problem
  2023-04-12 11:15 [Bug tui/30337] New: [gdb/tui] TUI in ansi terminal has one off width problem vries at gcc dot gnu.org
  2023-04-12 11:15 ` [Bug tui/30337] [gdb/tui] TUI in ansi terminal has off-by-one " vries at gcc dot gnu.org
  2023-04-12 11:48 ` vries at gcc dot gnu.org
@ 2023-04-12 12:45 ` vries at gcc dot gnu.org
  2023-04-12 13:56 ` vries at gcc dot gnu.org
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: vries at gcc dot gnu.org @ 2023-04-12 12:45 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=30337

--- Comment #2 from Tom de Vries <vries at gcc dot gnu.org> ---
Created attachment 14813
  --> https://sourceware.org/bugzilla/attachment.cgi?id=14813&action=edit
Tentative patch

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug tui/30337] [gdb/tui] TUI in ansi terminal has off-by-one width problem
  2023-04-12 11:15 [Bug tui/30337] New: [gdb/tui] TUI in ansi terminal has one off width problem vries at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2023-04-12 12:45 ` vries at gcc dot gnu.org
@ 2023-04-12 13:56 ` vries at gcc dot gnu.org
  2023-04-13 12:43 ` vries at gcc dot gnu.org
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: vries at gcc dot gnu.org @ 2023-04-12 13:56 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=30337

--- Comment #3 from Tom de Vries <vries at gcc dot gnu.org> ---
The problem manifest outside of TUI as well.

Say we have a terminal with:
...
$ echo $COLUMNS
40
...

For contrast, lets start with the terminal in xterm mode, and type 'a' for a
while:
...
$ TERM=xterm gdb -q
         1         2         3         4
1234567890123456789012345678901234567890
(gdb) aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aa
...
All 40 positions in the line are used, before we wrap to the next line.

Now we start gdb with the terminal in ansi mode:
...
$ TERM=ansi gdb -q
         1         2         3         4
1234567890123456789012345678901234567890
(gdb) aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aa
...

The line wraps after 38 chars.

Based on the readline behaviour of hiding one char to deal with the lack of
autowrap, we'd expect wrapping after 39 chars.

The problem is that we start out with COLUMNS=40, then ask readline how wide
the screen is, which replies 39.  Then we use the 39 to set the screensize
using readline, which results in an effective width of 38.

With the patch, we have instead:
...
$ TERM=ansi gdb -q
         1         2         3         4
1234567890123456789012345678901234567890
(gdb) aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aa
...
wrapping after 39 chars, as expected.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug tui/30337] [gdb/tui] TUI in ansi terminal has off-by-one width problem
  2023-04-12 11:15 [Bug tui/30337] New: [gdb/tui] TUI in ansi terminal has one off width problem vries at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2023-04-12 13:56 ` vries at gcc dot gnu.org
@ 2023-04-13 12:43 ` vries at gcc dot gnu.org
  2023-04-13 14:11 ` vries at gcc dot gnu.org
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: vries at gcc dot gnu.org @ 2023-04-13 12:43 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=30337

--- Comment #4 from Tom de Vries <vries at gcc dot gnu.org> ---
(In reply to Tom de Vries from comment #3)
> The problem manifest outside of TUI as well.

I've filed this as PR30346 - "[gdb/cli] CLI in ansi terminal has off-by-one
width problem".

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug tui/30337] [gdb/tui] TUI in ansi terminal has off-by-one width problem
  2023-04-12 11:15 [Bug tui/30337] New: [gdb/tui] TUI in ansi terminal has one off width problem vries at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2023-04-13 12:43 ` vries at gcc dot gnu.org
@ 2023-04-13 14:11 ` vries at gcc dot gnu.org
  2023-04-30 11:06 ` cvs-commit at gcc dot gnu.org
  2023-04-30 11:10 ` vries at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: vries at gcc dot gnu.org @ 2023-04-13 14:11 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=30337

--- Comment #5 from Tom de Vries <vries at gcc dot gnu.org> ---
Posted patch:
https://sourceware.org/pipermail/gdb-patches/2023-April/198855.html

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug tui/30337] [gdb/tui] TUI in ansi terminal has off-by-one width problem
  2023-04-12 11:15 [Bug tui/30337] New: [gdb/tui] TUI in ansi terminal has one off width problem vries at gcc dot gnu.org
                   ` (5 preceding siblings ...)
  2023-04-13 14:11 ` vries at gcc dot gnu.org
@ 2023-04-30 11:06 ` cvs-commit at gcc dot gnu.org
  2023-04-30 11:10 ` vries at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-04-30 11:06 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=30337

--- Comment #6 from cvs-commit at gcc dot gnu.org <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Tom de Vries <vries@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=deb1ba4e38bf1427d4297b1e9b3e5e73cbc9e456

commit deb1ba4e38bf1427d4297b1e9b3e5e73cbc9e456
Author: Tom de Vries <tdevries@suse.de>
Date:   Sun Apr 30 13:06:23 2023 +0200

    [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

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug tui/30337] [gdb/tui] TUI in ansi terminal has off-by-one width problem
  2023-04-12 11:15 [Bug tui/30337] New: [gdb/tui] TUI in ansi terminal has one off width problem vries at gcc dot gnu.org
                   ` (6 preceding siblings ...)
  2023-04-30 11:06 ` cvs-commit at gcc dot gnu.org
@ 2023-04-30 11:10 ` vries at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: vries at gcc dot gnu.org @ 2023-04-30 11:10 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=30337

Tom de Vries <vries at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|NEW                         |RESOLVED
   Target Milestone|---                         |14.1

--- Comment #7 from Tom de Vries <vries at gcc dot gnu.org> ---
Fixed.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2023-04-30 11:10 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-12 11:15 [Bug tui/30337] New: [gdb/tui] TUI in ansi terminal has one off width problem vries at gcc dot gnu.org
2023-04-12 11:15 ` [Bug tui/30337] [gdb/tui] TUI in ansi terminal has off-by-one " vries at gcc dot gnu.org
2023-04-12 11:48 ` vries at gcc dot gnu.org
2023-04-12 12:45 ` vries at gcc dot gnu.org
2023-04-12 13:56 ` vries at gcc dot gnu.org
2023-04-13 12:43 ` vries at gcc dot gnu.org
2023-04-13 14:11 ` vries at gcc dot gnu.org
2023-04-30 11:06 ` cvs-commit at gcc dot gnu.org
2023-04-30 11:10 ` vries at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).