diff options
author | Pedro Alves <palves@redhat.com> | 2016-06-21 01:11:54 +0100 |
---|---|---|
committer | Pedro Alves <palves@redhat.com> | 2016-06-21 01:11:54 +0100 |
commit | 268a799a454ce862f516ff2215290fae08eca7fa (patch) | |
tree | f68a29246ef353cdcefa73f01979fb931957ff21 /gdb/event-top.c | |
parent | 07169ff772077f566c6540f623d7d609babc4c81 (diff) | |
download | gdb-268a799a454ce862f516ff2215290fae08eca7fa.zip gdb-268a799a454ce862f516ff2215290fae08eca7fa.tar.gz gdb-268a799a454ce862f516ff2215290fae08eca7fa.tar.bz2 |
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 <palves@redhat.com>
* 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) <stdin_stream, input_interactive_p>: 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.
Diffstat (limited to 'gdb/event-top.c')
-rw-r--r-- | gdb/event-top.c | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/gdb/event-top.c b/gdb/event-top.c index 777823e..072ad2a 100644 --- a/gdb/event-top.c +++ b/gdb/event-top.c @@ -518,7 +518,7 @@ stdin_event_handler (int error, gdb_client_data client_data) { /* If stdin died, we may as well kill gdb. */ printf_unfiltered (_("error detected on stdin\n")); - quit_command ((char *) 0, stdin == ui->instream); + quit_command ((char *) 0, 0); } else { @@ -589,7 +589,7 @@ command_handler (char *command) struct cleanup *stat_chain; char *c; - if (ui->instream == stdin) + if (ui->instream == ui->stdin_stream) reinitialize_more_filter (); stat_chain = make_command_stats_cleanup (1); @@ -599,7 +599,7 @@ command_handler (char *command) ; if (c[0] != '#') { - execute_command (command, ui->instream == stdin); + execute_command (command, ui->instream == ui->stdin_stream); /* Do any commands attached to breakpoint we stopped at. */ bpstat_do_actions (); @@ -667,6 +667,7 @@ handle_line_of_input (struct buffer *cmd_line_buffer, char *rl, int repeat, char *annotation_suffix) { struct ui *ui = current_ui; + int from_tty = ui->instream == ui->stdin_stream; char *p1; char *cmd; @@ -681,7 +682,7 @@ handle_line_of_input (struct buffer *cmd_line_buffer, command, but leave ownership of memory to the buffer . */ cmd_line_buffer->used_size = 0; - if (annotation_level > 1 && ui->instream == stdin) + if (from_tty && annotation_level > 1) { printf_unfiltered (("\n\032\032post-")); puts_unfiltered (annotation_suffix); @@ -698,8 +699,7 @@ handle_line_of_input (struct buffer *cmd_line_buffer, } /* Do history expansion if that is wished. */ - if (history_expansion_p && ui->instream == stdin - && ISATTY (ui->instream)) + if (history_expansion_p && from_tty && input_interactive_p (current_ui)) { char *history_value; int expanded; @@ -743,7 +743,7 @@ handle_line_of_input (struct buffer *cmd_line_buffer, and then later fetch it from the value history and remove the '#'. The kill ring is probably better, but some people are in the habit of commenting things out. */ - if (*cmd != '\0' && input_from_terminal_p ()) + if (*cmd != '\0' && from_tty && input_interactive_p (current_ui)) gdb_add_history (cmd); /* Save into global buffer if appropriate. */ @@ -772,8 +772,7 @@ command_line_handler (char *rl) struct ui *ui = current_ui; char *cmd; - cmd = handle_line_of_input (line_buffer, rl, ui->instream == stdin, - "prompt"); + cmd = handle_line_of_input (line_buffer, rl, 1, "prompt"); if (cmd == (char *) EOF) { /* stdin closed. The connection with the terminal is gone. @@ -781,7 +780,7 @@ command_line_handler (char *rl) hung up but GDB is still alive. In such a case, we just quit gdb killing the inferior program too. */ printf_unfiltered ("quit\n"); - execute_command ("quit", stdin == ui->instream); + execute_command ("quit", 1); } else if (cmd == NULL) { @@ -838,7 +837,7 @@ gdb_readline_no_editing_callback (gdb_client_data client_data) { /* Read from stdin if we are executing a user defined command. This is the right thing for prompt_for_continue, at least. */ - c = fgetc (ui->instream ? ui->instream : stdin); + c = fgetc (ui->instream != NULL ? ui->instream : ui->stdin_stream); if (c == EOF) { @@ -1086,7 +1085,7 @@ interruptible_select (int n, static void async_sigterm_handler (gdb_client_data arg) { - quit_force (NULL, stdin == current_ui->instream); + quit_force (NULL, 0); } /* See defs.h. */ |