From: Tom de Vries Date: Fri, 15 Aug 2025 12:48:10 +0000 (+0200) Subject: [gdb/tui] Clear readline buffer on switching to TUI X-Git-Tag: gdb-17-branchpoint~296 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ee3c07a28be01ff4ab34089b8849aa398cc2d612;p=thirdparty%2Fbinutils-gdb.git [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 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 --- diff --git a/gdb/tui/tui.c b/gdb/tui/tui.c index 5883d6cad5e..01aee2f1788 100644 --- a/gdb/tui/tui.c +++ b/gdb/tui/tui.c @@ -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 ();