From: Andrew Burgess <aburgess@redhat.com>
To: Simon Marchi via Gdb-patches <gdb-patches@sourceware.org>,
gdb-patches@sourceware.org
Cc: Simon Marchi <simon.marchi@efficios.com>
Subject: Re: [PATCH 18/21] gdb: make interp_set a method of struct ui
Date: Tue, 12 Sep 2023 11:58:44 +0100 [thread overview]
Message-ID: <875y4fk68r.fsf@redhat.com> (raw)
In-Reply-To: <20230908190227.96319-19-simon.marchi@efficios.com>
Simon Marchi via Gdb-patches <gdb-patches@sourceware.org> writes:
> Move interp_set to ui::set_current_interpreter.
>
> Change-Id: I7e83ca7732bb6229a1e61dc0e3832f54c20c3f52
> ---
> gdb/interps.c | 66 +++------------------------------------------------
> gdb/ui.c | 51 +++++++++++++++++++++++++++++++++++++++
> gdb/ui.h | 12 ++++++++++
> 3 files changed, 66 insertions(+), 63 deletions(-)
>
> diff --git a/gdb/interps.c b/gdb/interps.c
> index 18758f1f7af6..465c174ea794 100644
> --- a/gdb/interps.c
> +++ b/gdb/interps.c
> @@ -80,66 +80,6 @@ find_interp_factory (const char *name)
> return nullptr;
> }
>
> -/* This sets the current interpreter to be INTERP. If INTERP has not
> - been initialized, then this will also run the init method.
> -
> - The TOP_LEVEL parameter tells if this new interpreter is
> - the top-level one. The top-level is what is requested
> - on the command line, and is responsible for reporting general
> - notification about target state changes. For example, if
> - MI is the top-level interpreter, then it will always report
> - events such as target stops and new thread creation, even if they
> - are caused by CLI commands. */
> -
> -static void
> -interp_set (ui *ui, struct interp *interp, bool top_level)
> -{
> - struct interp *old_interp = ui->current_interpreter;
> -
> - /* If we already have an interpreter, then trying to
> - set top level interpreter is kinda pointless. */
> - gdb_assert (!top_level || !ui->current_interpreter);
> - gdb_assert (!top_level || !ui->top_level_interpreter);
> -
> - if (old_interp != NULL)
> - {
> - ui->m_current_uiout->flush ();
> - old_interp->suspend ();
> - }
> -
> - ui->current_interpreter = interp;
> - if (top_level)
> - ui->top_level_interpreter = interp;
> -
> - if (interpreter_p != interp->name ())
> - interpreter_p = interp->name ();
> -
> - bool warn_about_mi1 = false;
> -
> - /* Run the init proc. */
> - if (!interp->inited)
> - {
> - interp->init (top_level);
> - interp->inited = true;
> -
> - if (streq (interp->name (), "mi1"))
> - warn_about_mi1 = true;
> - }
> -
> - /* Do this only after the interpreter is initialized. */
> - ui->m_current_uiout = interp->interp_ui_out ();
> -
> - /* Clear out any installed interpreter hooks/event handlers. */
> - clear_interpreter_hooks ();
> -
> - interp->resume ();
> -
> - if (warn_about_mi1)
> - warning (_("MI version 1 is deprecated in GDB 13 and "
> - "will be removed in GDB 14. Please upgrade "
> - "to a newer version of MI."));
> -}
> -
> /* See interps.h. */
>
> void
> @@ -151,7 +91,7 @@ set_top_level_interpreter (const char *name)
> if (interp == NULL)
> error (_("Interpreter `%s' unrecognized"), name);
> /* Install it. */
> - interp_set (current_ui, interp, true);
> + current_ui->set_current_interpreter (interp, true);
> }
>
> void
> @@ -267,10 +207,10 @@ interpreter_exec_cmd (const char *args, int from_tty)
> if (interp_to_use == NULL)
> error (_("Could not find interpreter \"%s\"."), prules[0]);
>
> - interp_set (current_ui, interp_to_use, false);
> + current_ui->set_current_interpreter (interp_to_use, false);
> SCOPE_EXIT
> {
> - interp_set (current_ui, old_interp, false);
> + current_ui->set_current_interpreter (old_interp, false);
> };
>
> for (i = 1; i < nrules; i++)
> diff --git a/gdb/ui.c b/gdb/ui.c
> index 8c04dc92b89e..2db899eb9c31 100644
> --- a/gdb/ui.c
> +++ b/gdb/ui.c
> @@ -172,6 +172,57 @@ ui::lookup_interp (const char *name)
>
> /* See ui.h. */
>
> +void
> +ui::set_current_interpreter (interp *interp, bool top_level)
> +{
> + struct interp *old_interp = this->current_interpreter;
Is there any way that we can assert something like:
gdb_assert (this == interp->m_ui);
we maybe need an interp::mi() accessor function.
> +
> + /* If we already have an interpreter, then trying to
> + set top level interpreter is kinda pointless. */
> + gdb_assert (!top_level || !this->current_interpreter);
> + gdb_assert (!top_level || !this->top_level_interpreter);
> +
> + if (old_interp != NULL)
> + {
> + m_current_uiout->flush ();
> + old_interp->suspend ();
> + }
> +
> + this->current_interpreter = interp;
> + if (top_level)
> + this->top_level_interpreter = interp;
> +
> + if (interpreter_p != interp->name ())
> + interpreter_p = interp->name ();
> +
> + bool warn_about_mi1 = false;
> +
> + /* Run the init proc. */
> + if (!interp->inited)
> + {
> + interp->init (top_level);
> + interp->inited = true;
> +
> + if (streq (interp->name (), "mi1"))
> + warn_about_mi1 = true;
> + }
> +
> + /* Do this only after the interpreter is initialized. */
> + m_current_uiout = interp->interp_ui_out ();
> +
> + /* Clear out any installed interpreter hooks/event handlers. */
> + clear_interpreter_hooks ();
> +
> + interp->resume ();
> +
> + if (warn_about_mi1)
> + warning (_("MI version 1 is deprecated in GDB 13 and "
> + "will be removed in GDB 14. Please upgrade "
> + "to a newer version of MI."));
> +}
> +
> +/* See ui.h. */
> +
> void
> ui::unregister_file_handler ()
> {
> diff --git a/gdb/ui.h b/gdb/ui.h
> index be89ab3d6848..4f6a32991d6d 100644
> --- a/gdb/ui.h
> +++ b/gdb/ui.h
> @@ -167,6 +167,18 @@ struct ui : public intrusive_list_node<ui>
> interp_factory_register, return nullptr; otherwise return a pointer to
> the interpreter. */
> interp *lookup_interp (const char *name);
> +
> + /* This sets the current interpreter of this UI to be INTERP. If INTERP has
> + not been initialized, then this will also run the init method.
> +
> + The TOP_LEVEL parameter tells if this new interpreter is
I know these aren't your words, but could we take this chance to update
this text to:
The TOP_LEVEL parameter is true if this new interpreter is
which reads much nicer.
Thanks,
Andrew
> + the top-level one. The top-level is what is requested
> + on the command line, and is responsible for reporting general
> + notification about target state changes. For example, if
> + MI is the top-level interpreter, then it will always report
> + events such as target stops and new thread creation, even if they
> + are caused by CLI commands. */
> + void set_current_interpreter (interp *interp, bool top_level);
> };
>
> /* The main UI. This is the UI that is bound to stdin/stdout/stderr.
> --
> 2.42.0
next prev parent reply other threads:[~2023-09-12 10:58 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-08 18:22 [PATCH 00/21] ui / interp cleansup Simon Marchi
2023-09-08 18:22 ` [PATCH 01/21] gdb: use intrusive_list for struct ui linked list Simon Marchi
2023-09-08 18:22 ` [PATCH 02/21] gdb: make interp_lookup_existing a method of struct ui Simon Marchi
2023-09-08 18:22 ` [PATCH 03/21] gdb: make interp_add " Simon Marchi
2023-09-08 18:22 ` [PATCH 04/21] gdb: make interp_lookup " Simon Marchi
2023-09-12 9:15 ` Andrew Burgess
2023-09-12 14:38 ` Simon Marchi
2023-09-08 18:22 ` [PATCH 05/21] gdb: remove ui:::add_interp and ui::lookup_existing_interp Simon Marchi
2023-09-08 18:23 ` [PATCH 06/21] gdb: uncover some current_ui uses in interp_set Simon Marchi
2023-09-08 18:23 ` [PATCH 07/21] gdb: add backlink to ui in interp Simon Marchi
2023-09-08 18:23 ` [PATCH 08/21] gdb: pass ui down to gdb_setup_readline and gdb_disable_readline Simon Marchi
2023-09-08 18:23 ` [PATCH 09/21] gdb/python: use m_ui instead of current_ui in dap_interp::init Simon Marchi
2023-09-08 18:23 ` [PATCH 10/21] gdb/mi: use m_ui instead of current_ui in mi_interp::init Simon Marchi
2023-09-08 18:23 ` [PATCH 11/21] gdb/cli: use m_ui instead of current_ui in cli_interp::resume Simon Marchi
2023-09-12 10:40 ` Andrew Burgess
2023-09-12 15:42 ` Simon Marchi
2023-09-08 18:23 ` [PATCH 12/21] gdb/tui: use m_ui instead of current_ui in tui_interp::resume Simon Marchi
2023-09-12 10:41 ` Andrew Burgess
2023-09-08 18:23 ` [PATCH 13/21] gdb/mi: use m_ui instead of current_ui in mi_interp::resume Simon Marchi
2023-09-12 10:44 ` Andrew Burgess
2023-09-12 16:36 ` Simon Marchi
2023-09-08 18:23 ` [PATCH 14/21] gdb/cli: use m_ui instead of current_ui in cli_interp::suspend Simon Marchi
2023-09-08 18:23 ` [PATCH 15/21] gdb/tui: use m_ui instead of current_ui in tui_interp::suspend Simon Marchi
2023-09-08 18:23 ` [PATCH 16/21] gdb/mi: use m_ui instead of current_ui in mi_interp::suspend Simon Marchi
2023-09-08 18:23 ` [PATCH 17/21] gdb: pass current_ui down to interp_set Simon Marchi
2023-09-12 10:54 ` Andrew Burgess
2023-09-12 17:17 ` Simon Marchi
2023-09-08 18:23 ` [PATCH 18/21] gdb: make interp_set a method of struct ui Simon Marchi
2023-09-12 10:58 ` Andrew Burgess [this message]
2023-09-12 17:23 ` Simon Marchi
2023-09-12 13:41 ` Tom Tromey
2023-09-12 17:32 ` Simon Marchi
2023-09-08 18:23 ` [PATCH 19/21] gdb: pass down current_ui to set_top_level_interpreter Simon Marchi
2023-09-11 15:15 ` Simon Marchi
2023-09-08 18:23 ` [PATCH 20/21] gdb: make set_top_level_interpreter a method of struct ui Simon Marchi
2023-09-12 11:20 ` Andrew Burgess
2023-09-12 17:41 ` Simon Marchi
2023-09-08 18:23 ` [PATCH 21/21] gdb: make top_level_interpreter " Simon Marchi
2023-09-12 11:35 ` Andrew Burgess
2023-09-12 17:54 ` Simon Marchi
2023-09-12 11:38 ` [PATCH 00/21] ui / interp cleansup Andrew Burgess
2023-09-12 17:51 ` Simon Marchi
2023-09-12 18:06 ` Tom Tromey
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=875y4fk68r.fsf@redhat.com \
--to=aburgess@redhat.com \
--cc=gdb-patches@sourceware.org \
--cc=simon.marchi@efficios.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).