From 268a799a454ce862f516ff2215290fae08eca7fa Mon Sep 17 00:00:00 2001 From: Pedro Alves Date: Tue, 21 Jun 2016 01:11:54 +0100 Subject: Make stdin be per UI This commit makes each UI have its own "stdin" stream pointer. This is used to determine whether the "from_tty" argument to execute_command, etc. should be true. Related, this commit makes input_from_terminal_p take an UI parameter, and then avoids the gdb_has_a_terminal in it. gdb_has_a_terminal only returns info on gdb's own main/primary terminal (the real stdin). However, the places that call input_from_terminal_p really want to know is whether the command came from an interactive tty. This patch thus renames input_from_terminal_p to input_interactive_p for clarity, and then makes input_interactive_p check for "set interactive" itself, along with ISATTY, instead of calling gdb_has_a_terminal. Actually, quit_force wants to call input_interactive_p _after_ stdin is closed, we can't call ISATTY that late. So instead we save the result of ISATTY in a field of the UI. gdb/ChangeLog: 2016-06-21 Pedro Alves * cli/cli-script.c (read_next_line): Adjust to per-UI stdin. (read_command_lines): Use input_interactive_p instead of input_from_terminal_p. * defs.h (struct ui): Forward declare. (input_from_terminal_p): Rename to ... (input_interactive_p): ... this. * event-top.c (stdin_event_handler): Pass 0 as from_tty argument to quit_command. (command_handler): Adjust to per-UI stdin. (handle_line_of_input): Adjust to per-UI stdin and use input_interactive_p instead of ISATTY and input_from_terminal_p. (gdb_readline_no_editing_callback): Adjust to per-UI stdin. (command_line_handler): Always pass true as "from_tty" parameter of handle_line_of_input and execute_command. (async_sigterm_handler): Pass 0 as from_tty argument to quit_command. * inflow.c (interactive_mode, show_interactive_mode): Moved to ... (gdb_has_a_terminal): Don't check interactive_mode here. (_initialize_inflow): Don't install "set interactive-mode" here. * main.c (captured_command_loop): Adjust to per-UI stdin. * mi/mi-interp.c (mi_execute_command_wrapper): Adjust to per-UI stdin. * top.c (new_ui): Save the stdin stream and whether it's a tty. (dont_repeat): Adjust to per-UI stdin. (command_line_input): Adjust to per-UI stdin and to use input_interactive_p. (quit_force): Write history if any UI supports interactive input. (interactive_mode, show_interactive_mode): Move here, from inflow.c. (input_from_terminal_p): Rename to ... (input_interactive_p): ... this, and check the "interactive_mode" global instead of calling gdb_has_a_terminal. (_initialize_top): Install "set interactive-mode" here. * top.h (struct ui) : New fields. * utils.c (quit): Pass 0 as from_tty argument to quit_force. (defaulted_query): Adjust to per-UI stdin and to use input_interactive_p. --- gdb/cli/cli-script.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'gdb/cli/cli-script.c') diff --git a/gdb/cli/cli-script.c b/gdb/cli/cli-script.c index 0507c55..579d0a4 100644 --- a/gdb/cli/cli-script.c +++ b/gdb/cli/cli-script.c @@ -935,12 +935,13 @@ read_next_line (void) struct ui *ui = current_ui; char *prompt_ptr, control_prompt[256]; int i = 0; + int from_tty = ui->instream == ui->stdin_stream; if (control_level >= 254) error (_("Control nesting too deep!")); /* Set a prompt based on the nesting of the control commands. */ - if (ui->instream == stdin + if (from_tty || (ui->instream == 0 && deprecated_readline_hook != NULL)) { for (i = 0; i < control_level; i++) @@ -952,7 +953,7 @@ read_next_line (void) else prompt_ptr = NULL; - return command_line_input (prompt_ptr, ui->instream == stdin, "commands"); + return command_line_input (prompt_ptr, from_tty, "commands"); } /* Process one input line. If the command is an "end", return such an @@ -1256,7 +1257,7 @@ read_command_lines (char *prompt_arg, int from_tty, int parse_commands, { struct command_line *head; - if (from_tty && input_from_terminal_p ()) + if (from_tty && input_interactive_p (current_ui)) { if (deprecated_readline_begin_hook) { @@ -1287,7 +1288,8 @@ read_command_lines (char *prompt_arg, int from_tty, int parse_commands, do_cleanups (old_chain); } - if (deprecated_readline_end_hook && from_tty && input_from_terminal_p ()) + if (from_tty && input_interactive_p (current_ui) + && deprecated_readline_end_hook) { (*deprecated_readline_end_hook) (); } -- cgit v1.1