]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit - gdb/testsuite/ChangeLog
Fix PR 21218: GDB dumps core when escaping newline in multi-line command
authorPedro Alves <palves@redhat.com>
Wed, 8 Mar 2017 11:41:35 +0000 (11:41 +0000)
committerPedro Alves <palves@redhat.com>
Wed, 8 Mar 2017 11:41:35 +0000 (11:41 +0000)
commit6e5d74e74756fafe59e8198c4cc462cf7c57e12c
tree010e0817845a560794e50a2ad2f8eb12c7c1c62c
parent5cf70512f835032c413f2554af07814e1dc05cd6
Fix PR 21218: GDB dumps core when escaping newline in multi-line command

With commit 3b12939dfc2399 ("Replace the sync_execution global with a
new enum prompt_state tristate"), GDB started aborting if you try
splitting an input line with a continuation char (backslash) while in
a multi-line command:

 (gdb) commands
 Type commands for breakpoint(s) 1, one per line.
 End with a line saying just "end".
 >print \

 (gdb) 1      # note "(gdb)" incorrectly printed here.
 >end

 readline: readline_callback_read_char() called with no handler!
 $

That abort is actually a symptom of an old problem introduced when
gdb_readline_wrapper was rewritten to use asynchronous readline, back
in 2007.  Note how the "(gdb)" prompt is printed above in the "(gdb)
1" line.  Clearly it shouldn't be there, but it already was before the
commit mentioned above.  Fixing that also fixes the readline abort
shown above.

The problem starts when command_line_input passes a NULL prompt to
gdb_readline_wrapper when it finds previous incomplete input due to a
backslash, trying to fetch more input without printing another ">"
secondary prompt.  That itself should not be a problem, because
passing NULL to gdb_readline_wrapper has the same meaning as passing a
pointer to empty string, since gdb_readline_wrapper exposes the same
interface as 'readline(char *)'.  However, gdb_readline_wrapper passes
the prompt argument directly to display_gdb_prompt, and for the
latter, a NULL prompt argument has a different meaning - it requests
printing the primary prompt.

Before commit 782a7b8ef9c096 (which rewrote gdb_readline_wrapper to
use asynchronous readline), GDB behaved like this:

 (gdb) commands
 [....]
 >print \
 1
 >end
 (gdb)

The above is what this commit restores GDB back to.

New test included.

gdb/ChangeLog:
2017-03-08  Pedro Alves  <palves@redhat.com>

PR cli/21218
* top.c (gdb_readline_wrapper): Avoid passing NULL to
display_gdb_prompt.
(command_line_input): Add comment.

gdb/testsuite/ChangeLog:
2017-03-08  Pedro Alves  <palves@redhat.com>
    Jan Kratochvil  <jan.kratochvil@redhat.com>

PR cli/21218
* gdb.base/commands.exp (backslash_in_multi_line_command_test):
New proc.
(top level): Call it.
gdb/ChangeLog
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.base/commands.exp
gdb/top.c