aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom de Vries <tdevries@suse.de>2025-08-15 14:48:10 +0200
committerTom de Vries <tdevries@suse.de>2025-08-15 14:48:10 +0200
commitee3c07a28be01ff4ab34089b8849aa398cc2d612 (patch)
treefa93be904491b89cb94a8d10fb0abc673b5782dc
parente53b88b40ed38651b50f954dfe76066822094c15 (diff)
downloadbinutils-ee3c07a28be01ff4ab34089b8849aa398cc2d612.zip
binutils-ee3c07a28be01ff4ab34089b8849aa398cc2d612.tar.gz
binutils-ee3c07a28be01ff4ab34089b8849aa398cc2d612.tar.bz2
[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
-rw-r--r--gdb/tui/tui.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/gdb/tui/tui.c b/gdb/tui/tui.c
index 5883d6c..01aee2f 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 ();