public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@efficios.com>
To: gdb-patches@sourceware.org
Cc: Simon Marchi <simon.marchi@efficios.com>
Subject: [PATCH 07/21] gdb: add backlink to ui in interp
Date: Fri,  8 Sep 2023 14:23:01 -0400	[thread overview]
Message-ID: <20230908190227.96319-8-simon.marchi@efficios.com> (raw)
In-Reply-To: <20230908190227.96319-1-simon.marchi@efficios.com>

Interps are bound to a single parent UI.  Pass this UI down when
constructing interps, so that they'll be able to use it internally,
instead of using current_ui.

Change-Id: Ife900d501ae26d1a7a1d06b1d5f4013917235d7a
---
 gdb/cli/cli-interp.c | 14 +++++++-------
 gdb/cli/cli-interp.h |  2 +-
 gdb/interps.c        |  5 +++--
 gdb/interps.h        |  7 +++++--
 gdb/mi/mi-interp.c   |  4 ++--
 gdb/mi/mi-interp.h   |  4 ++--
 gdb/python/py-dap.c  |  8 ++++----
 gdb/tui/tui-interp.c |  8 ++++----
 gdb/ui.c             |  2 +-
 9 files changed, 29 insertions(+), 25 deletions(-)

diff --git a/gdb/cli/cli-interp.c b/gdb/cli/cli-interp.c
index 6a175f7baa13..374d379ec7a3 100644
--- a/gdb/cli/cli-interp.c
+++ b/gdb/cli/cli-interp.c
@@ -31,8 +31,8 @@
 #include "thread-fsm.h"
 #include "inferior.h"
 
-cli_interp_base::cli_interp_base (const char *name)
-  : interp (name)
+cli_interp_base::cli_interp_base (ui *ui, const char *name)
+  : interp (ui, name)
 {}
 
 cli_interp_base::~cli_interp_base ()
@@ -43,7 +43,7 @@ cli_interp_base::~cli_interp_base ()
 class cli_interp final : public cli_interp_base
 {
  public:
-  explicit cli_interp (const char *name);
+  explicit cli_interp (ui *ui, const char *name);
   ~cli_interp () = default;
 
   void init (bool top_level) override;
@@ -58,8 +58,8 @@ class cli_interp final : public cli_interp_base
   std::unique_ptr<cli_ui_out> m_cli_uiout;
 };
 
-cli_interp::cli_interp (const char *name)
-  : cli_interp_base (name),
+cli_interp::cli_interp (ui *ui, const char *name)
+  : cli_interp_base (ui, name),
     m_cli_uiout (new cli_ui_out (gdb_stdout))
 {
 }
@@ -317,9 +317,9 @@ cli_interp_base::set_logging (ui_file_up logfile, bool logging_redirect,
 /* Factory for CLI interpreters.  */
 
 static struct interp *
-cli_interp_factory (const char *name)
+cli_interp_factory (ui *ui, const char *name)
 {
-  return new cli_interp (name);
+  return new cli_interp (ui, name);
 }
 
 /* Standard gdb initialization hook.  */
diff --git a/gdb/cli/cli-interp.h b/gdb/cli/cli-interp.h
index a1a20b678942..b92a49b3fc40 100644
--- a/gdb/cli/cli-interp.h
+++ b/gdb/cli/cli-interp.h
@@ -25,7 +25,7 @@
 class cli_interp_base : public interp
 {
 public:
-  explicit cli_interp_base (const char *name);
+  explicit cli_interp_base (ui *ui, const char *name);
   virtual ~cli_interp_base () = 0;
 
   void set_logging (ui_file_up logfile, bool logging_redirect,
diff --git a/gdb/interps.c b/gdb/interps.c
index 9d27d6a2bd2c..0575128b8124 100644
--- a/gdb/interps.c
+++ b/gdb/interps.c
@@ -41,8 +41,9 @@
 #include "gdbsupport/buildargv.h"
 #include "gdbsupport/scope-exit.h"
 
-interp::interp (const char *name)
-  : m_name (name)
+interp::interp (ui *ui, const char *name)
+  : m_ui (ui),
+    m_name (name)
 {
 }
 
diff --git a/gdb/interps.h b/gdb/interps.h
index 433d92439eba..278ee5aff9a5 100644
--- a/gdb/interps.h
+++ b/gdb/interps.h
@@ -34,7 +34,7 @@ struct inferior;
 struct so_list;
 struct trace_state_variable;
 
-typedef struct interp *(*interp_factory_func) (const char *name);
+using interp_factory_func = interp *(*) (ui *ui, const char *name);
 
 /* An interpreter factory.  Maps an interpreter name to the factory
    function that instantiates an interpreter by that name.  */
@@ -69,7 +69,7 @@ extern void interp_exec (struct interp *interp, const char *command);
 class interp : public intrusive_list_node<interp>
 {
 public:
-  explicit interp (const char *name);
+  explicit interp (ui *ui, const char *name);
   virtual ~interp () = 0;
 
   virtual void init (bool top_level)
@@ -202,6 +202,9 @@ class interp : public intrusive_list_node<interp>
   /* Notify the interpreter that inferior INF's memory was changed.  */
   virtual void on_memory_changed (inferior *inf, CORE_ADDR addr, ssize_t len,
 				  const bfd_byte *data) {}
+protected:
+  /* Backlink to the UI owning this interpreter.  */
+  ui *m_ui;
 
 private:
   /* The memory for this is static, it comes from literal strings (e.g. "cli").  */
diff --git a/gdb/mi/mi-interp.c b/gdb/mi/mi-interp.c
index 946fed5867c4..be9dacaf9304 100644
--- a/gdb/mi/mi-interp.c
+++ b/gdb/mi/mi-interp.c
@@ -925,9 +925,9 @@ mi_interp::set_logging (ui_file_up logfile, bool logging_redirect,
 /* Factory for MI interpreters.  */
 
 static struct interp *
-mi_interp_factory (const char *name)
+mi_interp_factory (ui *ui, const char *name)
 {
-  return new mi_interp (name);
+  return new mi_interp (ui, name);
 }
 
 void _initialize_mi_interp ();
diff --git a/gdb/mi/mi-interp.h b/gdb/mi/mi-interp.h
index f9af61f0a571..54ba70bdab88 100644
--- a/gdb/mi/mi-interp.h
+++ b/gdb/mi/mi-interp.h
@@ -29,8 +29,8 @@ struct mi_console_file;
 class mi_interp final : public interp
 {
 public:
-  mi_interp (const char *name)
-    : interp (name)
+  mi_interp (ui *ui, const char *name)
+    : interp (ui, name)
   {}
 
   void init (bool top_level) override;
diff --git a/gdb/python/py-dap.c b/gdb/python/py-dap.c
index 3444eccb6fb6..724a4925938c 100644
--- a/gdb/python/py-dap.c
+++ b/gdb/python/py-dap.c
@@ -27,8 +27,8 @@ class dap_interp final : public interp
 {
 public:
 
-  explicit dap_interp (const char *name)
-    : interp (name),
+  explicit dap_interp (ui *ui, const char *name)
+    : interp (ui, name),
       m_ui_out (new cli_ui_out (gdb_stdout))
   {
   }
@@ -93,9 +93,9 @@ _initialize_py_interp ()
 {
   /* The dap code uses module typing, available starting python 3.5.  */
 #if PY_VERSION_HEX >= 0x03050000
-  interp_factory_register ("dap", [] (const char *name) -> interp *
+  interp_factory_register ("dap", [] (ui *ui, const char *name) -> interp *
     {
-      return new dap_interp (name);
+      return new dap_interp (ui, name);
     });
 #endif
 }
diff --git a/gdb/tui/tui-interp.c b/gdb/tui/tui-interp.c
index 299cc4caea09..227b37f374dc 100644
--- a/gdb/tui/tui-interp.c
+++ b/gdb/tui/tui-interp.c
@@ -42,8 +42,8 @@ static bool tui_start_enabled = false;
 class tui_interp final : public cli_interp_base
 {
 public:
-  explicit tui_interp (const char *name)
-    : cli_interp_base (name)
+  explicit tui_interp (ui *ui, const char *name)
+    : cli_interp_base (ui, name)
   {}
 
   void init (bool top_level) override;
@@ -159,9 +159,9 @@ tui_interp::exec (const char *command_str)
 /* Factory for TUI interpreters.  */
 
 static struct interp *
-tui_interp_factory (const char *name)
+tui_interp_factory (ui *ui, const char *name)
 {
-  return new tui_interp (name);
+  return new tui_interp (ui, name);
 }
 
 void _initialize_tui_interp ();
diff --git a/gdb/ui.c b/gdb/ui.c
index 4bb63ed63030..8c04dc92b89e 100644
--- a/gdb/ui.c
+++ b/gdb/ui.c
@@ -164,7 +164,7 @@ ui::lookup_interp (const char *name)
   if (factory == nullptr)
     return nullptr;
 
-  interp *interp = factory->func (factory->name);
+  interp *interp = factory->func (this, factory->name);
   this->interp_list.push_back (*interp);
 
   return interp;
-- 
2.42.0


  parent reply	other threads:[~2023-09-08 19:02 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 ` Simon Marchi [this message]
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
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=20230908190227.96319-8-simon.marchi@efficios.com \
    --to=simon.marchi@efficios.com \
    --cc=gdb-patches@sourceware.org \
    /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).