diff options
author | Pedro Alves <palves@redhat.com> | 2016-06-21 01:11:48 +0100 |
---|---|---|
committer | Pedro Alves <palves@redhat.com> | 2016-06-21 01:11:48 +0100 |
commit | 3c216924d6ae534ea6c2f6bdcc4b42238af52ab1 (patch) | |
tree | 3c75bdbe8e48f1ae075ca113b8a1b66171d5c780 /gdb/tui | |
parent | b6dcde571e1a230d12fc483ba6d38a1253ab097e (diff) | |
download | fsf-binutils-gdb-3c216924d6ae534ea6c2f6bdcc4b42238af52ab1.zip fsf-binutils-gdb-3c216924d6ae534ea6c2f6bdcc4b42238af52ab1.tar.gz fsf-binutils-gdb-3c216924d6ae534ea6c2f6bdcc4b42238af52ab1.tar.bz2 |
Make command line editing (use of readline) be per UI
Due to the way that readline's API works (based on globals), we can
only have one instance of readline in a process. So the goal of this
patch is to only allow editing in the main UI, and make sure that only
one UI calls into readline. Some MI paths touch readline variables
currently, which is bad as that is changing variables that matter for
the main console UI. This patch fixes those.
This actually fixes a nasty bug -- starting gdb in MI mode ("gdb
-i=mi"), and then doing "set editing on" crashes GDB, because MI is
not prepared to use readline:
set editing on
&"set editing on\n"
=cmd-param-changed,param="editing",value="on"
^done
(gdb)
p 1
readline: readline_callback_read_char() called with no handler!
Aborted (core dumped)
The fix for that was to add an interp_proc method to query the
interpreter whether it actually supports editing. New test included.
gdb/ChangeLog:
2016-06-21 Pedro Alves <palves@redhat.com>
PR mi/20034
* cli/cli-interp.c: Include cli-interp.h and event-top.h.
(cli_interpreter_resume): Pass 1 to gdb_setup_readline. Set the
UI's input_handler here.
(cli_interpreter_supports_command_editing): New function.
(cli_interp_procs): Install it.
* cli/cli-interp.h: New file.
* event-top.c (async_command_editing_p): Rename to ...
(set_editing_cmd_var): ... this.
(change_line_handler): Add parameter 'editing', and use it. Bail
early if the interpreter doesn't support editing. Don't touch
readline state if editing is off.
(gdb_rl_callback_handler_remove, gdb_rl_callback_handler_install)
(gdb_rl_callback_handler_reinstall): Assert the current UI is the
main UI.
(display_gdb_prompt): Don't call gdb_rl_callback_handler_remove if
not using readline. Check whether the current UI is using command
editing instead of checking the async_command_editing_p global.
(set_async_editing_command): Delete.
(gdb_setup_readline): Add 'editing' parameter. Only allow editing
on the main UI. Don't touch readline state if editing is off.
(gdb_disable_readline): Don't touch readline state if editing is
off.
* event-top.h (gdb_setup_readline): Add 'int' parameter.
(set_async_editing_command): Delete declaration.
(change_line_handler, command_line_handler): Declare.
(async_command_editing_p): Rename to ...
(set_editing_cmd_var): ... this.
* infrun.c (reinstall_readline_callback_handler_cleanup): Check
whether the current UI has editing enabled rather than checking
the async_command_editing_p global.
* interps.c (interp_supports_command_editing): New function.
* interps.h (interp_supports_command_editing_ftype): New typedef.
(struct interp_procs) <supports_command_editing_proc>: New field.
(interp_supports_command_editing): Declare.
* mi/mi-interp.c (mi_interpreter_resume): Pass 0 to
gdb_setup_readline. Don't clear the async_command_editing_p
global. Update comments.
* top.c (gdb_readline_wrapper_line, gdb_readline_wrapper): Check
whether the current UI has editing enabled rather than checking
the async_command_editing_p global. Don't touch readline state if
editing is off.
(undo_terminal_modifications_before_exit): Switch to the main UI.
Unconditionally call gdb_disable_readline.
(set_editing): New function.
(show_async_command_editing_p): Rename to ...
(show_editing): ... this. Show the state of the current UI.
(_initialize_top): Adjust.
* top.h (struct ui) <command_editing>: New field.
* tui/tui-interp.c: Include cli/cli-interp.h.
(tui_resume): Pass 1 to gdb_setup_readline. Set the UI's
input_handler.
(tui_interp_procs): Install
cli_interpreter_supports_command_editing.
* tui/tui-io.c (tui_getc): Check whether the current UI has
editing enabled rather than checking the async_command_editing_p
global.
gdb/testsuite/ChangeLog:
2016-06-21 Pedro Alves <palves@redhat.com>
PR mi/20034
* gdb.mi/mi-editing.exp: New file.
Diffstat (limited to 'gdb/tui')
-rw-r--r-- | gdb/tui/tui-interp.c | 9 | ||||
-rw-r--r-- | gdb/tui/tui-io.c | 2 |
2 files changed, 8 insertions, 3 deletions
diff --git a/gdb/tui/tui-interp.c b/gdb/tui/tui-interp.c index 452dd20..85bb26d 100644 --- a/gdb/tui/tui-interp.c +++ b/gdb/tui/tui-interp.c @@ -18,6 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "defs.h" +#include "cli/cli-interp.h" #include "interps.h" #include "top.h" #include "event-top.h" @@ -219,6 +220,7 @@ tui_init (struct interp *self, int top_level) static int tui_resume (void *data) { + struct ui *ui = current_ui; struct ui_file *stream; /* gdb_setup_readline will change gdb_stdout. If the TUI was @@ -232,7 +234,9 @@ tui_resume (void *data) stream = NULL; } - gdb_setup_readline (); + gdb_setup_readline (1); + + ui->input_handler = command_line_handler; if (stream != NULL) cli_out_set_stream (tui_old_uiout, gdb_stdout); @@ -274,7 +278,8 @@ static const struct interp_procs tui_interp_procs = { tui_exec, tui_ui_out, NULL, - cli_command_loop + cli_command_loop, + cli_interpreter_supports_command_editing, }; /* Factory for TUI interpreters. */ diff --git a/gdb/tui/tui-io.c b/gdb/tui/tui-io.c index 3fa32db..6f2d892 100644 --- a/gdb/tui/tui-io.c +++ b/gdb/tui/tui-io.c @@ -616,7 +616,7 @@ tui_getc (FILE *fp) if (ch == KEY_BACKSPACE) return '\b'; - if (async_command_editing_p && key_is_start_sequence (ch)) + if (current_ui->command_editing && key_is_start_sequence (ch)) { int ch_pending; |