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
}
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 ();