From: Simon Marchi <simon.marchi@efficios.com>
To: gdb-patches@sourceware.org
Cc: Simon Marchi <simon.marchi@efficios.com>
Subject: [PATCH 3/3] gdb: remove ui_interp_info
Date: Fri, 28 Apr 2023 14:27:13 -0400 [thread overview]
Message-ID: <20230428182713.216446-4-simon.marchi@efficios.com> (raw)
In-Reply-To: <20230428182713.216446-1-simon.marchi@efficios.com>
I don't think that having struct ui_interp_info separated from struct ui
is very useful. As of today, it looks like an unnecessary indirection
layer. Move the contents of ui_interp_info directly into struct ui, and
update all users.
Change-Id: I817ba6e047dbcc4ba15b666af184b40bfed7e521
---
gdb/interps.c | 91 +++++++++++----------------------------------------
gdb/ui.h | 11 ++++++-
2 files changed, 30 insertions(+), 72 deletions(-)
diff --git a/gdb/interps.c b/gdb/interps.c
index 54e1cb45db68..e3f6ee685123 100644
--- a/gdb/interps.c
+++ b/gdb/interps.c
@@ -41,41 +41,6 @@
#include "gdbsupport/buildargv.h"
#include "gdbsupport/scope-exit.h"
-/* Each UI has its own independent set of interpreters. */
-
-struct ui_interp_info
-{
- ui_interp_info () = default;
- DISABLE_COPY_AND_ASSIGN (ui_interp_info);
-
- /* Each top level has its own independent set of interpreters. */
- intrusive_list<interp> interp_list;
- interp *current_interpreter = nullptr;
- interp *top_level_interpreter = nullptr;
-
- /* The interpreter that is active while `interp_exec' is active, NULL
- at all other times. */
- interp *command_interpreter = nullptr;
-};
-
-/* Get UI's ui_interp_info object. */
-
-static ui_interp_info &
-get_interp_info (struct ui *ui)
-{
- if (ui->interp_info == NULL)
- ui->interp_info = new ui_interp_info;
- return *ui->interp_info;
-}
-
-/* Get the current UI's ui_interp_info object. */
-
-static ui_interp_info &
-get_current_interp_info (void)
-{
- return get_interp_info (current_ui);
-}
-
/* The magic initialization routine for this module. */
static struct interp *interp_lookup_existing (struct ui *ui,
@@ -128,11 +93,9 @@ interp_factory_register (const char *name, interp_factory_func func)
static void
interp_add (struct ui *ui, struct interp *interp)
{
- ui_interp_info &ui_interp = get_interp_info (ui);
-
gdb_assert (interp_lookup_existing (ui, interp->name ()) == NULL);
- ui_interp.interp_list.push_back (*interp);
+ ui->interp_list.push_back (*interp);
}
/* This sets the current interpreter to be INTERP. If INTERP has not
@@ -149,13 +112,12 @@ interp_add (struct ui *ui, struct interp *interp)
static void
interp_set (struct interp *interp, bool top_level)
{
- ui_interp_info &ui_interp = get_current_interp_info ();
- struct interp *old_interp = ui_interp.current_interpreter;
+ struct interp *old_interp = current_ui->current_interpreter;
/* If we already have an interpreter, then trying to
set top level interpreter is kinda pointless. */
- gdb_assert (!top_level || !ui_interp.current_interpreter);
- gdb_assert (!top_level || !ui_interp.top_level_interpreter);
+ gdb_assert (!top_level || !current_ui->current_interpreter);
+ gdb_assert (!top_level || !current_ui->top_level_interpreter);
if (old_interp != NULL)
{
@@ -163,9 +125,9 @@ interp_set (struct interp *interp, bool top_level)
old_interp->suspend ();
}
- ui_interp.current_interpreter = interp;
+ current_ui->current_interpreter = interp;
if (top_level)
- ui_interp.top_level_interpreter = interp;
+ current_ui->top_level_interpreter = interp;
if (interpreter_p != interp->name ())
interpreter_p = interp->name ();
@@ -202,9 +164,7 @@ interp_set (struct interp *interp, bool top_level)
static struct interp *
interp_lookup_existing (struct ui *ui, const char *name)
{
- ui_interp_info &ui_interp = get_interp_info (ui);
-
- for (interp &interp : ui_interp.interp_list)
+ for (interp &interp : ui->interp_list)
if (strcmp (interp.name (), name) == 0)
return &interp;
@@ -253,8 +213,7 @@ void
current_interp_set_logging (ui_file_up logfile, bool logging_redirect,
bool debug_redirect)
{
- ui_interp_info &ui_interp = get_current_interp_info ();
- struct interp *interp = ui_interp.current_interpreter;
+ struct interp *interp = current_ui->current_interpreter;
interp->set_logging (std::move (logfile), logging_redirect, debug_redirect);
}
@@ -263,12 +222,12 @@ current_interp_set_logging (ui_file_up logfile, bool logging_redirect,
struct interp *
scoped_restore_interp::set_interp (const char *name)
{
- ui_interp_info &ui_interp = get_current_interp_info ();
struct interp *interp = interp_lookup (current_ui, name);
- struct interp *old_interp = ui_interp.current_interpreter;
+ struct interp *old_interp = current_ui->current_interpreter;
if (interp)
- ui_interp.current_interpreter = interp;
+ current_ui->current_interpreter = interp;
+
return old_interp;
}
@@ -276,8 +235,7 @@ scoped_restore_interp::set_interp (const char *name)
int
current_interp_named_p (const char *interp_name)
{
- ui_interp_info &ui_interp = get_current_interp_info ();
- struct interp *interp = ui_interp.current_interpreter;
+ interp *interp = current_ui->current_interpreter;
if (interp != NULL)
return (strcmp (interp->name (), interp_name) == 0);
@@ -298,12 +256,10 @@ current_interp_named_p (const char *interp_name)
struct interp *
command_interp (void)
{
- ui_interp_info &ui_interp = get_current_interp_info ();
-
- if (ui_interp.command_interpreter != NULL)
- return ui_interp.command_interpreter;
+ if (current_ui->command_interpreter != nullptr)
+ return current_ui->command_interpreter;
else
- return ui_interp.current_interpreter;
+ return current_ui->current_interpreter;
}
/* See interps.h. */
@@ -330,11 +286,9 @@ interp_supports_command_editing (struct interp *interp)
void
interp_exec (struct interp *interp, const char *command_str)
{
- ui_interp_info &ui_interp = get_current_interp_info ();
-
/* See `command_interp' for why we do this. */
scoped_restore save_command_interp
- = make_scoped_restore (&ui_interp.command_interpreter, interp);
+ = make_scoped_restore (¤t_ui->command_interpreter, interp);
interp->exec (command_str);
}
@@ -359,8 +313,7 @@ clear_interpreter_hooks (void)
static void
interpreter_exec_cmd (const char *args, int from_tty)
{
- ui_interp_info &ui_interp = get_current_interp_info ();
- struct interp *old_interp, *interp_to_use;
+ struct interp *interp_to_use;
unsigned int nrules;
unsigned int i;
@@ -381,7 +334,7 @@ interpreter_exec_cmd (const char *args, int from_tty)
if (nrules < 2)
error (_("Usage: interpreter-exec INTERPRETER COMMAND..."));
- old_interp = ui_interp.current_interpreter;
+ interp *old_interp = current_ui->current_interpreter;
interp_to_use = interp_lookup (current_ui, prules[0]);
if (interp_to_use == NULL)
@@ -419,9 +372,7 @@ interpreter_completer (struct cmd_list_element *ignore,
struct interp *
top_level_interpreter (void)
{
- ui_interp_info &ui_interp = get_current_interp_info ();
-
- return ui_interp.top_level_interpreter;
+ return current_ui->top_level_interpreter;
}
/* See interps.h. */
@@ -429,9 +380,7 @@ top_level_interpreter (void)
struct interp *
current_interpreter (void)
{
- ui_interp_info &ui_interp = get_interp_info (current_ui);
-
- return ui_interp.current_interpreter;
+ return current_ui->current_interpreter;
}
/* This just adds the "interpreter-exec" command. */
diff --git a/gdb/ui.h b/gdb/ui.h
index 8da4b2d8eeed..ed75e041e5f2 100644
--- a/gdb/ui.h
+++ b/gdb/ui.h
@@ -19,8 +19,11 @@
#define UI_H
#include "gdbsupport/event-loop.h"
+#include "gdbsupport/intrusive_list.h"
#include "gdbsupport/next-iterator.h"
+struct interp;
+
/* Prompt state. */
enum prompt_state
@@ -84,7 +87,13 @@ struct ui
int command_editing = 0;
/* Each UI has its own independent set of interpreters. */
- struct ui_interp_info *interp_info = nullptr;
+ intrusive_list<interp> interp_list;
+ interp *current_interpreter = nullptr;
+ interp *top_level_interpreter = nullptr;
+
+ /* The interpreter that is active while `interp_exec' is active, NULL
+ at all other times. */
+ interp *command_interpreter = nullptr;
/* True if the UI is in async mode, false if in sync mode. If in
sync mode, a synchronous execution command (e.g, "next") does not
--
2.40.1
next prev parent reply other threads:[~2023-04-28 18:27 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-28 18:27 [PATCH 0/3] Some struct ui / struct interps cleanup Simon Marchi
2023-04-28 18:27 ` [PATCH 1/3] gdb: move struct ui and related things to ui.{c,h} Simon Marchi
2023-04-28 18:27 ` [PATCH 2/3] gdb: store interps in an intrusive_list Simon Marchi
2023-04-28 18:27 ` Simon Marchi [this message]
2023-05-01 15:25 ` [PATCH 0/3] Some struct ui / struct interps cleanup Tom Tromey
2023-05-02 0:49 ` Simon Marchi
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=20230428182713.216446-4-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).