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
This commit is contained in:
Simon Marchi 2021-06-25 21:35:40 -04:00
parent ac2d77c6a1
commit 0f8e203412
17 changed files with 69 additions and 62 deletions

View file

@ -1,3 +1,14 @@
2021-06-25 Simon Marchi <simon.marchi@polymtl.ca>
* 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.
2021-06-25 Andrew Burgess <andrew.burgess@embecosm.com>
* NEWS: Mention changes to 'info sources'.

View file

@ -49,6 +49,7 @@
#include "typeprint.h"
#include "namespace.h"
#include "cli/cli-style.h"
#include "cli/cli-decode.h"
#include "value.h"
#include "mi/mi-common.h"
@ -12229,7 +12230,7 @@ catch_ada_exception_command (const char *arg_entry, int from_tty,
std::string excep_string;
std::string cond_string;
tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
tempflag = command->context () == CATCH_TEMPORARY;
if (!arg)
arg = "";
@ -12254,7 +12255,7 @@ catch_ada_handlers_command (const char *arg_entry, int from_tty,
std::string excep_string;
std::string cond_string;
tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
tempflag = command->context () == CATCH_TEMPORARY;
if (!arg)
arg = "";
@ -12322,7 +12323,7 @@ catch_assert_command (const char *arg_entry, int from_tty,
int tempflag;
std::string cond_string;
tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
tempflag = command->context () == CATCH_TEMPORARY;
if (!arg)
arg = "";

View file

@ -29,6 +29,7 @@
#include "cli/cli-utils.h"
#include "completer.h"
#include "cli/cli-style.h"
#include "cli/cli-decode.h"
#include <string>
@ -389,7 +390,7 @@ catch_signal_command (const char *arg, int from_tty,
bool catch_all = false;
std::vector<gdb_signal> filter;
tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
tempflag = command->context () == CATCH_TEMPORARY;
arg = skip_spaces (arg);

View file

@ -30,6 +30,7 @@
#include "observable.h"
#include "xml-syscall.h"
#include "cli/cli-style.h"
#include "cli/cli-decode.h"
/* An instance of this type is used to represent a syscall catchpoint.
A breakpoint is really of this type iff its ops pointer points to
@ -439,7 +440,7 @@ catch_syscall_command_1 (const char *arg, int from_tty,
error (_("The feature 'catch syscall' is not supported on \
this architecture yet."));
tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
tempflag = command->context () == CATCH_TEMPORARY;
arg = skip_spaces (arg);

View file

@ -36,6 +36,7 @@
#include "gdb_regex.h"
#include "cp-support.h"
#include "location.h"
#include "cli/cli-decode.h"
/* Each spot where we may place an exception-related catchpoint has
two names: the SDT probe point and the function name. This
@ -456,7 +457,7 @@ static void
catch_catch_command (const char *arg, int from_tty,
struct cmd_list_element *command)
{
bool tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
bool tempflag = command->context () == CATCH_TEMPORARY;
catch_exception_event (EX_EVENT_CATCH, arg, tempflag, from_tty);
}
@ -467,7 +468,7 @@ static void
catch_throw_command (const char *arg, int from_tty,
struct cmd_list_element *command)
{
bool tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
bool tempflag = command->context () == CATCH_TEMPORARY;
catch_exception_event (EX_EVENT_THROW, arg, tempflag, from_tty);
}
@ -478,7 +479,7 @@ static void
catch_rethrow_command (const char *arg, int from_tty,
struct cmd_list_element *command)
{
bool tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
bool tempflag = command->context () == CATCH_TEMPORARY;
catch_exception_event (EX_EVENT_RETHROW, arg, tempflag, from_tty);
}

View file

@ -67,6 +67,7 @@
#include "thread-fsm.h"
#include "tid-parse.h"
#include "cli/cli-style.h"
#include "cli/cli-decode.h"
/* readline include files */
#include "readline/tilde.h"
@ -8196,7 +8197,7 @@ catch_load_or_unload (const char *arg, int from_tty, int is_load,
struct cmd_list_element *command)
{
const int enabled = 1;
bool temp = get_cmd_context (command) == CATCH_TEMPORARY;
bool temp = command->context () == CATCH_TEMPORARY;
add_solib_catchpoint (arg, is_load, temp, enabled);
}
@ -11280,7 +11281,7 @@ catch_fork_command_1 (const char *arg, int from_tty,
const char *cond_string = NULL;
catch_fork_kind fork_kind;
fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command);
fork_kind = (catch_fork_kind) (uintptr_t) command->context ();
bool temp = (fork_kind == catch_fork_temporary
|| fork_kind == catch_vfork_temporary);
@ -11324,7 +11325,7 @@ catch_exec_command_1 (const char *arg, int from_tty,
{
struct gdbarch *gdbarch = get_current_arch ();
const char *cond_string = NULL;
bool temp = get_cmd_context (command) == CATCH_TEMPORARY;
bool temp = command->context () == CATCH_TEMPORARY;
if (!arg)
arg = "";
@ -15214,13 +15215,13 @@ add_catch_command (const char *name, const char *docstring,
command = add_cmd (name, class_breakpoint, docstring,
&catch_cmdlist);
set_cmd_sfunc (command, sfunc);
set_cmd_context (command, user_data_catch);
command->set_context (user_data_catch);
set_cmd_completer (command, completer);
command = add_cmd (name, class_breakpoint, docstring,
&tcatch_cmdlist);
set_cmd_sfunc (command, sfunc);
set_cmd_context (command, user_data_tcatch);
command->set_context (user_data_tcatch);
set_cmd_completer (command, completer);
}

View file

@ -134,18 +134,6 @@ cmd_cfunc_eq (struct cmd_list_element *cmd, cmd_const_cfunc_ftype *cfunc)
return cmd->func == do_const_cfunc && cmd->function.const_cfunc == 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)
{
@ -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;

View file

@ -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. */

View file

@ -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

View file

@ -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);

View file

@ -253,12 +253,6 @@ extern void set_cmd_completer_handle_brkchars (struct cmd_list_element *,
extern int cmd_cfunc_eq (struct cmd_list_element *cmd,
cmd_const_cfunc_ftype *cfun);
/* Each command object has a local context attached to it. */
extern void set_cmd_context (struct cmd_list_element *cmd,
void *context);
extern void *get_cmd_context (struct cmd_list_element *cmd);
/* Execute CMD's pre/post hook. Throw an error if the command fails.
If already executing this pre/post hook, or there is no pre/post
hook, the call is silently ignored. */

View file

@ -294,7 +294,7 @@ static void
cmdscm_function (struct cmd_list_element *command,
const char *args, int from_tty)
{
command_smob *c_smob/*obj*/ = (command_smob *) get_cmd_context (command);
command_smob *c_smob/*obj*/ = (command_smob *) command->context ();
SCM arg_scm, tty_scm, result;
gdb_assert (c_smob != NULL);
@ -383,7 +383,7 @@ cmdscm_completer (struct cmd_list_element *command,
completion_tracker &tracker,
const char *text, const char *word)
{
command_smob *c_smob/*obj*/ = (command_smob *) get_cmd_context (command);
command_smob *c_smob/*obj*/ = (command_smob *) command->context ();
SCM completer_result_scm;
SCM text_scm, word_scm;
@ -788,7 +788,7 @@ gdbscm_register_command_x (SCM self)
cmd->destroyer = cmdscm_destroyer;
c_smob->command = cmd;
set_cmd_context (cmd, c_smob);
cmd->set_context (c_smob);
if (gdbscm_is_true (c_smob->complete))
{

View file

@ -274,7 +274,7 @@ pascm_signal_setshow_error (SCM exception, const char *msg)
static void
pascm_set_func (const char *args, int from_tty, struct cmd_list_element *c)
{
param_smob *p_smob = (param_smob *) get_cmd_context (c);
param_smob *p_smob = (param_smob *) c->context ();
SCM self, result, exception;
gdb_assert (gdbscm_is_procedure (p_smob->set_func));
@ -314,7 +314,7 @@ static void
pascm_show_func (struct ui_file *file, int from_tty,
struct cmd_list_element *c, const char *value)
{
param_smob *p_smob = (param_smob *) get_cmd_context (c);
param_smob *p_smob = (param_smob *) c->context ();
SCM value_scm, self, result, exception;
gdb_assert (gdbscm_is_procedure (p_smob->show_func));
@ -468,13 +468,13 @@ add_setshow_generic (enum var_types param_type, enum command_class cmd_class,
tmp_name = cmd_name;
param = lookup_cmd (&tmp_name, *show_list, "", NULL, 0, 1);
gdb_assert (param != NULL);
set_cmd_context (param, self);
param->set_context (self);
*set_cmd = param;
tmp_name = cmd_name;
param = lookup_cmd (&tmp_name, *set_list, "", NULL, 0, 1);
gdb_assert (param != NULL);
set_cmd_context (param, self);
param->set_context (self);
*show_cmd = param;
}

View file

@ -103,7 +103,7 @@ static void
cmdpy_function (struct cmd_list_element *command,
const char *args, int from_tty)
{
cmdpy_object *obj = (cmdpy_object *) get_cmd_context (command);
cmdpy_object *obj = (cmdpy_object *) command->context ();
gdbpy_enter enter_py (get_current_arch (), current_language);
@ -172,7 +172,7 @@ static gdbpy_ref<>
cmdpy_completer_helper (struct cmd_list_element *command,
const char *text, const char *word)
{
cmdpy_object *obj = (cmdpy_object *) get_cmd_context (command);
cmdpy_object *obj = (cmdpy_object *) command->context ();
if (obj == NULL)
error (_("Invalid invocation of Python command object."));
@ -532,7 +532,7 @@ cmdpy_init (PyObject *self, PyObject *args, PyObject *kw)
cmd->name_allocated = 1;
obj->command = cmd;
set_cmd_context (cmd, self_ref.release ());
cmd->set_context (self_ref.release ());
set_cmd_completer (cmd, ((completetype == -1) ? cmdpy_completer
: completers[completetype].completer));
if (completetype == -1)

View file

@ -376,7 +376,7 @@ static void
get_set_value (const char *args, int from_tty,
struct cmd_list_element *c)
{
PyObject *obj = (PyObject *) get_cmd_context (c);
PyObject *obj = (PyObject *) c->context ();
gdb::unique_xmalloc_ptr<char> set_doc_string;
gdbpy_enter enter_py (get_current_arch (), current_language);
@ -411,7 +411,7 @@ get_show_value (struct ui_file *file, int from_tty,
struct cmd_list_element *c,
const char *value)
{
PyObject *obj = (PyObject *) get_cmd_context (c);
PyObject *obj = (PyObject *) c->context ();
gdb::unique_xmalloc_ptr<char> show_doc_string;
gdbpy_enter enter_py (get_current_arch (), current_language);
@ -569,8 +569,8 @@ add_setshow_generic (int parmclass, enum command_class cmdclass,
}
/* Register Python objects in both commands' context. */
set_cmd_context (commands.set, self);
set_cmd_context (commands.show, self);
commands.set->set_context (self);
commands.show->set_context (self);
/* We (unfortunately) currently leak the command name. */
cmd_name.release ();

View file

@ -52,6 +52,7 @@
#include <unordered_map>
#include "target-connection.h"
#include "valprint.h"
#include "cli/cli-decode.h"
static void generic_tls_error (void) ATTRIBUTE_NORETURN;
@ -837,7 +838,7 @@ target_log_command (const char *p)
static void
open_target (const char *args, int from_tty, struct cmd_list_element *command)
{
auto *ti = static_cast<target_info *> (get_cmd_context (command));
auto *ti = static_cast<target_info *> (command->context ());
target_open_ftype *func = target_factories[ti];
if (targetdebug)
@ -874,7 +875,7 @@ information on the arguments for a particular protocol, type\n\
`help target ' followed by the protocol name."),
&targetlist, 0, &cmdlist);
c = add_cmd (t.shortname, no_class, t.doc, &targetlist);
set_cmd_context (c, (void *) &t);
c->set_context ((void *) &t);
set_cmd_sfunc (c, open_target);
if (completer != NULL)
set_cmd_completer (c, completer);
@ -892,7 +893,7 @@ add_deprecated_target_alias (const target_info &tinfo, const char *alias)
see PR cli/15104. */
c = add_cmd (alias, no_class, tinfo.doc, &targetlist);
set_cmd_sfunc (c, open_target);
set_cmd_context (c, (void *) &tinfo);
c->set_context ((void *) &tinfo);
alt = xstrprintf ("target %s", tinfo.shortname);
deprecate_cmd (c, alt);
}

View file

@ -172,8 +172,7 @@ static void
tui_apply_layout (struct cmd_list_element *command,
const char *args, int from_tty)
{
tui_layout_split *layout
= (tui_layout_split *) get_cmd_context (command);
tui_layout_split *layout = (tui_layout_split *) command->context ();
/* Make sure the curses mode is enabled. */
tui_enable ();
@ -858,7 +857,7 @@ This layout was created using:\n\
name, name, spec.c_str ()));
cmd = add_cmd (name, class_tui, nullptr, doc.get (), &layout_list);
set_cmd_context (cmd, layout);
cmd->set_context (layout);
/* There is no API to set this. */
cmd->func = tui_apply_layout;
cmd->destroyer = destroy_layout;