static void mi_breakpoint_modified (struct breakpoint *b) { struct mi_interp *mi = top_level_interpreter_data (); struct ui_out *mi_uiout = interp_ui_out (top_level_interpreter ()); volatile struct gdb_exception e; if (mi_suppress_notification.breakpoint) return; if (b->number <= 0) return; target_terminal_ours (); fprintf_unfiltered (mi->event_channel, "breakpoint-modified"); /* We want the output from gdb_breakpoint_query to go to mi->event_channel. One approach would be to just call gdb_breakpoint_query, and then use mi_out_put to send the current content of mi_outout into mi->event_channel. However, that will break if anything is output to mi_uiout prior to calling the breakpoint_created notifications. So, we use ui_out_redirect. */ ui_out_redirect (mi_uiout, mi->event_channel); TRY_CATCH (e, RETURN_MASK_ERROR) gdb_breakpoint_query (mi_uiout, b->number, NULL); ui_out_redirect (mi_uiout, NULL); gdb_flush (mi->event_channel); }
static void mi_solib_loaded (struct so_list *solib) { struct mi_interp *mi = top_level_interpreter_data (); struct ui_out *uiout = interp_ui_out (top_level_interpreter ()); target_terminal_ours (); fprintf_unfiltered (mi->event_channel, "library-loaded"); ui_out_redirect (uiout, mi->event_channel); ui_out_field_string (uiout, "id", solib->so_original_name); ui_out_field_string (uiout, "target-name", solib->so_original_name); ui_out_field_string (uiout, "host-name", solib->so_name); ui_out_field_int (uiout, "symbols-loaded", solib->symbols_loaded); if (!gdbarch_has_global_solist (target_gdbarch ())) { ui_out_field_fmt (uiout, "thread-group", "i%d", current_inferior ()->num); } ui_out_redirect (uiout, NULL); gdb_flush (mi->event_channel); }
static void mi_record_changed (struct inferior *inferior, int started) { struct mi_interp *mi = top_level_interpreter_data (); fprintf_unfiltered (mi->event_channel, "record-%s,thread-group=\"i%d\"", started ? "started" : "stopped", inferior->num); gdb_flush (mi->event_channel); }
static void mi_inferior_removed (struct inferior *inf) { struct mi_interp *mi = top_level_interpreter_data (); target_terminal_ours (); fprintf_unfiltered (mi->event_channel, "thread-group-removed,id=\"i%d\"", inf->num); gdb_flush (mi->event_channel); }
static void mi_new_thread (struct thread_info *t) { struct mi_interp *mi = top_level_interpreter_data (); struct inferior *inf = find_inferior_ptid (t->ptid); gdb_assert (inf); fprintf_unfiltered (mi->event_channel, "thread-created,id=\"%d\",group-id=\"i%d\"", t->num, inf->num); gdb_flush (mi->event_channel); }
static void mi_tsv_created (const struct trace_state_variable *tsv) { struct mi_interp *mi = top_level_interpreter_data (); target_terminal_ours (); fprintf_unfiltered (mi->event_channel, "tsv-created," "name=\"%s\",initial=\"%s\"\n", tsv->name, plongest (tsv->initial_value)); gdb_flush (mi->event_channel); }
static void mi_tsv_deleted (const struct trace_state_variable *tsv) { struct mi_interp *mi = top_level_interpreter_data (); target_terminal_ours (); if (tsv != NULL) fprintf_unfiltered (mi->event_channel, "tsv-deleted," "name=\"%s\"\n", tsv->name); else fprintf_unfiltered (mi->event_channel, "tsv-deleted\n"); gdb_flush (mi->event_channel); }
static void mi_inferior_exit (struct inferior *inf) { struct mi_interp *mi = top_level_interpreter_data (); target_terminal_ours (); if (inf->has_exit_code) fprintf_unfiltered (mi->event_channel, "thread-group-exited,id=\"i%d\",exit-code=\"%s\"", inf->num, int_string (inf->exit_code, 8, 0, 0, 1)); else fprintf_unfiltered (mi->event_channel, "thread-group-exited,id=\"i%d\"", inf->num); gdb_flush (mi->event_channel); }
static void mi_thread_exit (struct thread_info *t, int silent) { struct mi_interp *mi; struct inferior *inf; if (silent) return; inf = find_inferior_pid (ptid_get_pid (t->ptid)); mi = top_level_interpreter_data (); target_terminal_ours (); fprintf_unfiltered (mi->event_channel, "thread-exited,id=\"%d\",group-id=\"i%d\"", t->num, inf->num); gdb_flush (mi->event_channel); }
static void mi_breakpoint_deleted (struct breakpoint *b) { struct mi_interp *mi = top_level_interpreter_data (); if (mi_suppress_notification.breakpoint) return; if (b->number <= 0) return; target_terminal_ours (); fprintf_unfiltered (mi->event_channel, "breakpoint-deleted,id=\"%d\"", b->number); gdb_flush (mi->event_channel); }
static void mi_traceframe_changed (int tfnum, int tpnum) { struct mi_interp *mi = top_level_interpreter_data (); if (mi_suppress_notification.traceframe) return; target_terminal_ours (); if (tfnum >= 0) fprintf_unfiltered (mi->event_channel, "traceframe-changed," "num=\"%d\",tracepoint=\"%d\"\n", tfnum, tpnum); else fprintf_unfiltered (mi->event_channel, "traceframe-changed,end"); gdb_flush (mi->event_channel); }
static void mi_solib_unloaded (struct so_list *solib) { struct mi_interp *mi = top_level_interpreter_data (); target_terminal_ours (); if (gdbarch_has_global_solist (target_gdbarch ())) fprintf_unfiltered (mi->event_channel, "library-unloaded,id=\"%s\",target-name=\"%s\"," "host-name=\"%s\"", solib->so_original_name, solib->so_original_name, solib->so_name); else fprintf_unfiltered (mi->event_channel, "library-unloaded,id=\"%s\",target-name=\"%s\"," "host-name=\"%s\",thread-group=\"i%d\"", solib->so_original_name, solib->so_original_name, solib->so_name, current_inferior ()->num); gdb_flush (mi->event_channel); }
static void mi_thread_exit (struct thread_info *t, int silent) { struct mi_interp *mi; struct inferior *inf; struct cleanup *old_chain; if (silent) return; inf = find_inferior_ptid (t->ptid); mi = top_level_interpreter_data (); old_chain = make_cleanup_restore_target_terminal (); target_terminal_ours (); fprintf_unfiltered (mi->event_channel, "thread-exited,id=\"%d\",group-id=\"i%d\"", t->num, inf->num); gdb_flush (mi->event_channel); do_cleanups (old_chain); }
static void mi_memory_changed (struct inferior *inferior, CORE_ADDR memaddr, ssize_t len, const bfd_byte *myaddr) { struct mi_interp *mi = top_level_interpreter_data (); struct ui_out *mi_uiout = interp_ui_out (top_level_interpreter ()); struct obj_section *sec; if (mi_suppress_notification.memory) return; target_terminal_ours (); fprintf_unfiltered (mi->event_channel, "memory-changed"); ui_out_redirect (mi_uiout, mi->event_channel); ui_out_field_fmt (mi_uiout, "thread-group", "i%d", inferior->num); ui_out_field_core_addr (mi_uiout, "addr", target_gdbarch (), memaddr); ui_out_field_fmt (mi_uiout, "len", "%s", hex_string (len)); /* Append 'type=code' into notification if MEMADDR falls in the range of sections contain code. */ sec = find_pc_section (memaddr); if (sec != NULL && sec->objfile != NULL) { flagword flags = bfd_get_section_flags (sec->objfile->obfd, sec->the_bfd_section); if (flags & SEC_CODE) ui_out_field_string (mi_uiout, "type", "code"); } ui_out_redirect (mi_uiout, NULL); gdb_flush (mi->event_channel); }
static void mi_tsv_modified (const struct trace_state_variable *tsv) { struct mi_interp *mi = top_level_interpreter_data (); struct ui_out *mi_uiout = interp_ui_out (top_level_interpreter ()); target_terminal_ours (); fprintf_unfiltered (mi->event_channel, "tsv-modified"); ui_out_redirect (mi_uiout, mi->event_channel); ui_out_field_string (mi_uiout, "name", tsv->name); ui_out_field_string (mi_uiout, "initial", plongest (tsv->initial_value)); if (tsv->value_known) ui_out_field_string (mi_uiout, "current", plongest (tsv->value)); ui_out_redirect (mi_uiout, NULL); gdb_flush (mi->event_channel); }
static void mi_command_param_changed (const char *param, const char *value) { struct mi_interp *mi = top_level_interpreter_data (); struct ui_out *mi_uiout = interp_ui_out (top_level_interpreter ()); if (mi_suppress_notification.cmd_param_changed) return; target_terminal_ours (); fprintf_unfiltered (mi->event_channel, "cmd-param-changed"); ui_out_redirect (mi_uiout, mi->event_channel); ui_out_field_string (mi_uiout, "param", param); ui_out_field_string (mi_uiout, "value", value); ui_out_redirect (mi_uiout, NULL); gdb_flush (mi->event_channel); }
static void mi_on_normal_stop (struct bpstats *bs, int print_frame) { /* Since this can be called when CLI command is executing, 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 ()); if (print_frame) { struct thread_info *tp; int core; tp = inferior_thread (); if (tp->thread_fsm != NULL && thread_fsm_finished_p (tp->thread_fsm)) { enum async_reply_reason reason; reason = thread_fsm_async_reply_reason (tp->thread_fsm); ui_out_field_string (mi_uiout, "reason", async_reason_lookup (reason)); } print_stop_event (mi_uiout); /* Breakpoint hits should always be mirrored to the console. Deciding what to mirror to the console wrt to breakpoints and random stops gets messy real fast. E.g., say "s" trips on a breakpoint. We'd clearly want to mirror the event to the console in this case. But what about more complicated cases like "s&; thread n; s&", and one of those steps spawning a new thread, and that thread hitting a breakpoint? It's impossible in general to track whether the thread had any relation to the commands that had been executed. So we just simplify and always mirror breakpoints and random events to the console. OTOH, we should print the source line to the console when stepping or other similar commands, iff the step was started by a console command, but not if it was started with -exec-step or similar. */ if ((bpstat_what (tp->control.stop_bpstat).main_action == BPSTAT_WHAT_STOP_NOISY) || !(tp->thread_fsm != NULL && 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); } ui_out_field_int (mi_uiout, "thread-id", pid_to_thread_id (inferior_ptid)); if (non_stop) { struct cleanup *back_to = make_cleanup_ui_out_list_begin_end (mi_uiout, "stopped-threads"); ui_out_field_int (mi_uiout, NULL, pid_to_thread_id (inferior_ptid)); do_cleanups (back_to); } else ui_out_field_string (mi_uiout, "stopped-threads", "all"); core = target_core_of_thread (inferior_ptid); if (core != -1) ui_out_field_int (mi_uiout, "core", core); } fputs_unfiltered ("*stopped", raw_stdout); mi_out_put (mi_uiout, raw_stdout); mi_out_rewind (mi_uiout); mi_print_timing_maybe (); fputs_unfiltered ("\n", raw_stdout); gdb_flush (raw_stdout); }
static void mi_on_normal_stop (struct bpstats *bs, int print_frame) { /* Since this can be called when CLI command is executing, 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 ()); if (print_frame) { int core; if (current_uiout != mi_uiout) { /* The normal_stop function has printed frame information into CLI uiout, or some other non-MI uiout. There's no way we can extract proper fields from random uiout object, so we print the frame again. In practice, this can only happen when running a CLI command in MI. */ struct ui_out *saved_uiout = current_uiout; struct target_waitstatus last; ptid_t last_ptid; current_uiout = mi_uiout; get_last_target_status (&last_ptid, &last); print_stop_event (&last); current_uiout = saved_uiout; } /* Otherwise, frame information has already been printed by normal_stop. */ else { /* Breakpoint hits should always be mirrored to the console. Deciding what to mirror to the console wrt to breakpoints and random stops gets messy real fast. E.g., say "s" trips on a breakpoint. We'd clearly want to mirror the event to the console in this case. But what about more complicated cases like "s&; thread n; s&", and one of those steps spawning a new thread, and that thread hitting a breakpoint? It's impossible in general to track whether the thread had any relation to the commands that had been executed. So we just simplify and always mirror breakpoints and random events to the console. Also, CLI execution commands (-interpreter-exec console "next", for example) in async mode have the opposite issue as described in the "then" branch above -- normal_stop has already printed frame information to MI uiout, but nothing has printed the same information to the CLI channel. We should print the source line to the console when stepping or other similar commands, iff the step was started by a console command (but not if it was started with -exec-step or similar). */ struct thread_info *tp = inferior_thread (); if ((!tp->control.stop_step && !tp->control.proceed_to_finish) || (tp->control.command_interp != NULL && tp->control.command_interp != top_level_interpreter ())) { struct mi_interp *mi = top_level_interpreter_data (); struct target_waitstatus last; ptid_t last_ptid; struct cleanup *old_chain; /* Set the current uiout to CLI uiout temporarily. */ old_chain = make_cleanup (restore_current_uiout_cleanup, current_uiout); current_uiout = mi->cli_uiout; get_last_target_status (&last_ptid, &last); print_stop_event (&last); do_cleanups (old_chain); } } ui_out_field_int (mi_uiout, "thread-id", pid_to_thread_id (inferior_ptid)); if (non_stop) { struct cleanup *back_to = make_cleanup_ui_out_list_begin_end (mi_uiout, "stopped-threads"); ui_out_field_int (mi_uiout, NULL, pid_to_thread_id (inferior_ptid)); do_cleanups (back_to); } else ui_out_field_string (mi_uiout, "stopped-threads", "all"); core = target_core_of_thread (inferior_ptid); if (core != -1) ui_out_field_int (mi_uiout, "core", core); } fputs_unfiltered ("*stopped", raw_stdout); mi_out_put (mi_uiout, raw_stdout); mi_out_rewind (mi_uiout); mi_print_timing_maybe (); fputs_unfiltered ("\n", raw_stdout); gdb_flush (raw_stdout); }