aboutsummaryrefslogtreecommitdiff
path: root/gdb/cli
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@polymtl.ca>2021-06-25 21:35:40 -0400
committerSimon Marchi <simon.marchi@polymtl.ca>2021-06-25 21:35:40 -0400
commit0f8e2034128e4a73e02cb8311eeeea7e886a5985 (patch)
tree609b9baf7a5f167daa28b0341743aa650677f28a /gdb/cli
parentac2d77c6a102ca785aae565aec93a3478a9f4544 (diff)
downloadgdb-0f8e2034128e4a73e02cb8311eeeea7e886a5985.zip
gdb-0f8e2034128e4a73e02cb8311eeeea7e886a5985.tar.gz
gdb-0f8e2034128e4a73e02cb8311eeeea7e886a5985.tar.bz2
gdb: add context getter/setter to cmd_list_element
Straightforward replacement of get_cmd_context / set_cmd_context with cmd_list_element methods. gdb/ChangeLog: * cli/cli-decode.h (struct cmd_list_element) <set_context, context>: New. <context>: Rename to... <m_context>: ... this. * cli/cli-decode.c (set_cmd_context, get_cmd_context): Remove. * command.h (set_cmd_context, get_cmd_context): Remove, use cmd_list_element::set_context and cmd_list_element::context everywhere instead. Change-Id: I5016b0079014e3f17d1aa449ada7954473bf2b5d
Diffstat (limited to 'gdb/cli')
-rw-r--r--gdb/cli/cli-decode.c19
-rw-r--r--gdb/cli/cli-decode.h13
-rw-r--r--gdb/cli/cli-dump.c6
-rw-r--r--gdb/cli/cli-style.c5
4 files changed, 20 insertions, 23 deletions
diff --git a/gdb/cli/cli-decode.c b/gdb/cli/cli-decode.c
index 009986c..f2fdeb0 100644
--- a/gdb/cli/cli-decode.c
+++ b/gdb/cli/cli-decode.c
@@ -135,18 +135,6 @@ cmd_cfunc_eq (struct cmd_list_element *cmd, cmd_const_cfunc_ftype *cfunc)
}
void
-set_cmd_context (struct cmd_list_element *cmd, void *context)
-{
- cmd->context = context;
-}
-
-void *
-get_cmd_context (struct cmd_list_element *cmd)
-{
- return cmd->context;
-}
-
-void
set_cmd_completer (struct cmd_list_element *cmd, completer_ftype *completer)
{
cmd->completer = completer; /* Ok. */
@@ -593,8 +581,8 @@ add_setshow_enum_cmd (const char *name,
set_list, show_list);
commands.set->enums = enumlist;
- set_cmd_context (commands.set, context);
- set_cmd_context (commands.show, context);
+ commands.set->set_context (context);
+ commands.show->set_context (context);
return commands;
}
@@ -920,7 +908,8 @@ delete_cmd (const char *name, struct cmd_list_element **list,
if (strcmp (iter->name, name) == 0)
{
if (iter->destroyer)
- iter->destroyer (iter, iter->context);
+ iter->destroyer (iter, iter->context ());
+
if (iter->hookee_pre)
iter->hookee_pre->hook_pre = 0;
*prehook = iter->hook_pre;
diff --git a/gdb/cli/cli-decode.h b/gdb/cli/cli-decode.h
index 9328659..1692a6e 100644
--- a/gdb/cli/cli-decode.h
+++ b/gdb/cli/cli-decode.h
@@ -93,6 +93,12 @@ struct cmd_list_element
bool is_command_class_help () const
{ return this->func == nullptr; }
+ void set_context (void *context)
+ { m_context = context; }
+
+ void *context () const
+ { return m_context; }
+
/* Points to next command in this list. */
struct cmd_list_element *next = nullptr;
@@ -173,9 +179,6 @@ struct cmd_list_element
}
function;
- /* Local state (context) for this command. This can be anything. */
- void *context = nullptr;
-
/* Documentation of this command (or help topic).
First line is brief documentation; remaining lines form, with it,
the full documentation. First line should end with a period.
@@ -256,6 +259,10 @@ struct cmd_list_element
when this command is being executed. It will be set back to false
when the command has been executed. */
int *suppress_notification = nullptr;
+
+private:
+ /* Local state (context) for this command. This can be anything. */
+ void *m_context = nullptr;
};
/* Functions that implement commands about CLI commands. */
diff --git a/gdb/cli/cli-dump.c b/gdb/cli/cli-dump.c
index 95ce85e..efb4004 100644
--- a/gdb/cli/cli-dump.c
+++ b/gdb/cli/cli-dump.c
@@ -333,7 +333,7 @@ struct dump_context
static void
call_dump_func (struct cmd_list_element *c, const char *args, int from_tty)
{
- struct dump_context *d = (struct dump_context *) get_cmd_context (c);
+ struct dump_context *d = (struct dump_context *) c->context ();
d->func (args, d->mode);
}
@@ -352,7 +352,7 @@ add_dump_command (const char *name,
d = XNEW (struct dump_context);
d->func = func;
d->mode = FOPEN_WB;
- set_cmd_context (c, d);
+ c->set_context (d);
c->func = call_dump_func;
c = add_cmd (name, all_commands, descr, &append_cmdlist);
@@ -360,7 +360,7 @@ add_dump_command (const char *name,
d = XNEW (struct dump_context);
d->func = func;
d->mode = FOPEN_AB;
- set_cmd_context (c, d);
+ c->set_context (d);
c->func = call_dump_func;
/* Replace "Dump " at start of docstring with "Append " (borrowed
diff --git a/gdb/cli/cli-style.c b/gdb/cli/cli-style.c
index 25a1d88..0b88dba 100644
--- a/gdb/cli/cli-style.c
+++ b/gdb/cli/cli-style.c
@@ -19,6 +19,7 @@
#include "defs.h"
#include "cli/cli-cmds.h"
+#include "cli/cli-decode.h"
#include "cli/cli-setshow.h"
#include "cli/cli-style.h"
#include "source-cache.h"
@@ -167,7 +168,7 @@ void
cli_style_option::do_set_value (const char *ignore, int from_tty,
struct cmd_list_element *cmd)
{
- cli_style_option *cso = (cli_style_option *) get_cmd_context (cmd);
+ cli_style_option *cso = (cli_style_option *) cmd->context ();
cso->changed.notify ();
}
@@ -180,7 +181,7 @@ do_show (const char *what, struct ui_file *file,
struct cmd_list_element *cmd,
const char *value)
{
- cli_style_option *cso = (cli_style_option *) get_cmd_context (cmd);
+ cli_style_option *cso = (cli_style_option *) cmd->context ();
fputs_filtered (_("The "), file);
fprintf_styled (file, cso->style (), _("\"%s\" style"), cso->name ());
fprintf_filtered (file, _(" %s is: %s\n"), what, value);