+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.
+
2016-06-21 Pedro Alves <palves@redhat.com>
* mi/mi-interp.c (display_mi_prompt): New function.
return interp->data;
}
+/* See interps.h. */
+
+struct interp *
+current_interpreter (void)
+{
+ struct ui_interp_info *ui_interp = get_interp_info (current_ui);
+
+ return ui_interp->current_interpreter;
+}
+
/* This just adds the "interpreter-exec" command. */
void
_initialize_interpreter (void)
extern void *top_level_interpreter_data (void);
extern struct interp *top_level_interpreter (void);
+/* Return the current UI's current interpreter. */
+extern struct interp *current_interpreter (void);
+
extern struct interp *command_interp (void);
extern void clear_interpreter_hooks (void);
/* Debug flag */
extern int mi_debug_p;
-/* Raw console output - FIXME: should this be a parameter? */
-extern struct ui_file *raw_stdout;
-
extern void mi_execute_command (const char *cmd, int from_tty);
#endif
struct ui_file *targ;
struct ui_file *event_channel;
+ /* Raw console output. */
+ struct ui_file *raw_stdout;
+
+ /* Save the original value of raw_stdout here when logging, so we
+ can restore correctly when done. */
+ struct ui_file *saved_raw_stdout;
+
/* MI's builder. */
struct ui_out *mi_uiout;
/* Display the MI prompt. */
static void
-display_mi_prompt (void)
+display_mi_prompt (struct mi_interp *mi)
{
- fputs_unfiltered ("(gdb) \n", raw_stdout);
- gdb_flush (raw_stdout);
+ fputs_unfiltered ("(gdb) \n", mi->raw_stdout);
+ gdb_flush (mi->raw_stdout);
}
/* Returns the INTERP's data cast as mi_interp if INTERP is an MI, and
const char *name;
int mi_version;
- /* Assign the output channel created at startup to its own global,
- so that we can create a console channel that encapsulates and
- prefixes all gdb_output-type bits coming from the rest of the
- debugger. */
-
- raw_stdout = gdb_stdout;
+ /* Store the current output channel, so that we can create a console
+ channel that encapsulates and prefixes all gdb_output-type bits
+ coming from the rest of the debugger. */
+ mi->raw_stdout = gdb_stdout;
/* Create MI console channels, each with a different prefix so they
can be distinguished. */
- mi->out = mi_console_file_new (raw_stdout, "~", '"');
- mi->err = mi_console_file_new (raw_stdout, "&", '"');
+ mi->out = mi_console_file_new (mi->raw_stdout, "~", '"');
+ mi->err = mi_console_file_new (mi->raw_stdout, "&", '"');
mi->log = mi->err;
- mi->targ = mi_console_file_new (raw_stdout, "@", '"');
- mi->event_channel = mi_console_file_new (raw_stdout, "=", 0);
+ mi->targ = mi_console_file_new (mi->raw_stdout, "@", '"');
+ mi->event_channel = mi_console_file_new (mi->raw_stdout, "=", 0);
name = interp_name (interp);
/* INTERP_MI selects the most recent released version. "mi2" was
/* If MI is sync, then output the MI prompt now, indicating we're
ready for further input. */
if (!mi_async_p ())
- display_mi_prompt ();
+ display_mi_prompt (mi);
}
/* mi_execute_command_wrapper wrapper suitable for INPUT_HANDLER. */
static void
mi_execute_command_input_handler (char *cmd)
{
+ struct mi_interp *mi = as_mi_interp (top_level_interpreter ());
+
mi_execute_command_wrapper (cmd);
/* Print a prompt, indicating we're ready for further input, unless
'synchronous_command_done' observer when the target next
stops. */
if (!sync_execution)
- display_mi_prompt ();
+ display_mi_prompt (mi);
}
static void
mi_command_loop (void *data)
{
+ struct mi_interp *mi = (struct mi_interp *) data;
+
/* Turn off 8 bit strings in quoted output. Any character with the
high bit set is printed using C's octal format. */
sevenbit_strings = 1;
/* Tell the world that we're alive. */
- display_mi_prompt ();
+ display_mi_prompt (mi);
start_event_loop ();
}
using cli interpreter, be sure to use MI uiout for output,
not the current one. */
struct ui_out *mi_uiout = interp_ui_out (top_level_interpreter ());
+ struct mi_interp *mi = (struct mi_interp *) top_level_interpreter_data ();
if (print_frame)
{
&& thread_fsm_finished_p (tp->thread_fsm))
|| (tp->control.command_interp != NULL
&& tp->control.command_interp != top_level_interpreter ()))
- {
- struct mi_interp *mi
- = (struct mi_interp *) top_level_interpreter_data ();
-
- print_stop_event (mi->cli_uiout);
- }
+ print_stop_event (mi->cli_uiout);
tp = inferior_thread ();
ui_out_field_int (mi_uiout, "thread-id", tp->global_num);
ui_out_field_int (mi_uiout, "core", core);
}
- fputs_unfiltered ("*stopped", raw_stdout);
- mi_out_put (mi_uiout, raw_stdout);
+ fputs_unfiltered ("*stopped", mi->raw_stdout);
+ mi_out_put (mi_uiout, mi->raw_stdout);
mi_out_rewind (mi_uiout);
- mi_print_timing_maybe ();
- fputs_unfiltered ("\n", raw_stdout);
- gdb_flush (raw_stdout);
+ mi_print_timing_maybe (mi->raw_stdout);
+ fputs_unfiltered ("\n", mi->raw_stdout);
+ gdb_flush (mi->raw_stdout);
}
static void
continue;
if (ptid_get_pid (*ptid) == ptid_get_pid (info->ptid))
- fprintf_unfiltered (raw_stdout,
+ fprintf_unfiltered (mi->raw_stdout,
"*running,thread-id=\"%d\"\n",
info->global_num);
}
}
static void
-mi_on_resume_1 (ptid_t ptid)
+mi_on_resume_1 (struct mi_interp *mi, ptid_t ptid)
{
/* To cater for older frontends, emit ^running, but do it only once
per each command. We do it here, since at this point we know
In future (MI3), we'll be outputting "^done" here. */
if (!running_result_record_printed && mi_proceeded)
{
- fprintf_unfiltered (raw_stdout, "%s^running\n",
+ fprintf_unfiltered (mi->raw_stdout, "%s^running\n",
current_token ? current_token : "");
}
if (ptid_get_pid (ptid) == -1)
- fprintf_unfiltered (raw_stdout, "*running,thread-id=\"all\"\n");
+ fprintf_unfiltered (mi->raw_stdout, "*running,thread-id=\"all\"\n");
else if (ptid_is_pid (ptid))
{
int count = 0;
iterate_over_inferiors (mi_inferior_count, &count);
if (count == 1)
- fprintf_unfiltered (raw_stdout, "*running,thread-id=\"all\"\n");
+ fprintf_unfiltered (mi->raw_stdout, "*running,thread-id=\"all\"\n");
else
iterate_over_threads (mi_output_running_pid, &ptid);
}
struct thread_info *ti = find_thread_ptid (ptid);
gdb_assert (ti);
- fprintf_unfiltered (raw_stdout, "*running,thread-id=\"%d\"\n",
+ fprintf_unfiltered (mi->raw_stdout, "*running,thread-id=\"%d\"\n",
ti->global_num);
}
checked here because we only need to emit a prompt if a
synchronous command was issued when the target is async. */
if (!target_can_async_p () || sync_execution)
- fputs_unfiltered ("(gdb) \n", raw_stdout);
+ fputs_unfiltered ("(gdb) \n", mi->raw_stdout);
}
- gdb_flush (raw_stdout);
+ gdb_flush (mi->raw_stdout);
}
static void
old_chain = make_cleanup_restore_target_terminal ();
target_terminal_ours_for_output ();
- mi_on_resume_1 (ptid);
+ mi_on_resume_1 (mi, ptid);
do_cleanups (old_chain);
}
return mi->mi_uiout;
}
-/* Save the original value of raw_stdout here when logging, so we can
- restore correctly when done. */
-
-static struct ui_file *saved_raw_stdout;
-
/* Do MI-specific logging actions; save raw_stdout, and change all
the consoles to use the supplied ui-file(s). */
if (logfile)
{
ui_file_delete (out);
- out = tee_file_new (raw_stdout, 0, logfile, 0);
+ out = tee_file_new (mi->raw_stdout, 0, logfile, 0);
}
- saved_raw_stdout = raw_stdout;
- raw_stdout = out;
+ mi->saved_raw_stdout = mi->raw_stdout;
+ mi->raw_stdout = out;
}
else
{
- raw_stdout = saved_raw_stdout;
- saved_raw_stdout = NULL;
+ mi->raw_stdout = mi->saved_raw_stdout;
+ mi->saved_raw_stdout = NULL;
}
- mi_console_set_raw (mi->out, raw_stdout);
- mi_console_set_raw (mi->err, raw_stdout);
- mi_console_set_raw (mi->log, raw_stdout);
- mi_console_set_raw (mi->targ, raw_stdout);
- mi_console_set_raw (mi->event_channel, raw_stdout);
+ mi_console_set_raw (mi->out, mi->raw_stdout);
+ mi_console_set_raw (mi->err, mi->raw_stdout);
+ mi_console_set_raw (mi->log, mi->raw_stdout);
+ mi_console_set_raw (mi->targ, mi->raw_stdout);
+ mi_console_set_raw (mi->event_channel, mi->raw_stdout);
return 1;
}
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;
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);
}
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)
/* 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);
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
{
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);
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
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
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 &&
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);
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);
}
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
}
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,
#ifndef MI_MAIN_H
#define MI_MAIN_H
+struct ui_file;
+
extern void mi_load_progress (const char *section_name,
unsigned long sent_so_far,
unsigned long total_section,
unsigned long total_sent,
unsigned long grand_total);
-extern void mi_print_timing_maybe (void);
+extern void mi_print_timing_maybe (struct ui_file *file);
/* Whether MI is in async mode. */