public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug cli/32485] New: [gdb/cli, ^O] gdb operate-and-get-next different from bash operate-and-get-next
@ 2024-12-20 11:43 vries at gcc dot gnu.org
2024-12-20 14:25 ` [Bug cli/32485] " vries at gcc dot gnu.org
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: vries at gcc dot gnu.org @ 2024-12-20 11:43 UTC (permalink / raw)
To: gdb-prs
https://sourceware.org/bugzilla/show_bug.cgi?id=32485
Bug ID: 32485
Summary: [gdb/cli, ^O] gdb operate-and-get-next different from
bash operate-and-get-next
Product: gdb
Version: HEAD
Status: NEW
Severity: normal
Priority: P2
Component: cli
Assignee: unassigned at sourceware dot org
Reporter: vries at gcc dot gnu.org
Target Milestone: ---
TIL (from reading gdb source code) about a bash feature operate-and-get-next,
activated using Ctrl-o:
...
$ <echo 1>echo 1<enter>
1
$ <echo 2>echo 2<enter>
2
$ <echo 3>echo 3<enter>
1
$ <Ctrl-r>(reverse-i-search)`': <echo 1>echo 1<Ctrl-o>
1
$ echo 2<Ctrl-o>
2
$ echo 3<Ctrl-o>
3
$ echo 1
...
So, typing Ctrl-o executes the command, and prefills the next found in history.
We have the same in gdb:
...
$ gdb -q
(gdb) <echo 1\n>echo 1\n<enter>
1
(gdb) <echo 2\n>echo 3\n<enter>
2
(gdb) <echo 3\n>echo 3\n<enter>
3
(gdb) <Ctrl-r>(reverse-i-search)`': <echo 1>echo 1<Ctrl-o>
1
(gdb) echo 2\n<Ctrl-o>
2
(gdb) echo 3\n<Ctrl-o>
3
(gdb) echo 1\n
...
However, say we repeat the last command.
With bash, we have no prefill:
...
$ <echo 3>echo 3<enter>
$ <Ctrl-r>(reverse-i-search)`': <echo 3>echo 3<Ctrl-o>
$
...
But with gdb, we do:
...
(gdb) <echo 3\n>echo 3\n<enter>
3
(gdb) <Ctrl-r>(reverse-i-search)`': <echo 3>echo 3\n<Ctrl-o>
3
(gdb) echo 3\n
...
Fixed by:
...
$ git diff
diff --git a/gdb/top.c b/gdb/top.c
index c7a62c15ae2..bcaf4dc6a55 100644
--- a/gdb/top.c
+++ b/gdb/top.c
@@ -1054,11 +1054,14 @@ static int operate_saved_history = -1;
static void
gdb_rl_operate_and_get_next_completion (void)
{
- int delta = where_history () - operate_saved_history;
+ if (operate_saved_history != -1)
+ {
+ int delta = where_history () - operate_saved_history;
- /* The `key' argument to rl_get_previous_history is ignored. */
- rl_get_previous_history (delta, 0);
- operate_saved_history = -1;
+ /* The `key' argument to rl_get_previous_history is ignored. */
+ rl_get_previous_history (delta, 0);
+ operate_saved_history = -1;
+ }
/* readline doesn't automatically update the display for us. */
rl_redisplay ();
@@ -1083,9 +1086,10 @@ gdb_rl_operate_and_get_next (int count, int key)
/* Find the current line, and find the next line to use. */
where = where_history();
- if ((history_is_stifled () && (history_length >= history_max_entries))
- || (where >= history_length - 1))
+ if (history_is_stifled () && history_length >= history_max_entries)
operate_saved_history = where;
+ else if (where >= history_length - 1)
+ operate_saved_history = -1;
else
operate_saved_history = where + 1;
...
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug cli/32485] [gdb/cli, ^O] gdb operate-and-get-next different from bash operate-and-get-next
2024-12-20 11:43 [Bug cli/32485] New: [gdb/cli, ^O] gdb operate-and-get-next different from bash operate-and-get-next vries at gcc dot gnu.org
@ 2024-12-20 14:25 ` vries at gcc dot gnu.org
2024-12-20 17:34 ` cvs-commit at gcc dot gnu.org
2024-12-20 17:35 ` vries at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: vries at gcc dot gnu.org @ 2024-12-20 14:25 UTC (permalink / raw)
To: gdb-prs
https://sourceware.org/bugzilla/show_bug.cgi?id=32485
--- Comment #1 from Tom de Vries <vries at gcc dot gnu.org> ---
https://sourceware.org/pipermail/gdb-patches/2024-December/214297.html
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug cli/32485] [gdb/cli, ^O] gdb operate-and-get-next different from bash operate-and-get-next
2024-12-20 11:43 [Bug cli/32485] New: [gdb/cli, ^O] gdb operate-and-get-next different from bash operate-and-get-next vries at gcc dot gnu.org
2024-12-20 14:25 ` [Bug cli/32485] " vries at gcc dot gnu.org
@ 2024-12-20 17:34 ` cvs-commit at gcc dot gnu.org
2024-12-20 17:35 ` vries at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-12-20 17:34 UTC (permalink / raw)
To: gdb-prs
https://sourceware.org/bugzilla/show_bug.cgi?id=32485
--- Comment #2 from Sourceware Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Tom de Vries <vries@sourceware.org>:
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=602f66f5aba3b3871cef08306f9c3c2962992784
commit 602f66f5aba3b3871cef08306f9c3c2962992784
Author: Tom de Vries <tdevries@suse.de>
Date: Fri Dec 20 18:34:50 2024 +0100
[gdb/cli] Don't prefill for operate-and-get-next of last command
Consider operate-and-get-next [1] in bash:
...
$ <echo 1>echo 1<enter>
1
$ <echo 2>echo 2<enter>
2
$ <Ctrl-r>(reverse-i-search)`': <echo 1>echo 1<Ctrl-o>
1
$ echo 2<Ctrl-o>
2
$ echo 1
...
So, typing Ctrl-o:
- executes the recalled command, and
- prefills the next one (which then can be executed again with Ctrl-o).
We have the same functionality in gdb, but when recalling the last command
from history with bash we have no prefill:
...
$ <echo 1>echo 1<enter>
1
$ <Ctrl-r>(reverse-i-search)`': <echo 1>echo 1<Ctrl-o>
1
$
...
but with gdb do we have a prefill:
...
(gdb) echo 1\n
1
(gdb) <Ctrl-r>(reverse-i-search)`': <echo 1>echo 1\n<Ctrl-o>
1
(gdb) echo 1\n
...
Following the principle of least surprise [2], I think gdb should do what
bash
does.
Fix this by:
- signalling this case in gdb_rl_operate_and_get_next using
"operate_saved_history = -1", and
- handling operate_saved_history == -1 in
gdb_rl_operate_and_get_next_completion.
Tested on aarch64-linux.
Approved-By: Tom Tromey <tom@tromey.com>
PR cli/32485
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32485
[1] https://www.man7.org/linux/man-pages/man3/readline.3.html
[2] https://en.wikipedia.org/wiki/Principle_of_least_astonishment
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug cli/32485] [gdb/cli, ^O] gdb operate-and-get-next different from bash operate-and-get-next
2024-12-20 11:43 [Bug cli/32485] New: [gdb/cli, ^O] gdb operate-and-get-next different from bash operate-and-get-next vries at gcc dot gnu.org
2024-12-20 14:25 ` [Bug cli/32485] " vries at gcc dot gnu.org
2024-12-20 17:34 ` cvs-commit at gcc dot gnu.org
@ 2024-12-20 17:35 ` vries at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: vries at gcc dot gnu.org @ 2024-12-20 17:35 UTC (permalink / raw)
To: gdb-prs
https://sourceware.org/bugzilla/show_bug.cgi?id=32485
Tom de Vries <vries at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |FIXED
Target Milestone|--- |16.1
Status|NEW |RESOLVED
--- Comment #3 from Tom de Vries <vries at gcc dot gnu.org> ---
Fixed.
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-12-20 17:35 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-12-20 11:43 [Bug cli/32485] New: [gdb/cli, ^O] gdb operate-and-get-next different from bash operate-and-get-next vries at gcc dot gnu.org
2024-12-20 14:25 ` [Bug cli/32485] " vries at gcc dot gnu.org
2024-12-20 17:34 ` cvs-commit at gcc dot gnu.org
2024-12-20 17:35 ` vries at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).