This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[PATCH v3 09/34] Make instream be per UI
- From: Pedro Alves <palves at redhat dot com>
- To: gdb-patches at sourceware dot org
- Date: Fri, 6 May 2016 13:34:39 +0100
- Subject: [PATCH v3 09/34] Make instream be per UI
- Authentication-results: sourceware.org; auth=none
- References: <1462538104-19109-1-git-send-email-palves at redhat dot com>
gdb/ChangeLog:
yyyy-mm-dd Pedro Alves <palves@redhat.com>
* cli/cli-script.c (execute_user_command, read_next_line)
(read_next_line): Adjust to per-UI instream.
* event-top.c (stdin_event_handler, command_handler)
(handle_line_of_input, command_line_handler)
(gdb_readline_no_editing_callback, async_sigterm_handler)
(gdb_setup_readline): Likewise.
* inflow.c: Include top.h.
(gdb_has_a_terminal, child_terminal_init_with_pgrp)
(gdb_save_tty_state, child_terminal_inferior)
(child_terminal_ours_1, copy_terminal_info): Use the main UI.
(initialize_stdin_serial): Adjust to per-UI instream.
* main.c (captured_command_loop, captured_main): Adjust to per-UI
instream.
* mi/mi-interp.c (mi_execute_command_wrapper): Likewise.
* python/python.c (python_interactive_command): Likewise.
* terminal.h (struct ui): Forward declare.
(initialize_stdin_serial): Add struct ui parameter.
* top.c (instream): Delete.
(do_restore_instream_cleanup, read_command_file, dont_repeat)
(gdb_readline_no_editing, command_line_input)
(input_from_terminal_p, gdb_init): Adjust to per-UI instream.
* top.h (struct ui) <instream>: New field.
(instream): Delete declaration.
(quit): Adjust to per-UI instream.
gdb/testsuite/ChangeLog:
yyyy-mm-dd Pedro Alves <palves@redhat.com>
* gdb.gdb/selftest.exp (do_steps_and_nexts): Add new regexp.
---
gdb/cli/cli-script.c | 11 +++++++----
gdb/event-top.c | 34 +++++++++++++++++++---------------
gdb/main.c | 7 +++++--
gdb/mi/mi-interp.c | 4 +++-
gdb/python/python.c | 3 ++-
gdb/testsuite/gdb.gdb/selftest.exp | 4 ++++
gdb/top.c | 36 +++++++++++++++++++-----------------
gdb/top.h | 7 ++++++-
gdb/utils.c | 4 +++-
9 files changed, 68 insertions(+), 42 deletions(-)
diff --git a/gdb/cli/cli-script.c b/gdb/cli/cli-script.c
index 5fc01b3..0507c55 100644
--- a/gdb/cli/cli-script.c
+++ b/gdb/cli/cli-script.c
@@ -352,6 +352,7 @@ do_restore_user_call_depth (void * call_depth)
void
execute_user_command (struct cmd_list_element *c, char *args)
{
+ struct ui *ui = current_ui;
struct command_line *cmdlines;
struct cleanup *old_chain;
enum command_control_type ret;
@@ -372,8 +373,8 @@ execute_user_command (struct cmd_list_element *c, char *args)
/* Set the instream to 0, indicating execution of a
user-defined function. */
- make_cleanup (do_restore_instream_cleanup, instream);
- instream = (FILE *) 0;
+ make_cleanup (do_restore_instream_cleanup, ui->instream);
+ ui->instream = NULL;
/* Also set the global in_user_command, so that NULL instream is
not confused with Insight. */
@@ -931,6 +932,7 @@ realloc_body_list (struct command_line *command, int new_length)
static char *
read_next_line (void)
{
+ struct ui *ui = current_ui;
char *prompt_ptr, control_prompt[256];
int i = 0;
@@ -938,7 +940,8 @@ read_next_line (void)
error (_("Control nesting too deep!"));
/* Set a prompt based on the nesting of the control commands. */
- if (instream == stdin || (instream == 0 && deprecated_readline_hook != NULL))
+ if (ui->instream == stdin
+ || (ui->instream == 0 && deprecated_readline_hook != NULL))
{
for (i = 0; i < control_level; i++)
control_prompt[i] = ' ';
@@ -949,7 +952,7 @@ read_next_line (void)
else
prompt_ptr = NULL;
- return command_line_input (prompt_ptr, instream == stdin, "commands");
+ return command_line_input (prompt_ptr, ui->instream == stdin, "commands");
}
/* Process one input line. If the command is an "end", return such an
diff --git a/gdb/event-top.c b/gdb/event-top.c
index 63f6896..3e2f778 100644
--- a/gdb/event-top.c
+++ b/gdb/event-top.c
@@ -510,7 +510,7 @@ stdin_event_handler (int error, gdb_client_data client_data)
printf_unfiltered (_("error detected on stdin\n"));
delete_file_handler (input_fd);
/* If stdin died, we may as well kill gdb. */
- quit_command ((char *) 0, stdin == instream);
+ quit_command ((char *) 0, stdin == ui->instream);
}
else
{
@@ -566,10 +566,11 @@ async_disable_stdin (void)
void
command_handler (char *command)
{
+ struct ui *ui = current_ui;
struct cleanup *stat_chain;
char *c;
- if (instream == stdin)
+ if (ui->instream == stdin)
reinitialize_more_filter ();
stat_chain = make_command_stats_cleanup (1);
@@ -579,7 +580,7 @@ command_handler (char *command)
;
if (c[0] != '#')
{
- execute_command (command, instream == stdin);
+ execute_command (command, ui->instream == stdin);
/* Do any commands attached to breakpoint we stopped at. */
bpstat_do_actions ();
@@ -646,6 +647,7 @@ char *
handle_line_of_input (struct buffer *cmd_line_buffer,
char *rl, int repeat, char *annotation_suffix)
{
+ struct ui *ui = current_ui;
char *p1;
char *cmd;
@@ -660,7 +662,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 && instream == stdin)
+ if (annotation_level > 1 && ui->instream == stdin)
{
printf_unfiltered (("\n\032\032post-"));
puts_unfiltered (annotation_suffix);
@@ -677,8 +679,8 @@ handle_line_of_input (struct buffer *cmd_line_buffer,
}
/* Do history expansion if that is wished. */
- if (history_expansion_p && instream == stdin
- && ISATTY (instream))
+ if (history_expansion_p && ui->instream == stdin
+ && ISATTY (ui->instream))
{
char *history_value;
int expanded;
@@ -748,9 +750,11 @@ void
command_line_handler (char *rl)
{
struct buffer *line_buffer = get_command_line_buffer ();
+ struct ui *ui = current_ui;
char *cmd;
- cmd = handle_line_of_input (line_buffer, rl, instream == stdin, "prompt");
+ cmd = handle_line_of_input (line_buffer, rl, ui->instream == stdin,
+ "prompt");
if (cmd == (char *) EOF)
{
/* stdin closed. The connection with the terminal is gone.
@@ -758,7 +762,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 == instream);
+ execute_command ("quit", stdin == ui->instream);
}
else if (cmd == NULL)
{
@@ -793,9 +797,9 @@ gdb_readline_no_editing_callback (gdb_client_data client_data)
stream after '\n'. If we buffer the input and fgetc drains the
stream, getting stuff beyond the newline as well, a select, done
afterwards will not trigger. */
- if (!done_once && !ISATTY (instream))
+ if (!done_once && !ISATTY (ui->instream))
{
- setbuf (instream, NULL);
+ setbuf (ui->instream, NULL);
done_once = 1;
}
@@ -811,7 +815,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 (instream ? instream : stdin);
+ c = fgetc (ui->instream ? ui->instream : stdin);
if (c == EOF)
{
@@ -1059,7 +1063,7 @@ interruptible_select (int n,
static void
async_sigterm_handler (gdb_client_data arg)
{
- quit_force (NULL, stdin == instream);
+ quit_force (NULL, stdin == current_ui->instream);
}
/* See defs.h. */
@@ -1241,7 +1245,7 @@ gdb_setup_readline (void)
/* If the input stream is connected to a terminal, turn on
editing. */
- if (ISATTY (instream))
+ if (ISATTY (ui->instream))
{
/* Tell gdb that we will be using the readline library. This
could be overwritten by a command in .gdbinit like 'set
@@ -1264,11 +1268,11 @@ gdb_setup_readline (void)
ui->input_handler = command_line_handler;
/* Tell readline to use the same input stream that gdb uses. */
- rl_instream = instream;
+ rl_instream = ui->instream;
/* Get a file descriptor for the input stream, so that we can
register it with the event loop. */
- input_fd = fileno (instream);
+ input_fd = fileno (ui->instream);
/* Now we need to create the event sources for the input file
descriptor. */
diff --git a/gdb/main.c b/gdb/main.c
index d84340e..7d7b52a 100644
--- a/gdb/main.c
+++ b/gdb/main.c
@@ -309,6 +309,8 @@ setup_alternate_signal_stack (void)
static int
captured_command_loop (void *data)
{
+ struct ui *ui = current_ui;
+
/* Top-level execution commands can be run in the background from
here on. */
current_ui->async = 1;
@@ -326,7 +328,7 @@ captured_command_loop (void *data)
error) we try to quit. If the quit is aborted, catch_errors()
which called this catch the signal and restart the command
loop. */
- quit_command (NULL, instream == stdin);
+ quit_command (NULL, ui->instream == stdin);
return 1;
}
@@ -435,6 +437,7 @@ DEF_VEC_O (cmdarg_s);
static int
captured_main (void *data)
{
+ struct ui *ui = current_ui;
struct captured_main_args *context = (struct captured_main_args *) data;
int argc = context->argc;
char **argv = context->argv;
@@ -504,7 +507,7 @@ captured_main (void *data)
ndir = 0;
saved_command_line = (char *) xstrdup ("");
- instream = stdin;
+ ui->instream = stdin;
#ifdef __MINGW32__
/* Ensure stderr is unbuffered. A Cygwin pty or pipe is implemented
diff --git a/gdb/mi/mi-interp.c b/gdb/mi/mi-interp.c
index f9820cb..22250d9 100644
--- a/gdb/mi/mi-interp.c
+++ b/gdb/mi/mi-interp.c
@@ -283,7 +283,9 @@ mi_interp_query_hook (const char *ctlstr, va_list ap)
static void
mi_execute_command_wrapper (const char *cmd)
{
- mi_execute_command (cmd, stdin == instream);
+ struct ui *ui = current_ui;
+
+ mi_execute_command (cmd, stdin == ui->instream);
}
/* Observer for the synchronous_command_done notification. */
diff --git a/gdb/python/python.c b/gdb/python/python.c
index fa1c78e..06fd468 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -318,6 +318,7 @@ eval_python_command (const char *command)
static void
python_interactive_command (char *arg, int from_tty)
{
+ struct ui *ui = current_ui;
struct cleanup *cleanup;
int err;
@@ -341,7 +342,7 @@ python_interactive_command (char *arg, int from_tty)
}
else
{
- err = PyRun_InteractiveLoop (instream, "<stdin>");
+ err = PyRun_InteractiveLoop (ui->instream, "<stdin>");
dont_repeat ();
}
diff --git a/gdb/testsuite/gdb.gdb/selftest.exp b/gdb/testsuite/gdb.gdb/selftest.exp
index 969797a..af0026c 100644
--- a/gdb/testsuite/gdb.gdb/selftest.exp
+++ b/gdb/testsuite/gdb.gdb/selftest.exp
@@ -205,6 +205,10 @@ proc do_steps_and_nexts {} {
set description "step over gdb_stderr initialization"
set command "step"
}
+ -re "ui = current_ui.*$gdb_prompt $" {
+ set description "step over top_level initialization"
+ set command "step"
+ }
-re ".*main.c.*No such file or directory.*$gdb_prompt $" {
setup_xfail "rs6000-*-aix3*"
fail "must be able to list source lines"
diff --git a/gdb/top.c b/gdb/top.c
index 3842f0c..733580f 100644
--- a/gdb/top.c
+++ b/gdb/top.c
@@ -123,13 +123,6 @@ show_confirm (struct ui_file *file, int from_tty,
value);
}
-/* stdio stream that command input is being read from. Set to stdin
- normally. Set by source_command to the file we are sourcing. Set
- to NULL if we are executing a user-defined command or interacting
- via a GUI. */
-
-FILE *instream;
-
/* Flag to indicate whether a user defined command is currently running. */
int in_user_command;
@@ -286,23 +279,26 @@ quit_cover (void)
void
do_restore_instream_cleanup (void *stream)
{
+ struct ui *ui = current_ui;
+
/* Restore the previous input stream. */
- instream = (FILE *) stream;
+ ui->instream = (FILE *) stream;
}
/* Read commands from STREAM. */
void
read_command_file (FILE *stream)
{
+ struct ui *ui = current_ui;
struct cleanup *cleanups;
- cleanups = make_cleanup (do_restore_instream_cleanup, instream);
- instream = stream;
+ cleanups = make_cleanup (do_restore_instream_cleanup, ui->instream);
+ ui->instream = stream;
/* Read commands from `instream' and execute them until end of file
or error reading instream. */
- while (instream != NULL && !feof (instream))
+ while (ui->instream != NULL && !feof (ui->instream))
{
char *command;
@@ -568,13 +564,15 @@ static int suppress_dont_repeat = 0;
void
dont_repeat (void)
{
+ struct ui *ui = current_ui;
+
if (suppress_dont_repeat || server_command)
return;
/* If we aren't reading from standard input, we are saving the last
thing read from stdin in line and don't want to delete it. Null
lines won't repeat here in any case. */
- if (instream == stdin)
+ if (ui->instream == stdin)
*saved_command_line = 0;
}
@@ -603,9 +601,10 @@ static char *
gdb_readline_no_editing (const char *prompt)
{
struct buffer line_buffer;
+ struct ui *ui = current_ui;
/* Read from stdin if we are executing a user defined command. This
is the right thing for prompt_for_continue, at least. */
- FILE *stream = instream != NULL ? instream : stdin;
+ FILE *stream = ui->instream != NULL ? ui->instream : stdin;
int fd = fileno (stream);
buffer_init (&line_buffer);
@@ -1047,6 +1046,7 @@ command_line_input (const char *prompt_arg, int repeat, char *annotation_suffix)
{
static struct buffer cmd_line_buffer;
static int cmd_line_buffer_initialized;
+ struct ui *ui = current_ui;
const char *prompt = prompt_arg;
char *cmd;
@@ -1054,7 +1054,7 @@ command_line_input (const char *prompt_arg, int repeat, char *annotation_suffix)
if (annotation_suffix == NULL)
annotation_suffix = "";
- if (annotation_level > 1 && instream == stdin)
+ if (annotation_level > 1 && ui->instream == stdin)
{
char *local_prompt;
@@ -1100,7 +1100,7 @@ command_line_input (const char *prompt_arg, int repeat, char *annotation_suffix)
if (source_file_name != NULL)
++source_line_number;
- if (annotation_level > 1 && instream == stdin)
+ if (annotation_level > 1 && ui->instream == stdin)
{
puts_unfiltered ("\n\032\032pre-");
puts_unfiltered (annotation_suffix);
@@ -1511,16 +1511,18 @@ quit_force (char *args, int from_tty)
int
input_from_terminal_p (void)
{
+ struct ui *ui = current_ui;
+
if (batch_flag)
return 0;
- if (gdb_has_a_terminal () && instream == stdin)
+ if (gdb_has_a_terminal () && ui->instream == stdin)
return 1;
/* If INSTREAM is unset, and we are not in a user command, we
must be in Insight. That's like having a terminal, for our
purposes. */
- if (instream == NULL && !in_user_command)
+ if (ui->instream == NULL && !in_user_command)
return 1;
return 0;
diff --git a/gdb/top.h b/gdb/top.h
index 8f01f78..bb84097 100644
--- a/gdb/top.h
+++ b/gdb/top.h
@@ -68,6 +68,12 @@ struct ui
"start" -ex "next"') are processed. */
int async;
+ /* stdio stream that command input is being read from. Set to stdin
+ normally. Set by source_command to the file we are sourcing.
+ Set to NULL if we are executing a user-defined command or
+ interacting via a GUI. */
+ FILE *instream;
+
/* The fields below that start with "m_" are "private". They're
meant to be accessed through wrapper macros that make them look
like globals. */
@@ -121,7 +127,6 @@ extern void switch_thru_all_uis_next (struct switch_thru_all_uis *state);
/* From top.c. */
extern char *saved_command_line;
-extern FILE *instream;
extern int in_user_command;
extern int confirm;
extern char gdb_dirbuf[1024];
diff --git a/gdb/utils.c b/gdb/utils.c
index db5104d..78d2e98 100644
--- a/gdb/utils.c
+++ b/gdb/utils.c
@@ -1047,10 +1047,12 @@ print_sys_errmsg (const char *string, int errcode)
void
quit (void)
{
+ struct ui *ui = current_ui;
+
if (sync_quit_force_run)
{
sync_quit_force_run = 0;
- quit_force (NULL, stdin == instream);
+ quit_force (NULL, stdin == ui->instream);
}
#ifdef __MSDOS__
--
2.5.5