[02/21] gdb: make interp_lookup_existing a method of struct ui

Message ID 20230908190227.96319-3-simon.marchi@efficios.com
State New
Headers
Series ui / interp cleansup |

Commit Message

Simon Marchi Sept. 8, 2023, 6:22 p.m. UTC
  No behavior changes expected.

Change-Id: I2bd15b70425326a3b499b9346217b93f76175999
---
 gdb/interps.c | 22 ++--------------------
 gdb/ui.c      | 12 ++++++++++++
 gdb/ui.h      |  4 ++++
 3 files changed, 18 insertions(+), 20 deletions(-)
  

Patch

diff --git a/gdb/interps.c b/gdb/interps.c
index adac98125239..3ddcfe9566fe 100644
--- a/gdb/interps.c
+++ b/gdb/interps.c
@@ -41,11 +41,6 @@ 
 #include "gdbsupport/buildargv.h"
 #include "gdbsupport/scope-exit.h"
 
-/* The magic initialization routine for this module.  */
-
-static struct interp *interp_lookup_existing (struct ui *ui,
-					      const char *name);
-
 interp::interp (const char *name)
   : m_name (name)
 {
@@ -93,7 +88,7 @@  interp_factory_register (const char *name, interp_factory_func func)
 static void
 interp_add (struct ui *ui, struct interp *interp)
 {
-  gdb_assert (interp_lookup_existing (ui, interp->name ()) == NULL);
+  gdb_assert (ui->lookup_existing_interp (interp->name ()) == nullptr);
 
   ui->interp_list.push_back (*interp);
 }
@@ -158,19 +153,6 @@  interp_set (struct interp *interp, bool top_level)
 	       "to a newer version of MI."));
 }
 
-/* Look up the interpreter for NAME.  If no such interpreter exists,
-   return NULL, otherwise return a pointer to the interpreter.  */
-
-static struct interp *
-interp_lookup_existing (struct ui *ui, const char *name)
-{
-  for (interp &interp : ui->interp_list)
-    if (strcmp (interp.name (), name) == 0)
-      return &interp;
-
-  return nullptr;
-}
-
 /* See interps.h.  */
 
 struct interp *
@@ -180,7 +162,7 @@  interp_lookup (struct ui *ui, const char *name)
     return NULL;
 
   /* Only create each interpreter once per top level.  */
-  struct interp *interp = interp_lookup_existing (ui, name);
+  interp *interp = ui->lookup_existing_interp (name);
   if (interp != NULL)
     return interp;
 
diff --git a/gdb/ui.c b/gdb/ui.c
index f3dd14bfd3e0..ae87dcda2453 100644
--- a/gdb/ui.c
+++ b/gdb/ui.c
@@ -147,6 +147,18 @@  ui::register_file_handler ()
 		      string_printf ("ui-%d", num), true);
 }
 
+/* See ui.h.  */
+
+interp *
+ui::lookup_existing_interp (const char *name) const
+{
+  for (interp &interp : this->interp_list)
+    if (strcmp (interp.name (), name) == 0)
+      return &interp;
+
+  return nullptr;
+}
+
 /* See top.h.  */
 
 void
diff --git a/gdb/ui.h b/gdb/ui.h
index c5e65c0393d8..23c6b2e1a3d9 100644
--- a/gdb/ui.h
+++ b/gdb/ui.h
@@ -158,6 +158,10 @@  struct ui : public intrusive_list_node<ui>
 
   /* Return true if this UI's input fd is a tty.  */
   bool input_interactive_p () const;
+
+  /* Look up the interpreter for NAME.  If no such interpreter exists,
+     return nullptr, otherwise return a pointer to the interpreter.  */
+  interp *lookup_existing_interp (const char *name) const;
 };
 
 /* The main UI.  This is the UI that is bound to stdin/stdout/stderr.