[gdb/tui] Clear readline buffer on switching to TUI

Consider the following scenario.  We start gdb and type foo:
...
$ gdb -q
(gdb) foo
         ^
...

Then we switch to TUI using C-x C-a, and switch back using the same key
combination.

We get back the same, but with the cursor after the prompt:
...
(gdb) foo
      ^
...

Typing b<ENTER> gives us:
...
(gdb) boo
️ No default breakpoint address now.
(gdb)
...
which means gdb didn't see "boo" here, just "b".

So while "foo" is part of the readline buffer when leaving CLI, it's not upon
returning to CLI, but it is still on screen, which is confusing.

Fix this by using rl_clear_visible_line in tui_rl_switch_mode to clear the
readline buffer when leaving CLI.

This only reproduces for me with TERM=xterm.

Tested on x86_64-linux.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30523
This commit is contained in:
Tom de Vries
2025-08-15 14:48:10 +02:00
parent e53b88b40e
commit ee3c07a28b

View File

@@ -125,6 +125,19 @@ tui_rl_switch_mode (int notused1, int notused2)
}
else
{
/* If we type "foo", entering it into the readline buffer
(gdb) foo
^
and then switch to TUI and back, we may get back
(gdb) foo
^
which is confusing because "foo" is no longer part of the
readline buffer. Fix this by clearing it before switching to
TUI. */
rl_clear_visible_line ();
/* If tui_enable throws, we'll re-prep below. */
rl_deprep_terminal ();
tui_enable ();