aboutsummaryrefslogtreecommitdiff
path: root/gdb/mi/mi-main.c
diff options
context:
space:
mode:
authorPedro Alves <palves@redhat.com>2016-06-21 01:11:50 +0100
committerPedro Alves <palves@redhat.com>2016-06-21 01:11:50 +0100
commit9204d6922cb80f34dd799e57f7f0c74bc86e7027 (patch)
treee92eead4f49213d5637b2ed4dc10d33298fdeb74 /gdb/mi/mi-main.c
parent05beb2750cd51a0ae1e8bb429aacda567acceba4 (diff)
downloadgdb-9204d6922cb80f34dd799e57f7f0c74bc86e7027.zip
gdb-9204d6922cb80f34dd799e57f7f0c74bc86e7027.tar.gz
gdb-9204d6922cb80f34dd799e57f7f0c74bc86e7027.tar.bz2
Make raw_stdout be per MI instance
Each MI instance should obviously have its own raw output channel, along with save_raw_stdout. gdb/ChangeLog: 2016-06-21 Pedro Alves <palves@redhat.com> * interps.c (current_interpreter): New function. * interps.h (current_interpreter): New declaration. * mi/mi-cmds.h (raw_stdout): Delete declaration. * mi/mi-common.h (struct mi_interp) <raw_stdout, saved_raw_stdout>: New field. * mi/mi-interp.c (display_mi_prompt): New parameter 'mi'. Adjust to per-UI raw_stdout. (mi_interpreter_init): Adjust to per-UI raw_stdout. (mi_on_sync_execution_done, mi_execute_command_input_handler) (mi_command_loop): Pass MI instance to display_mi_prompt. (mi_on_normal_stop_1, mi_output_running_pid, mi_on_resume_1) (mi_on_resume): Adjust to per-UI raw_stdout. (saved_raw_stdout): Delete. (mi_set_logging): Adjust to per-UI raw_stdout and saved_raw_stdout. * mi/mi-main.c (raw_stdout): Delete. (mi_cmd_gdb_exit, captured_mi_execute_command) (mi_print_exception, mi_load_progress): Adjust to per-UI raw_stdout. (print_diff_now, mi_print_timing_maybe): New ui_file parameter. Pass it along. (print_diff): New ui_file parameter. Send output there instead of raw_stdout. * mi/mi-main.h (struct ui_file): Forward declare. (mi_print_timing_maybe): Add ui_file parameter.
Diffstat (limited to 'gdb/mi/mi-main.c')
-rw-r--r--gdb/mi/mi-main.c93
1 files changed, 51 insertions, 42 deletions
diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
index d53bcc7..8e51edc 100644
--- a/gdb/mi/mi-main.c
+++ b/gdb/mi/mi-main.c
@@ -72,8 +72,6 @@ enum
int mi_debug_p;
-struct ui_file *raw_stdout;
-
/* This is used to pass the current command timestamp down to
continuation routines. */
static struct mi_timestamp *current_command_ts;
@@ -149,18 +147,21 @@ mi_async_p (void)
static void timestamp (struct mi_timestamp *tv);
-static void print_diff_now (struct mi_timestamp *start);
-static void print_diff (struct mi_timestamp *start, struct mi_timestamp *end);
+static void print_diff (struct ui_file *file, struct mi_timestamp *start,
+ struct mi_timestamp *end);
void
mi_cmd_gdb_exit (char *command, char **argv, int argc)
{
+ struct mi_interp *mi
+ = (struct mi_interp *) interp_data (current_interpreter ());
+
/* We have to print everything right here because we never return. */
if (current_token)
- fputs_unfiltered (current_token, raw_stdout);
- fputs_unfiltered ("^exit\n", raw_stdout);
- mi_out_put (current_uiout, raw_stdout);
- gdb_flush (raw_stdout);
+ fputs_unfiltered (current_token, mi->raw_stdout);
+ fputs_unfiltered ("^exit\n", mi->raw_stdout);
+ mi_out_put (current_uiout, mi->raw_stdout);
+ gdb_flush (mi->raw_stdout);
/* FIXME: The function called is not yet a formal libgdb function. */
quit_force (NULL, FROM_TTY);
}
@@ -1983,6 +1984,7 @@ mi_cmd_remove_inferior (char *command, char **argv, int argc)
static void
captured_mi_execute_command (struct ui_out *uiout, struct mi_parse *context)
{
+ struct mi_interp *mi = (struct mi_interp *) interp_data (command_interp ());
struct cleanup *cleanup;
if (do_timings)
@@ -1999,7 +2001,8 @@ captured_mi_execute_command (struct ui_out *uiout, struct mi_parse *context)
/* A MI command was read from the input stream. */
if (mi_debug_p)
/* FIXME: gdb_???? */
- fprintf_unfiltered (raw_stdout, " token=`%s' command=`%s' args=`%s'\n",
+ fprintf_unfiltered (mi->raw_stdout,
+ " token=`%s' command=`%s' args=`%s'\n",
context->token, context->command, context->args);
mi_cmd_execute (context);
@@ -2012,15 +2015,15 @@ captured_mi_execute_command (struct ui_out *uiout, struct mi_parse *context)
uiout will most likely crash in the mi_out_* routines. */
if (!running_result_record_printed)
{
- fputs_unfiltered (context->token, raw_stdout);
+ fputs_unfiltered (context->token, mi->raw_stdout);
/* There's no particularly good reason why target-connect results
in not ^done. Should kill ^connected for MI3. */
fputs_unfiltered (strcmp (context->command, "target-select") == 0
- ? "^connected" : "^done", raw_stdout);
- mi_out_put (uiout, raw_stdout);
+ ? "^connected" : "^done", mi->raw_stdout);
+ mi_out_put (uiout, mi->raw_stdout);
mi_out_rewind (uiout);
- mi_print_timing_maybe ();
- fputs_unfiltered ("\n", raw_stdout);
+ mi_print_timing_maybe (mi->raw_stdout);
+ fputs_unfiltered ("\n", mi->raw_stdout);
}
else
/* The command does not want anything to be printed. In that
@@ -2051,12 +2054,12 @@ captured_mi_execute_command (struct ui_out *uiout, struct mi_parse *context)
{
if (!running_result_record_printed)
{
- fputs_unfiltered (context->token, raw_stdout);
- fputs_unfiltered ("^done", raw_stdout);
- mi_out_put (uiout, raw_stdout);
+ fputs_unfiltered (context->token, mi->raw_stdout);
+ fputs_unfiltered ("^done", mi->raw_stdout);
+ mi_out_put (uiout, mi->raw_stdout);
mi_out_rewind (uiout);
- mi_print_timing_maybe ();
- fputs_unfiltered ("\n", raw_stdout);
+ mi_print_timing_maybe (mi->raw_stdout);
+ fputs_unfiltered ("\n", mi->raw_stdout);
}
else
mi_out_rewind (uiout);
@@ -2073,22 +2076,25 @@ captured_mi_execute_command (struct ui_out *uiout, struct mi_parse *context)
static void
mi_print_exception (const char *token, struct gdb_exception exception)
{
- fputs_unfiltered (token, raw_stdout);
- fputs_unfiltered ("^error,msg=\"", raw_stdout);
+ struct mi_interp *mi
+ = (struct mi_interp *) interp_data (current_interpreter ());
+
+ fputs_unfiltered (token, mi->raw_stdout);
+ fputs_unfiltered ("^error,msg=\"", mi->raw_stdout);
if (exception.message == NULL)
- fputs_unfiltered ("unknown error", raw_stdout);
+ fputs_unfiltered ("unknown error", mi->raw_stdout);
else
- fputstr_unfiltered (exception.message, '"', raw_stdout);
- fputs_unfiltered ("\"", raw_stdout);
+ fputstr_unfiltered (exception.message, '"', mi->raw_stdout);
+ fputs_unfiltered ("\"", mi->raw_stdout);
switch (exception.error)
{
case UNDEFINED_COMMAND_ERROR:
- fputs_unfiltered (",code=\"undefined-command\"", raw_stdout);
+ fputs_unfiltered (",code=\"undefined-command\"", mi->raw_stdout);
break;
}
- fputs_unfiltered ("\n", raw_stdout);
+ fputs_unfiltered ("\n", mi->raw_stdout);
}
void
@@ -2358,6 +2364,8 @@ mi_load_progress (const char *section_name,
int new_section;
struct ui_out *saved_uiout;
struct ui_out *uiout;
+ struct mi_interp *mi
+ = (struct mi_interp *) interp_data (current_interpreter ());
/* This function is called through deprecated_show_load_progress
which means uiout may not be correct. Fix it for the duration
@@ -2399,16 +2407,16 @@ mi_load_progress (const char *section_name,
previous_sect_name = xstrdup (section_name);
if (current_token)
- fputs_unfiltered (current_token, raw_stdout);
- fputs_unfiltered ("+download", raw_stdout);
+ fputs_unfiltered (current_token, mi->raw_stdout);
+ fputs_unfiltered ("+download", mi->raw_stdout);
cleanup_tuple = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
ui_out_field_string (uiout, "section", section_name);
ui_out_field_int (uiout, "section-size", total_section);
ui_out_field_int (uiout, "total-size", grand_total);
do_cleanups (cleanup_tuple);
- mi_out_put (uiout, raw_stdout);
- fputs_unfiltered ("\n", raw_stdout);
- gdb_flush (raw_stdout);
+ mi_out_put (uiout, mi->raw_stdout);
+ fputs_unfiltered ("\n", mi->raw_stdout);
+ gdb_flush (mi->raw_stdout);
}
if (delta.tv_sec >= update_threshold.tv_sec &&
@@ -2419,8 +2427,8 @@ mi_load_progress (const char *section_name,
last_update.tv_sec = time_now.tv_sec;
last_update.tv_usec = time_now.tv_usec;
if (current_token)
- fputs_unfiltered (current_token, raw_stdout);
- fputs_unfiltered ("+download", raw_stdout);
+ fputs_unfiltered (current_token, mi->raw_stdout);
+ fputs_unfiltered ("+download", mi->raw_stdout);
cleanup_tuple = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
ui_out_field_string (uiout, "section", section_name);
ui_out_field_int (uiout, "section-sent", sent_so_far);
@@ -2428,9 +2436,9 @@ mi_load_progress (const char *section_name,
ui_out_field_int (uiout, "total-sent", total_sent);
ui_out_field_int (uiout, "total-size", grand_total);
do_cleanups (cleanup_tuple);
- mi_out_put (uiout, raw_stdout);
- fputs_unfiltered ("\n", raw_stdout);
- gdb_flush (raw_stdout);
+ mi_out_put (uiout, mi->raw_stdout);
+ fputs_unfiltered ("\n", mi->raw_stdout);
+ gdb_flush (mi->raw_stdout);
}
xfree (uiout);
@@ -2460,21 +2468,21 @@ timestamp (struct mi_timestamp *tv)
}
static void
-print_diff_now (struct mi_timestamp *start)
+print_diff_now (struct ui_file *file, struct mi_timestamp *start)
{
struct mi_timestamp now;
timestamp (&now);
- print_diff (start, &now);
+ print_diff (file, start, &now);
}
void
-mi_print_timing_maybe (void)
+mi_print_timing_maybe (struct ui_file *file)
{
/* If the command is -enable-timing then do_timings may be true
whilst current_command_ts is not initialized. */
if (do_timings && current_command_ts)
- print_diff_now (current_command_ts);
+ print_diff_now (file, current_command_ts);
}
static long
@@ -2485,10 +2493,11 @@ timeval_diff (struct timeval start, struct timeval end)
}
static void
-print_diff (struct mi_timestamp *start, struct mi_timestamp *end)
+print_diff (struct ui_file *file, struct mi_timestamp *start,
+ struct mi_timestamp *end)
{
fprintf_unfiltered
- (raw_stdout,
+ (file,
",time={wallclock=\"%0.5f\",user=\"%0.5f\",system=\"%0.5f\"}",
timeval_diff (start->wallclock, end->wallclock) / 1000000.0,
timeval_diff (start->utime, end->utime) / 1000000.0,