]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
[gdb/tui] Clear readline buffer on switching to TUI
authorTom de Vries <tdevries@suse.de>
Fri, 15 Aug 2025 12:48:10 +0000 (14:48 +0200)
committerTom de Vries <tdevries@suse.de>
Fri, 15 Aug 2025 12:48:10 +0000 (14:48 +0200)
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

gdb/tui/tui.c

index 5883d6cad5ed9e2f478ecc824d13e836de6f7aac..01aee2f178869ca465a20eb749943bf799f33b17 100644 (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 ();