public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Andrew Burgess <aburgess@redhat.com>
To: Tom Tromey <tromey@adacore.com>, gdb-patches@sourceware.org
Cc: Tom Tromey <tromey@adacore.com>
Subject: Re: [PATCH] Don't allow new-ui to start the TUI
Date: Fri, 17 May 2024 15:11:11 +0100	[thread overview]
Message-ID: <87y188plz4.fsf@redhat.com> (raw)
In-Reply-To: <20240514133724.3726920-1-tromey@adacore.com>

Tom Tromey <tromey@adacore.com> writes:

> The TUI can't really work properly with new-ui, at least not as
> currently written.  This patch changes new-ui to reject an attempt.
> Attempting to make a DAP ui this way is also now rejected.
>
> Regression tested on x86-64 Fedora 38.

LGTM.

Approved-By: Andrew Burgess <aburgess@redhat.com>

Thanks,
Andrew

>
> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29273
> ---
>  gdb/interps.c                     |  5 ++++-
>  gdb/interps.h                     | 10 ++++++++--
>  gdb/main.c                        |  2 +-
>  gdb/python/py-dap.c               |  3 +++
>  gdb/testsuite/gdb.base/new-ui.exp |  5 +++++
>  gdb/tui/tui-interp.c              |  3 +++
>  gdb/ui.c                          |  2 +-
>  7 files changed, 25 insertions(+), 5 deletions(-)
>
> diff --git a/gdb/interps.c b/gdb/interps.c
> index 94a982e97ab..59c4ec532a7 100644
> --- a/gdb/interps.c
> +++ b/gdb/interps.c
> @@ -187,13 +187,16 @@ interp_lookup (struct ui *ui, const char *name)
>  /* See interps.h.  */
>  
>  void
> -set_top_level_interpreter (const char *name)
> +set_top_level_interpreter (const char *name, bool for_new_ui)
>  {
>    /* Find it.  */
>    struct interp *interp = interp_lookup (current_ui, name);
>  
>    if (interp == NULL)
>      error (_("Interpreter `%s' unrecognized"), name);
> +  if (for_new_ui && !interp->supports_new_ui ())
> +    error (_("interpreter '%s' cannot be used with a new UI"), name);
> +
>    /* Install it.  */
>    interp_set (interp, true);
>  }
> diff --git a/gdb/interps.h b/gdb/interps.h
> index bd435d734af..8d80c005ded 100644
> --- a/gdb/interps.h
> +++ b/gdb/interps.h
> @@ -84,6 +84,10 @@ class interp : public intrusive_list_node<interp>
>    virtual bool supports_command_editing ()
>    { return false; }
>  
> +  /* Returns true if this interpreter supports new UIs.  */
> +  virtual bool supports_new_ui () const
> +  { return true; }
> +
>    const char *name () const
>    { return m_name; }
>  
> @@ -201,8 +205,10 @@ extern struct interp *interp_lookup (struct ui *ui, const char *name);
>  
>  /* Set the current UI's top level interpreter to the interpreter named
>     NAME.  Throws an error if NAME is not a known interpreter or the
> -   interpreter fails to initialize.  */
> -extern void set_top_level_interpreter (const char *name);
> +   interpreter fails to initialize.  FOR_NEW_UI is true when called
> +   from the 'new-ui' command, and causes an extra check to ensure the
> +   interpreter is valid for a new UI.  */
> +extern void set_top_level_interpreter (const char *name, bool for_new_ui);
>  
>  /* Temporarily set the current interpreter, and reset it on
>     destruction.  */
> diff --git a/gdb/main.c b/gdb/main.c
> index 8b81640e8d2..efc04a66bbb 100644
> --- a/gdb/main.c
> +++ b/gdb/main.c
> @@ -1147,7 +1147,7 @@ captured_main_1 (struct captured_main_args *context)
>  
>    /* Install the default UI.  All the interpreters should have had a
>       look at things by now.  Initialize the default interpreter.  */
> -  set_top_level_interpreter (interpreter_p.c_str ());
> +  set_top_level_interpreter (interpreter_p.c_str (), false);
>  
>    /* The interpreter should have installed the real uiout by now.  */
>    gdb_assert (current_uiout != temp_uiout.get ());
> diff --git a/gdb/python/py-dap.c b/gdb/python/py-dap.c
> index 861514d9002..d5555c90a11 100644
> --- a/gdb/python/py-dap.c
> +++ b/gdb/python/py-dap.c
> @@ -62,6 +62,9 @@ class dap_interp final : public interp
>  
>    void pre_command_loop () override;
>  
> +  bool supports_new_ui () const override
> +  { return false; }
> +
>  private:
>  
>    std::unique_ptr<ui_out> m_ui_out;
> diff --git a/gdb/testsuite/gdb.base/new-ui.exp b/gdb/testsuite/gdb.base/new-ui.exp
> index 97166925c1b..2dfcbf7e108 100644
> --- a/gdb/testsuite/gdb.base/new-ui.exp
> +++ b/gdb/testsuite/gdb.base/new-ui.exp
> @@ -183,6 +183,11 @@ proc_with_prefix do_test_invalid_args {} {
>  	     "Interpreter `bloop' unrecognized" \
>  	     "new-ui with bad interpreter name"
>  
> +    # Test that the TUI cannot be used for a new UI.
> +    gdb_test "new-ui tui $extra_tty_name" \
> +	"interpreter 'tui' cannot be used with a new UI" \
> +	"new-ui with tui"
> +
>      # Test that we can continue working normally.
>      if ![runto_main] {
>  	return
> diff --git a/gdb/tui/tui-interp.c b/gdb/tui/tui-interp.c
> index a75708ba662..7ebaf8f83f7 100644
> --- a/gdb/tui/tui-interp.c
> +++ b/gdb/tui/tui-interp.c
> @@ -50,6 +50,9 @@ class tui_interp final : public cli_interp_base
>    void suspend () override;
>    void exec (const char *command_str) override;
>    ui_out *interp_ui_out () override;
> +
> +  bool supports_new_ui () const override
> +  { return false; }
>  };
>  
>  /* Cleanup the tui before exiting.  */
> diff --git a/gdb/ui.c b/gdb/ui.c
> index 80ee67dbae5..e5c7965d8dc 100644
> --- a/gdb/ui.c
> +++ b/gdb/ui.c
> @@ -224,7 +224,7 @@ new_ui_command (const char *args, int from_tty)
>  
>      current_ui = ui.get ();
>  
> -    set_top_level_interpreter (interpreter_name);
> +    set_top_level_interpreter (interpreter_name, true);
>  
>      top_level_interpreter ()->pre_command_loop ();
>  
> -- 
> 2.44.0


      reply	other threads:[~2024-05-17 14:11 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-14 13:37 Tom Tromey
2024-05-17 14:11 ` Andrew Burgess [this message]

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=87y188plz4.fsf@redhat.com \
    --to=aburgess@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=tromey@adacore.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).