diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 432cdccd2c..92847f7217 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,10 @@ +2017-03-08 Pedro Alves + + PR cli/21218 + * top.c (gdb_readline_wrapper): Avoid passing NULL to + display_gdb_prompt. + (command_line_input): Add comment. + 2017-03-08 Pedro Alves PR tui/21216 diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 0654bef40d..d7b603b43f 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,11 @@ +2017-03-08 Pedro Alves + Jan Kratochvil + + PR cli/21218 + * gdb.base/commands.exp (backslash_in_multi_line_command_test): + New proc. + (top level): Call it. + 2017-03-08 Pedro Alves PR tui/21216 diff --git a/gdb/testsuite/gdb.base/commands.exp b/gdb/testsuite/gdb.base/commands.exp index 9ad70f5244..6d3c398c6e 100644 --- a/gdb/testsuite/gdb.base/commands.exp +++ b/gdb/testsuite/gdb.base/commands.exp @@ -1003,6 +1003,34 @@ proc_with_prefix redefine_backtrace_test {} { gdb_test "bt" "hibob" "execute bt command" } +# Test an input line split with a continuation character (backslash) +# while entering a multi-line command (in a secondary prompt). + +proc_with_prefix backslash_in_multi_line_command_test {} { + gdb_breakpoint "main" + + gdb_test_multiple "commands" "commands" { + -re "End with a line saying just \"end\"\\.\r\n>$" { + pass "commands" + } + } + + set test "input line split with backslash" + send_gdb "print \\\nargc\n" + gdb_test_multiple "" $test { + -re "^print \\\\\r\nargc\r\n>$" { + pass $test + } + } + + gdb_test_no_output "end" + + # Input any command, just to be sure the readline state is sane. + # In PR 21218, this would trigger the infamous: + # readline: readline_callback_read_char() called with no handler! + gdb_test "print 1" "" "run command" +} + gdbvar_simple_if_test gdbvar_simple_while_test gdbvar_complex_if_while_test @@ -1027,5 +1055,6 @@ recursive_source_test if_commands_test error_clears_commands_left redefine_hook_test +backslash_in_multi_line_command_test # This one should come last, as it redefines "backtrace". redefine_backtrace_test diff --git a/gdb/top.c b/gdb/top.c index 6bf9d8c021..295b6806de 100644 --- a/gdb/top.c +++ b/gdb/top.c @@ -1030,8 +1030,11 @@ gdb_readline_wrapper (const char *prompt) if (cleanup->target_is_async_orig) target_async (0); - /* Display our prompt and prevent double prompt display. */ - display_gdb_prompt (prompt); + /* Display our prompt and prevent double prompt display. Don't pass + down a NULL prompt, since that has special meaning for + display_gdb_prompt -- it indicates a request to print the primary + prompt, while we want a secondary prompt here. */ + display_gdb_prompt (prompt != NULL ? prompt : ""); if (ui->command_editing) rl_already_prompted = 1; @@ -1307,6 +1310,9 @@ command_line_input (const char *prompt_arg, int repeat, char *annotation_suffix) if (cmd != NULL) break; + /* Got partial input. I.e., got a line that ends with a + continuation character (backslash). Suppress printing the + prompt again. */ prompt = NULL; }