}
}
}
+
+# Test operate_and_get_next when selecting the last command.
+with_test_prefix "operate_and_get_next last command" {
+ clean_restart
+
+ # Expected output from echo 1\n.
+ set re1 \
+ [multi_line \
+ "" \
+ "1"]
+
+ # Expected output from echo 2\n.
+ set re2 \
+ [multi_line \
+ "" \
+ "2"]
+
+ # Enter command into history.
+ gdb_test {echo 1\n} $re1 \
+ "enter command"
+
+ # Recall command from history (Ctrl-r, 022), and do operate-and-get-next
+ # (Ctrl-o, 017). There shouldn't be a prefill, but if there is one,
+ # prevent a possible timeout using -no-prompt-anchor.
+ send_gdb "\022echo 1\017"
+ gdb_test -no-prompt-anchor "" $re1 \
+ "recall command"
+
+ # Regression test for PR32485: Since we recalled the last command, there
+ # shouldn't be a prefil, so check that here.
+ # If there is no prefil, we simple have:
+ # (gdb) echo 2\n^M
+ # 2^M
+ # (gdb)
+ # If there is a prefil, we have:
+ # (gdb) echo 1\necho 2\n^M
+ # 1^M
+ # echo 2^M
+ # (gdb)
+ gdb_test {echo 2\n} $re2 \
+ "no prefill"
+}
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 ();
/* 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;