public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom de Vries <tdevries@suse.de>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: Re: [PATCH 8/8] [gdb/tui] Fix TUI for TERM=ansi
Date: Tue, 18 Apr 2023 08:10:14 +0200	[thread overview]
Message-ID: <cc331915-bb8f-d8d2-f041-987219eaed18@suse.de> (raw)
In-Reply-To: <af0da14f-d73e-33fe-cd3a-477117409e1e@suse.de>

On 4/14/23 13:02, Tom de Vries via Gdb-patches wrote:
> On 4/13/23 16:17, Tom de Vries via Gdb-patches wrote:
>> On 4/13/23 16:08, Tom de Vries via Gdb-patches wrote:
>>> @@ -1144,6 +1148,11 @@ init_page_info (void)
>>>         /* Get the screen size from Readline.  */
>>>         rl_get_screen_size (&rows, &cols);
>>> +      if (gdb_stdout->isatty ()) {
>>> +    readline_hidden_cols = COLS - cols;
>>> +    gdb_assert (readline_hidden_cols >= 0);
>>> +    gdb_assert (readline_hidden_cols <= 1);
>>> +      }
>>>         lines_per_page = rows;
>>>         chars_per_line = cols;
>>
>> Reading this over once more, I noticed this is missing a fix for an 
>> assertion failure we run into when doing:
>> ...
>> $ TERM=blabla gdb
>> ...
>>
>> So, this bit is missing:
>> ...
>> -      if (gdb_stdout->isatty ()) {
>> +      if (gdb_stdout->isatty () && COLS != 0) {
>> ...
>>
> 
> I also ran into trouble with this version.  It's not a good idea to use 
> COLS, because it's just a copy of the env variable COLUMNS at the time 
> of curses startup.  So, I can trigger one of the asserts by doing:
> ...
> $ COLUMNS=<some-n> gdb
> ...
> 
> Here's an updated version, using the COLUMNS value as written by 
> readline instead.


> @@ -1144,6 +1148,24 @@ init_page_info (void)
>  
>        /* Get the screen size from Readline.  */
>        rl_get_screen_size (&rows, &cols);
> +
> +      /* Readline:
> +	 - ignores the COLUMNS variable when detecting screen width
> +	   (because rl_prefer_env_winsize defaults to 0)
> +	 - puts the detected screen width in the COLUMNS variable
> +	   (because rl_change_environment defaults to 1)
> +	 - may report one less than the detected screen width in
> +	   rl_get_screen_size (when _rl_term_autowrap == 0).
> +	 Set readline_hidden_cols by comparing COLUMNS to cols as returned by
> +	 rl_get_screen_size.  */
> +      char *columns_env = getenv ("COLUMNS");
> +      gdb_assert (columns_env != nullptr);
> +      int columns_env_val = atoi (columns_env);
> +      gdb_assert (columns_env_val != 0);
> +      readline_hidden_cols = columns_env_val - cols;
> +      gdb_assert (readline_hidden_cols >= 0);
> +      gdb_assert (readline_hidden_cols <= 1);
> +
>        lines_per_page = rows;
>        chars_per_line = cols;
>  

Hmm, it seems there is precedent for using private functions and 
variables of readline, the ones advertised as "functions and variables 
global to the readline library, but not intended for use by applications":
...
$ find gdb* -type f | grep -v ChangeLog | xargs grep -i 
"extern.*[^a-zA-Z]_rl_"
gdb/tui/tui-io.c:  extern int _rl_echoing_p;
gdb/completer.c:  extern int _rl_complete_mark_directories;
gdb/completer.c:extern int _rl_completion_prefix_display_length;
gdb/completer.c:extern int _rl_print_completions_horizontally;
gdb/completer.c:EXTERN_C int _rl_qsort_string_compare (const void *, 
const void *);
gdb/cli-out.c:EXTERN_C void _rl_erase_entire_line (void);
...

So, this patch could be simplified by just using _rl_term_autowrap.

Thanks,
- Tom

  reply	other threads:[~2023-04-18  6:10 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-13 14:08 [PATCH 0/8] [gdb/testsuite] Fix timeouts in TUI tests Tom de Vries
2023-04-13 14:08 ` [PATCH 1/8] [gdb/testsuite] Add warning for timeout in accept_gdb_output Tom de Vries
2023-04-13 14:08 ` [PATCH 2/8] [gdb/testsuite] Add debug prints in Term::wait_for Tom de Vries
2023-04-13 14:08 ` [PATCH 3/8] [gdb/testsuite] Fix timeout in gdb.tui/corefile-run.exp Tom de Vries
2023-04-13 14:08 ` [PATCH 4/8] [gdb/testsuite] Fix timeout in gdb.tui/main.exp Tom de Vries
2023-04-13 14:08 ` [PATCH 5/8] [gdb/testsuite] Fix timeout in gdb.tui/new-layout.exp Tom de Vries
2023-04-13 14:08 ` [PATCH 6/8] [gdb/testsuite] Fix timeout in gdb.tui/completion.exp Tom de Vries
2023-04-13 14:08 ` [PATCH 7/8] [gdb/testsuite] Fix timeout in gdb.tui/empty.exp Tom de Vries
2023-04-13 14:08 ` [PATCH 8/8] [gdb/tui] Fix TUI for TERM=ansi Tom de Vries
2023-04-13 14:17   ` Tom de Vries
2023-04-14 11:02     ` Tom de Vries
2023-04-18  6:10       ` Tom de Vries [this message]
2023-04-25  7:09         ` Tom de Vries
2023-04-30 11:08           ` Tom de Vries
2023-04-25  6:35 ` [PATCH 0/8] [gdb/testsuite] Fix timeouts in TUI tests Tom de Vries

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=cc331915-bb8f-d8d2-f041-987219eaed18@suse.de \
    --to=tdevries@suse.de \
    --cc=gdb-patches@sourceware.org \
    --cc=tom@tromey.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).