+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'.
#include "typeprint.h"
#include "namespace.h"
#include "cli/cli-style.h"
+#include "cli/cli-decode.h"
#include "value.h"
#include "mi/mi-common.h"
std::string excep_string;
std::string cond_string;
- tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
+ tempflag = command->context () == CATCH_TEMPORARY;
if (!arg)
arg = "";
std::string excep_string;
std::string cond_string;
- tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
+ tempflag = command->context () == CATCH_TEMPORARY;
if (!arg)
arg = "";
int tempflag;
std::string cond_string;
- tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
+ tempflag = command->context () == CATCH_TEMPORARY;
if (!arg)
arg = "";
#include "cli/cli-utils.h"
#include "completer.h"
#include "cli/cli-style.h"
+#include "cli/cli-decode.h"
#include <string>
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);
#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
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);
#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
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);
}
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);
}
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);
}
#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"
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);
}
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);
{
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 = "";
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);
}
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)
{
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;
}
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;
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;
}
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.
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. */
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);
}
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);
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
#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"
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 ();
}
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);
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. */
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);
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;
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))
{
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));
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));
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;
}
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);
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."));
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)
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);
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);
}
/* 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 ();
#include <unordered_map>
#include "target-connection.h"
#include "valprint.h"
+#include "cli/cli-decode.h"
static void generic_tls_error (void) ATTRIBUTE_NORETURN;
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)
`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);
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);
}
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 ();
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;