1 /* MI Interpreter Definitions and Commands for GDB, the GNU debugger.
3 Copyright (C) 2002-2024 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
22 #include "mi-interp.h"
25 #include "event-top.h"
26 #include "gdbsupport/event-loop.h"
34 #include "mi-console.h"
35 #include "mi-common.h"
36 #include "observable.h"
37 #include "gdbthread.h"
40 #include "tracepoint.h"
42 #include "thread-fsm.h"
43 #include "cli/cli-interp.h"
44 #include "gdbsupport/scope-exit.h"
46 /* These are the interpreter setup, etc. functions for the MI
49 static void mi_execute_command_wrapper (const char *cmd
);
50 static void mi_execute_command_input_handler
51 (gdb::unique_xmalloc_ptr
<char> &&cmd
);
53 /* These are hooks that we put in place while doing interpreter_exec
54 so we can report interesting things that happened "behind the MI's
55 back" in this command. */
57 static int mi_interp_query_hook (const char *ctlstr
, va_list ap
)
58 ATTRIBUTE_PRINTF (1, 0);
60 static void mi_insert_notify_hooks (void);
61 static void mi_remove_notify_hooks (void);
63 /* Display the MI prompt. */
66 display_mi_prompt (struct mi_interp
*mi
)
68 struct ui
*ui
= current_ui
;
70 gdb_puts ("(gdb) \n", mi
->raw_stdout
);
71 gdb_flush (mi
->raw_stdout
);
72 ui
->prompt_state
= PROMPTED
;
76 mi_interp::on_command_error ()
78 display_mi_prompt (this);
82 mi_interp::init (bool top_level
)
86 /* Store the current output channel, so that we can create a console
87 channel that encapsulates and prefixes all gdb_output-type bits
88 coming from the rest of the debugger. */
89 mi
->raw_stdout
= gdb_stdout
;
91 /* Create MI console channels, each with a different prefix so they
92 can be distinguished. */
93 mi
->out
= new mi_console_file (mi
->raw_stdout
, "~", '"');
94 mi
->err
= new mi_console_file (mi
->raw_stdout
, "&", '"');
96 mi
->targ
= new mi_console_file (mi
->raw_stdout
, "@", '"');
97 mi
->event_channel
= new mi_console_file (mi
->raw_stdout
, "=", 0);
98 mi
->mi_uiout
= mi_out_new (name ()).release ();
99 gdb_assert (mi
->mi_uiout
!= nullptr);
100 mi
->cli_uiout
= new cli_ui_out (mi
->out
);
104 /* The initial inferior is created before this function is called, so we
105 need to report it explicitly when initializing the top-level MI
108 This is also called when additional MI interpreters are added (using
109 the new-ui command), when multiple inferiors possibly exist, so we need
110 to use iteration to report all the inferiors. */
112 for (inferior
*inf
: all_inferiors ())
113 mi
->on_inferior_added (inf
);
120 struct mi_interp
*mi
= this;
121 struct ui
*ui
= current_ui
;
123 /* As per hack note in mi_interpreter_init, swap in the output
125 gdb_setup_readline (0);
127 ui
->call_readline
= gdb_readline_no_editing_callback
;
128 ui
->input_handler
= mi_execute_command_input_handler
;
130 gdb_stdout
= mi
->out
;
131 /* Route error and log output through the MI. */
132 gdb_stderr
= mi
->err
;
133 gdb_stdlog
= mi
->log
;
134 /* Route target output through the MI. */
135 gdb_stdtarg
= mi
->targ
;
136 /* Route target error through the MI as well. */
137 gdb_stdtargerr
= mi
->targ
;
139 deprecated_show_load_progress
= mi_load_progress
;
143 mi_interp::suspend ()
145 gdb_disable_readline ();
149 mi_interp::exec (const char *command
)
151 mi_execute_command_wrapper (command
);
155 mi_cmd_interpreter_exec (const char *command
, const char *const *argv
,
158 struct interp
*interp_to_use
;
162 error (_("-interpreter-exec: "
163 "Usage: -interpreter-exec interp command"));
165 interp_to_use
= interp_lookup (current_ui
, argv
[0]);
166 if (interp_to_use
== NULL
)
167 error (_("-interpreter-exec: could not find interpreter \"%s\""),
170 /* Note that unlike the CLI version of this command, we don't
171 actually set INTERP_TO_USE as the current interpreter, as we
172 still want gdb_stdout, etc. to point at MI streams. */
174 /* Insert the MI out hooks, making sure to also call the
175 interpreter's hooks if it has any. */
176 /* KRS: We shouldn't need this... Events should be installed and
177 they should just ALWAYS fire something out down the MI
179 mi_insert_notify_hooks ();
181 /* Now run the code. */
185 mi_remove_notify_hooks ();
188 for (i
= 1; i
< argc
; i
++)
189 interp_exec (interp_to_use
, argv
[i
]);
192 /* This inserts a number of hooks that are meant to produce
193 async-notify ("=") MI messages while running commands in another
194 interpreter using mi_interpreter_exec. The canonical use for this
195 is to allow access to the gdb CLI interpreter from within the MI,
196 while still producing MI style output when actions in the CLI
197 command change GDB's state. */
200 mi_insert_notify_hooks (void)
202 deprecated_query_hook
= mi_interp_query_hook
;
206 mi_remove_notify_hooks (void)
208 deprecated_query_hook
= NULL
;
212 mi_interp_query_hook (const char *ctlstr
, va_list ap
)
218 mi_execute_command_wrapper (const char *cmd
)
220 struct ui
*ui
= current_ui
;
222 mi_execute_command (cmd
, ui
->instream
== ui
->stdin_stream
);
226 mi_interp::on_sync_execution_done ()
228 /* If MI is sync, then output the MI prompt now, indicating we're
229 ready for further input. */
231 display_mi_prompt (this);
234 /* mi_execute_command_wrapper wrapper suitable for INPUT_HANDLER. */
237 mi_execute_command_input_handler (gdb::unique_xmalloc_ptr
<char> &&cmd
)
239 struct mi_interp
*mi
= as_mi_interp (top_level_interpreter ());
240 struct ui
*ui
= current_ui
;
242 ui
->prompt_state
= PROMPT_NEEDED
;
244 mi_execute_command_wrapper (cmd
.get ());
246 /* Print a prompt, indicating we're ready for further input, unless
247 we just started a synchronous command. In that case, we're about
248 to go back to the event loop and will output the prompt in the
249 'synchronous_command_done' observer when the target next
251 if (ui
->prompt_state
== PROMPT_NEEDED
)
252 display_mi_prompt (mi
);
256 mi_interp::pre_command_loop ()
258 struct mi_interp
*mi
= this;
260 /* Turn off 8 bit strings in quoted output. Any character with the
261 high bit set is printed using C's octal format. */
262 sevenbit_strings
= 1;
264 /* Tell the world that we're alive. */
265 display_mi_prompt (mi
);
269 mi_interp::on_new_thread (thread_info
*t
)
271 target_terminal::scoped_restore_terminal_state term_state
;
272 target_terminal::ours_for_output ();
274 gdb_printf (this->event_channel
, "thread-created,id=\"%d\",group-id=\"i%d\"",
275 t
->global_num
, t
->inf
->num
);
276 gdb_flush (this->event_channel
);
280 mi_interp::on_thread_exited (thread_info
*t
,
281 std::optional
<ULONGEST
> /* exit_code */,
284 target_terminal::scoped_restore_terminal_state term_state
;
285 target_terminal::ours_for_output ();
286 gdb_printf (this->event_channel
, "thread-exited,id=\"%d\",group-id=\"i%d\"",
287 t
->global_num
, t
->inf
->num
);
288 gdb_flush (this->event_channel
);
292 mi_interp::on_record_changed (inferior
*inferior
, int started
,
293 const char *method
, const char *format
)
295 target_terminal::scoped_restore_terminal_state term_state
;
296 target_terminal::ours_for_output ();
301 gdb_printf (this->event_channel
,
302 "record-started,thread-group=\"i%d\","
303 "method=\"%s\",format=\"%s\"",
304 inferior
->num
, method
, format
);
306 gdb_printf (this->event_channel
,
307 "record-started,thread-group=\"i%d\","
309 inferior
->num
, method
);
312 gdb_printf (this->event_channel
,
313 "record-stopped,thread-group=\"i%d\"",
316 gdb_flush (this->event_channel
);
320 mi_interp::on_inferior_added (inferior
*inf
)
322 target_terminal::scoped_restore_terminal_state term_state
;
323 target_terminal::ours_for_output ();
325 gdb_printf (this->event_channel
, "thread-group-added,id=\"i%d\"", inf
->num
);
326 gdb_flush (this->event_channel
);
330 mi_interp::on_inferior_appeared (inferior
*inf
)
332 target_terminal::scoped_restore_terminal_state term_state
;
333 target_terminal::ours_for_output ();
335 gdb_printf (this->event_channel
, "thread-group-started,id=\"i%d\",pid=\"%d\"",
337 gdb_flush (this->event_channel
);
341 mi_interp::on_inferior_disappeared (inferior
*inf
)
343 target_terminal::scoped_restore_terminal_state term_state
;
344 target_terminal::ours_for_output ();
346 if (inf
->has_exit_code
)
347 gdb_printf (this->event_channel
,
348 "thread-group-exited,id=\"i%d\",exit-code=\"%s\"",
349 inf
->num
, int_string (inf
->exit_code
, 8, 0, 0, 1));
351 gdb_printf (this->event_channel
,
352 "thread-group-exited,id=\"i%d\"", inf
->num
);
354 gdb_flush (this->event_channel
);
358 mi_interp::on_inferior_removed (inferior
*inf
)
360 target_terminal::scoped_restore_terminal_state term_state
;
361 target_terminal::ours_for_output ();
363 gdb_printf (this->event_channel
, "thread-group-removed,id=\"i%d\"", inf
->num
);
364 gdb_flush (this->event_channel
);
367 /* Observers for several run control events that print why the
368 inferior has stopped to both the MI event channel and to the MI
369 console. If the MI interpreter is not active, print nothing. */
372 mi_interp::on_signal_received (enum gdb_signal siggnal
)
374 print_signal_received_reason (this->mi_uiout
, siggnal
);
375 print_signal_received_reason (this->cli_uiout
, siggnal
);
379 mi_interp::on_signal_exited (gdb_signal sig
)
381 print_signal_exited_reason (this->mi_uiout
, sig
);
382 print_signal_exited_reason (this->cli_uiout
, sig
);
386 mi_interp::on_exited (int status
)
388 print_exited_reason (this->mi_uiout
, status
);
389 print_exited_reason (this->cli_uiout
, status
);
393 mi_interp::on_no_history ()
395 print_no_history_reason (this->mi_uiout
);
396 print_no_history_reason (this->cli_uiout
);
400 mi_interp::on_normal_stop (struct bpstat
*bs
, int print_frame
)
402 /* Since this can be called when CLI command is executing,
403 using cli interpreter, be sure to use MI uiout for output,
404 not the current one. */
405 ui_out
*mi_uiout
= this->interp_ui_out ();
409 thread_info
*tp
= inferior_thread ();
411 if (tp
->thread_fsm () != nullptr
412 && tp
->thread_fsm ()->finished_p ())
414 async_reply_reason reason
415 = tp
->thread_fsm ()->async_reply_reason ();
416 mi_uiout
->field_string ("reason", async_reason_lookup (reason
));
419 interp
*console_interp
= interp_lookup (current_ui
, INTERP_CONSOLE
);
421 /* We only want to print the displays once, and we want it to
422 look just how it would on the console, so we use this to
423 decide whether the MI stop should include them. */
424 bool console_print
= should_print_stop_to_console (console_interp
, tp
);
425 print_stop_event (mi_uiout
, !console_print
);
428 print_stop_event (this->cli_uiout
);
430 mi_uiout
->field_signed ("thread-id", tp
->global_num
);
433 ui_out_emit_list
list_emitter (mi_uiout
, "stopped-threads");
435 mi_uiout
->field_signed (NULL
, tp
->global_num
);
438 mi_uiout
->field_string ("stopped-threads", "all");
440 int core
= target_core_of_thread (tp
->ptid
);
442 mi_uiout
->field_signed ("core", core
);
445 gdb_puts ("*stopped", this->raw_stdout
);
446 mi_out_put (mi_uiout
, this->raw_stdout
);
447 mi_out_rewind (mi_uiout
);
448 mi_print_timing_maybe (this->raw_stdout
);
449 gdb_puts ("\n", this->raw_stdout
);
450 gdb_flush (this->raw_stdout
);
454 mi_interp::on_about_to_proceed ()
456 /* Suppress output while calling an inferior function. */
458 if (inferior_ptid
!= null_ptid
)
460 struct thread_info
*tp
= inferior_thread ();
462 if (tp
->control
.in_infcall
)
466 this->mi_proceeded
= 1;
469 /* When the element is non-zero, no MI notifications will be emitted in
470 response to the corresponding observers. */
472 struct mi_suppress_notification mi_suppress_notification
=
481 mi_interp::on_traceframe_changed (int tfnum
, int tpnum
)
483 if (mi_suppress_notification
.traceframe
)
486 target_terminal::scoped_restore_terminal_state term_state
;
487 target_terminal::ours_for_output ();
490 gdb_printf (this->event_channel
, "traceframe-changed,"
491 "num=\"%d\",tracepoint=\"%d\"",
494 gdb_printf (this->event_channel
, "traceframe-changed,end");
496 gdb_flush (this->event_channel
);
500 mi_interp::on_tsv_created (const trace_state_variable
*tsv
)
502 target_terminal::scoped_restore_terminal_state term_state
;
503 target_terminal::ours_for_output ();
505 gdb_printf (this->event_channel
, "tsv-created,"
506 "name=\"%s\",initial=\"%s\"",
507 tsv
->name
.c_str (), plongest (tsv
->initial_value
));
509 gdb_flush (this->event_channel
);
513 mi_interp::on_tsv_deleted (const trace_state_variable
*tsv
)
515 target_terminal::scoped_restore_terminal_state term_state
;
516 target_terminal::ours_for_output ();
519 gdb_printf (this->event_channel
, "tsv-deleted,name=\"%s\"",
522 gdb_printf (this->event_channel
, "tsv-deleted");
524 gdb_flush (this->event_channel
);
528 mi_interp::on_tsv_modified (const trace_state_variable
*tsv
)
530 ui_out
*mi_uiout
= this->interp_ui_out ();
532 target_terminal::scoped_restore_terminal_state term_state
;
533 target_terminal::ours_for_output ();
535 gdb_printf (this->event_channel
,
538 ui_out_redirect_pop
redir (mi_uiout
, this->event_channel
);
540 mi_uiout
->field_string ("name", tsv
->name
);
541 mi_uiout
->field_string ("initial",
542 plongest (tsv
->initial_value
));
543 if (tsv
->value_known
)
544 mi_uiout
->field_string ("current", plongest (tsv
->value
));
546 gdb_flush (this->event_channel
);
549 /* Print breakpoint BP on MI's event channel. */
552 mi_print_breakpoint_for_event (struct mi_interp
*mi
, breakpoint
*bp
)
554 ui_out
*mi_uiout
= mi
->interp_ui_out ();
556 /* We want the output from print_breakpoint to go to
557 mi->event_channel. One approach would be to just call
558 print_breakpoint, and then use mi_out_put to send the current
559 content of mi_uiout into mi->event_channel. However, that will
560 break if anything is output to mi_uiout prior to calling the
561 breakpoint_created notifications. So, we use
563 ui_out_redirect_pop
redir (mi_uiout
, mi
->event_channel
);
567 scoped_restore restore_uiout
568 = make_scoped_restore (¤t_uiout
, mi_uiout
);
570 print_breakpoint (bp
);
572 catch (const gdb_exception_error
&ex
)
574 exception_print (gdb_stderr
, ex
);
579 mi_interp::on_breakpoint_created (breakpoint
*b
)
581 if (mi_suppress_notification
.breakpoint
)
587 target_terminal::scoped_restore_terminal_state term_state
;
588 target_terminal::ours_for_output ();
590 gdb_printf (this->event_channel
, "breakpoint-created");
591 mi_print_breakpoint_for_event (this, b
);
593 gdb_flush (this->event_channel
);
597 mi_interp::on_breakpoint_deleted (breakpoint
*b
)
599 if (mi_suppress_notification
.breakpoint
)
605 target_terminal::scoped_restore_terminal_state term_state
;
606 target_terminal::ours_for_output ();
608 gdb_printf (this->event_channel
, "breakpoint-deleted,id=\"%d\"", b
->number
);
609 gdb_flush (this->event_channel
);
613 mi_interp::on_breakpoint_modified (breakpoint
*b
)
615 if (mi_suppress_notification
.breakpoint
)
621 target_terminal::scoped_restore_terminal_state term_state
;
622 target_terminal::ours_for_output ();
623 gdb_printf (this->event_channel
, "breakpoint-modified");
624 mi_print_breakpoint_for_event (this, b
);
626 gdb_flush (this->event_channel
);
630 mi_output_running (struct thread_info
*thread
)
632 SWITCH_THRU_ALL_UIS ()
634 struct mi_interp
*mi
= as_mi_interp (top_level_interpreter ());
639 gdb_printf (mi
->raw_stdout
,
640 "*running,thread-id=\"%d\"\n",
645 /* Return true if there are multiple inferiors loaded. This is used
646 for backwards compatibility -- if there's only one inferior, output
647 "all", otherwise, output each resumed thread individually. */
650 multiple_inferiors_p ()
653 for (inferior
*inf ATTRIBUTE_UNUSED
: all_non_exited_inferiors ())
664 mi_on_resume_1 (struct mi_interp
*mi
,
665 process_stratum_target
*targ
, ptid_t ptid
)
667 /* To cater for older frontends, emit ^running, but do it only once
668 per each command. We do it here, since at this point we know
669 that the target was successfully resumed, and in non-async mode,
670 we won't return back to MI interpreter code until the target
671 is done running, so delaying the output of "^running" until then
672 will make it impossible for frontend to know what's going on.
674 In future (MI3), we'll be outputting "^done" here. */
675 if (!mi
->running_result_record_printed
&& mi
->mi_proceeded
)
677 gdb_printf (mi
->raw_stdout
, "%s^running\n",
678 mi
->current_token
? mi
->current_token
: "");
681 /* Backwards compatibility. If doing a wildcard resume and there's
682 only one inferior, output "all", otherwise, output each resumed
683 thread individually. */
684 if ((ptid
== minus_one_ptid
|| ptid
.is_pid ())
685 && !multiple_inferiors_p ())
686 gdb_printf (mi
->raw_stdout
, "*running,thread-id=\"all\"\n");
688 for (thread_info
*tp
: all_non_exited_threads (targ
, ptid
))
689 mi_output_running (tp
);
691 if (!mi
->running_result_record_printed
&& mi
->mi_proceeded
)
693 mi
->running_result_record_printed
= 1;
694 /* This is what gdb used to do historically -- printing prompt
695 even if it cannot actually accept any input. This will be
696 surely removed for MI3, and may be removed even earlier. */
697 if (current_ui
->prompt_state
== PROMPT_BLOCKED
)
698 gdb_puts ("(gdb) \n", mi
->raw_stdout
);
700 gdb_flush (mi
->raw_stdout
);
704 mi_interp::on_target_resumed (ptid_t ptid
)
706 struct thread_info
*tp
= NULL
;
708 process_stratum_target
*target
= current_inferior ()->process_target ();
709 if (ptid
== minus_one_ptid
|| ptid
.is_pid ())
710 tp
= inferior_thread ();
712 tp
= target
->find_thread (ptid
);
714 /* Suppress output while calling an inferior function. */
715 if (tp
->control
.in_infcall
)
718 target_terminal::scoped_restore_terminal_state term_state
;
719 target_terminal::ours_for_output ();
721 mi_on_resume_1 (this, target
, ptid
);
724 /* See mi-interp.h. */
727 mi_output_solib_attribs (ui_out
*uiout
, const solib
&solib
)
729 gdbarch
*gdbarch
= current_inferior ()->arch ();
731 uiout
->field_string ("id", solib
.so_original_name
);
732 uiout
->field_string ("target-name", solib
.so_original_name
);
733 uiout
->field_string ("host-name", solib
.so_name
);
734 uiout
->field_signed ("symbols-loaded", solib
.symbols_loaded
);
735 if (!gdbarch_has_global_solist (current_inferior ()->arch ()))
736 uiout
->field_fmt ("thread-group", "i%d", current_inferior ()->num
);
738 ui_out_emit_list
list_emitter (uiout
, "ranges");
739 ui_out_emit_tuple
tuple_emitter (uiout
, NULL
);
740 if (solib
.addr_high
!= 0)
742 uiout
->field_core_addr ("from", gdbarch
, solib
.addr_low
);
743 uiout
->field_core_addr ("to", gdbarch
, solib
.addr_high
);
748 mi_interp::on_solib_loaded (const solib
&solib
)
750 ui_out
*uiout
= this->interp_ui_out ();
752 target_terminal::scoped_restore_terminal_state term_state
;
753 target_terminal::ours_for_output ();
755 gdb_printf (this->event_channel
, "library-loaded");
757 ui_out_redirect_pop
redir (uiout
, this->event_channel
);
759 mi_output_solib_attribs (uiout
, solib
);
761 gdb_flush (this->event_channel
);
765 mi_interp::on_solib_unloaded (const solib
&solib
)
767 ui_out
*uiout
= this->interp_ui_out ();
769 target_terminal::scoped_restore_terminal_state term_state
;
770 target_terminal::ours_for_output ();
772 gdb_printf (this->event_channel
, "library-unloaded");
774 ui_out_redirect_pop
redir (uiout
, this->event_channel
);
776 uiout
->field_string ("id", solib
.so_original_name
);
777 uiout
->field_string ("target-name", solib
.so_original_name
);
778 uiout
->field_string ("host-name", solib
.so_name
);
779 if (!gdbarch_has_global_solist (current_inferior ()->arch ()))
780 uiout
->field_fmt ("thread-group", "i%d", current_inferior ()->num
);
782 gdb_flush (this->event_channel
);
786 mi_interp::on_param_changed (const char *param
, const char *value
)
788 if (mi_suppress_notification
.cmd_param_changed
)
791 ui_out
*mi_uiout
= this->interp_ui_out ();
793 target_terminal::scoped_restore_terminal_state term_state
;
794 target_terminal::ours_for_output ();
796 gdb_printf (this->event_channel
, "cmd-param-changed");
798 ui_out_redirect_pop
redir (mi_uiout
, this->event_channel
);
800 mi_uiout
->field_string ("param", param
);
801 mi_uiout
->field_string ("value", value
);
803 gdb_flush (this->event_channel
);
807 mi_interp::on_memory_changed (inferior
*inferior
, CORE_ADDR memaddr
,
808 ssize_t len
, const bfd_byte
*myaddr
)
810 if (mi_suppress_notification
.memory
)
814 ui_out
*mi_uiout
= this->interp_ui_out ();
816 target_terminal::scoped_restore_terminal_state term_state
;
817 target_terminal::ours_for_output ();
819 gdb_printf (this->event_channel
, "memory-changed");
821 ui_out_redirect_pop
redir (mi_uiout
, this->event_channel
);
823 mi_uiout
->field_fmt ("thread-group", "i%d", inferior
->num
);
824 mi_uiout
->field_core_addr ("addr", current_inferior ()->arch (), memaddr
);
825 mi_uiout
->field_string ("len", hex_string (len
));
827 /* Append 'type=code' into notification if MEMADDR falls in the range of
828 sections contain code. */
829 obj_section
*sec
= find_pc_section (memaddr
);
830 if (sec
!= nullptr && sec
->objfile
!= nullptr)
832 flagword flags
= bfd_section_flags (sec
->the_bfd_section
);
834 if (flags
& SEC_CODE
)
835 mi_uiout
->field_string ("type", "code");
838 gdb_flush (this->event_channel
);
842 mi_interp::on_user_selected_context_changed (user_selected_what selection
)
844 /* Don't send an event if we're responding to an MI command. */
845 if (mi_suppress_notification
.user_selected_context
)
848 thread_info
*tp
= inferior_ptid
!= null_ptid
? inferior_thread () : nullptr;
849 ui_out
*mi_uiout
= this->interp_ui_out ();
850 ui_out_redirect_pop
redirect_popper (mi_uiout
, this->event_channel
);
852 target_terminal::scoped_restore_terminal_state term_state
;
853 target_terminal::ours_for_output ();
855 if (selection
& USER_SELECTED_INFERIOR
)
856 print_selected_inferior (this->cli_uiout
);
859 && (selection
& (USER_SELECTED_THREAD
| USER_SELECTED_FRAME
)))
861 print_selected_thread_frame (this->cli_uiout
, selection
);
863 gdb_printf (this->event_channel
, "thread-selected,id=\"%d\"",
866 if (tp
->state
!= THREAD_RUNNING
)
868 if (has_stack_frames ())
869 print_stack_frame_to_uiout (mi_uiout
, get_selected_frame (NULL
),
874 gdb_flush (this->event_channel
);
878 mi_interp::interp_ui_out ()
880 return this->mi_uiout
;
883 /* Do MI-specific logging actions; save raw_stdout, and change all
884 the consoles to use the supplied ui-file(s). */
887 mi_interp::set_logging (ui_file_up logfile
, bool logging_redirect
,
890 struct mi_interp
*mi
= this;
894 mi
->saved_raw_stdout
= mi
->raw_stdout
;
896 ui_file
*logfile_p
= logfile
.get ();
897 mi
->logfile_holder
= std::move (logfile
);
899 /* If something is not being redirected, then a tee containing both the
900 logfile and stdout. */
901 ui_file
*tee
= nullptr;
902 if (!logging_redirect
|| !debug_redirect
)
904 tee
= new tee_file (mi
->raw_stdout
, logfile_p
);
905 mi
->stdout_holder
.reset (tee
);
908 mi
->raw_stdout
= logging_redirect
? logfile_p
: tee
;
912 mi
->logfile_holder
.reset ();
913 mi
->stdout_holder
.reset ();
914 mi
->raw_stdout
= mi
->saved_raw_stdout
;
915 mi
->saved_raw_stdout
= nullptr;
918 mi
->out
->set_raw (mi
->raw_stdout
);
919 mi
->err
->set_raw (mi
->raw_stdout
);
920 mi
->log
->set_raw (mi
->raw_stdout
);
921 mi
->targ
->set_raw (mi
->raw_stdout
);
922 mi
->event_channel
->set_raw (mi
->raw_stdout
);
925 /* Factory for MI interpreters. */
927 static struct interp
*
928 mi_interp_factory (const char *name
)
930 return new mi_interp (name
);
933 void _initialize_mi_interp ();
935 _initialize_mi_interp ()
937 /* The various interpreter levels. */
938 interp_factory_register (INTERP_MI2
, mi_interp_factory
);
939 interp_factory_register (INTERP_MI3
, mi_interp_factory
);
940 interp_factory_register (INTERP_MI4
, mi_interp_factory
);
941 interp_factory_register (INTERP_MI
, mi_interp_factory
);