Re: [PATCH v2 05/25] Make the intepreters output to all UIs

Yao Qi
2016-03-22T09:33:32Z

Pedro Alves <palves@redhat.com> writes:

Hi Pedro,
We have three interpreters, cli, mi and tui. Each of them has a
${inter}_on_normal_stop registered to normal_stop observer, as below,

> @@ -50,10 +55,17 @@ static struct gdb_exception safe_execute_command (struct ui_out *uiout,
> static void
> cli_on_normal_stop (struct bpstats *bs, int print_frame)
> {
> - if (!interp_quiet_p (cli_interp))
> + struct switch_thru_all_uis state;
> +
> + SWITCH_THRU_ALL_UIS (state)
> {
> + struct cli_interp *cli = as_cli_interp (top_level_interpreter ());
> +
> + if (cli == NULL)
> + continue;
> +
> if (print_frame)
> - print_stop_event (interp_ui_out (cli_interp));
> + print_stop_event (cli->cli_uiout);
> }
> }
>

>
> static void
> -mi_on_normal_stop (struct bpstats *bs, int print_frame)
> +mi_on_normal_stop_1 (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,
> @@ -645,6 +697,20 @@ mi_on_normal_stop (struct bpstats *bs, int print_frame)
> }
>
> static void
> +mi_on_normal_stop (struct bpstats *bs, int print_frame)
> +{
> + struct switch_thru_all_uis state;
> +
> + SWITCH_THRU_ALL_UIS (state)
> + {
> + if (as_mi_interp (top_level_interpreter ()) == NULL)
> + continue;
> +
> + mi_on_normal_stop_1 (bs, print_frame);
> + }
> +}
> +

> static void
> tui_on_normal_stop (struct bpstats *bs, int print_frame)
> {
> - if (!interp_quiet_p (tui_interp))
> + struct switch_thru_all_uis state;
> +
> + SWITCH_THRU_ALL_UIS (state)
> {
> + struct interp *tui = as_tui_interp (top_level_interpreter ());
> +
> + if (tui == NULL)
> + continue;
> +
> if (print_frame)
> - print_stop_event (tui_ui_out (tui_interp));
> + print_stop_event (tui_ui_out (tui));
> }
> }

Why don't we have 'struct ui' have a method 'print_stop_event', so that
we can put the different handling there. In this way, we can only
register one to normal_stop observer, in interps.c for example, and the
code can be simplified, like this,

static void
interp_on_normal_stop (struct bpstats *bs, int print_frame)
{
struct switch_thru_all_uis state;

SWITCH_THRU_ALL_UIS (state)
{
current_ui->print_stop_event (bs, print_frame);
}
}

we don't have to check the type of interpreter in the loop anymore.

--
Yao (齐尧)