[3/3,gdb/tui] Refresh on target_terminal_state::is_ours

Message ID 20230530105324.23089-4-tdevries@suse.de
State New
Headers
Series Improve handling of inferior output |

Commit Message

Tom de Vries May 30, 2023, 10:53 a.m. UTC
  Consider a hello world compiled with -g into an a.out:
...
int main (void) {
  printf ("hello\n");
  return 0;
}
...

After starting TUI like this:
...
$ gdb -q a.out -ex start -ex "tui enable"
...
we do "echo \n" and type enter until the prompt is at the bottom of the screen.

After doing next to execute the printf, we have:
...
(gdb) next
hello
(gdb)
...
but the entire screen scrolled, so:
- the src window is missing the top border
- the updates in the src and status window are misaligned with the current
  screen.

We can fix this by doing ^L.

Fix this by doing ^L automatically when gdb_tty_state changes to
target_terminal_state::is_ours.

Tested on x86_64-linux.
---
 gdb/testsuite/gdb.tui/hello.exp |  3 ---
 gdb/tui/tui-hooks.c             | 11 +++++++++++
 2 files changed, 11 insertions(+), 3 deletions(-)
  

Comments

Guinevere Larsen May 31, 2023, 2:18 p.m. UTC | #1
On 30/05/2023 12:53, Tom de Vries via Gdb-patches wrote:
> Consider a hello world compiled with -g into an a.out:
> ...
> int main (void) {
>    printf ("hello\n");
>    return 0;
> }
> ...
>
> After starting TUI like this:
> ...
> $ gdb -q a.out -ex start -ex "tui enable"
> ...
> we do "echo \n" and type enter until the prompt is at the bottom of the screen.
>
> After doing next to execute the printf, we have:
> ...
> (gdb) next
> hello
> (gdb)
> ...
> but the entire screen scrolled, so:
> - the src window is missing the top border
> - the updates in the src and status window are misaligned with the current
>    screen.
>
> We can fix this by doing ^L.
>
> Fix this by doing ^L automatically when gdb_tty_state changes to
> target_terminal_state::is_ours.
>
> Tested on x86_64-linux.

This is a nice cleanup after patch #1. Once the issue I outlined in my 
comment to that patch is solved, this will be a nice cleanup for the 
functionality, and the series as a whole does not add any regressions.

Reviewed-By: Bruno Larsen <blarsen@redhat.com>

> ---
>   gdb/testsuite/gdb.tui/hello.exp |  3 ---
>   gdb/tui/tui-hooks.c             | 11 +++++++++++
>   2 files changed, 11 insertions(+), 3 deletions(-)
>
> diff --git a/gdb/testsuite/gdb.tui/hello.exp b/gdb/testsuite/gdb.tui/hello.exp
> index 9634d9d8059..641b3b0c48e 100644
> --- a/gdb/testsuite/gdb.tui/hello.exp
> +++ b/gdb/testsuite/gdb.tui/hello.exp
> @@ -47,9 +47,6 @@ Term::check_box "before next: source box" 0 0 80 15
>   # Make the inferior print "hello".
>   Term::command "next"
>   
> -# Refresh to redraw the screen.
> -Term::command "refresh"
> -
>   # Check the source box again.
>   Term::check_box "after next: source box" 0 0 80 15
>   
> diff --git a/gdb/tui/tui-hooks.c b/gdb/tui/tui-hooks.c
> index d67c3d7f353..d1d307cf9ce 100644
> --- a/gdb/tui/tui-hooks.c
> +++ b/gdb/tui/tui-hooks.c
> @@ -211,6 +211,15 @@ tui_symtab_changed ()
>     from_source_symtab = true;
>   }
>   
> +/* Observer for terminal_owner_changed.  */
> +
> +static void
> +tui_terminal_owner_changed (target_terminal_state gdb_tty_state, bool active)
> +{
> +  if (active && gdb_tty_state == target_terminal_state::is_ours)
> +    tui_refresh_all_win (false);
> +}
> +
>   /* Token associated with observers registered while TUI hooks are
>      installed.  */
>   static const gdb::observers::token tui_observers_token {};
> @@ -250,6 +259,8 @@ tui_attach_detach_observers (bool attach)
>   		    tui_context_changed, attach);
>     attach_or_detach (gdb::observers::current_source_symtab_and_line_changed,
>   		    tui_symtab_changed, attach);
> +  attach_or_detach (gdb::observers::terminal_owner_changed,
> +		    tui_terminal_owner_changed, attach);
>   }
>   
>   /* Install the TUI specific hooks.  */
  

Patch

diff --git a/gdb/testsuite/gdb.tui/hello.exp b/gdb/testsuite/gdb.tui/hello.exp
index 9634d9d8059..641b3b0c48e 100644
--- a/gdb/testsuite/gdb.tui/hello.exp
+++ b/gdb/testsuite/gdb.tui/hello.exp
@@ -47,9 +47,6 @@  Term::check_box "before next: source box" 0 0 80 15
 # Make the inferior print "hello".
 Term::command "next"
 
-# Refresh to redraw the screen.
-Term::command "refresh"
-
 # Check the source box again.
 Term::check_box "after next: source box" 0 0 80 15
 
diff --git a/gdb/tui/tui-hooks.c b/gdb/tui/tui-hooks.c
index d67c3d7f353..d1d307cf9ce 100644
--- a/gdb/tui/tui-hooks.c
+++ b/gdb/tui/tui-hooks.c
@@ -211,6 +211,15 @@  tui_symtab_changed ()
   from_source_symtab = true;
 }
 
+/* Observer for terminal_owner_changed.  */
+
+static void
+tui_terminal_owner_changed (target_terminal_state gdb_tty_state, bool active)
+{
+  if (active && gdb_tty_state == target_terminal_state::is_ours)
+    tui_refresh_all_win (false);
+}
+
 /* Token associated with observers registered while TUI hooks are
    installed.  */
 static const gdb::observers::token tui_observers_token {};
@@ -250,6 +259,8 @@  tui_attach_detach_observers (bool attach)
 		    tui_context_changed, attach);
   attach_or_detach (gdb::observers::current_source_symtab_and_line_changed,
 		    tui_symtab_changed, attach);
+  attach_or_detach (gdb::observers::terminal_owner_changed,
+		    tui_terminal_owner_changed, attach);
 }
 
 /* Install the TUI specific hooks.  */