]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb: add context getter/setter to cmd_list_element
authorSimon Marchi <simon.marchi@polymtl.ca>
Sat, 26 Jun 2021 01:35:40 +0000 (21:35 -0400)
committerSimon Marchi <simon.marchi@polymtl.ca>
Sat, 26 Jun 2021 01:35:40 +0000 (21:35 -0400)
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

17 files changed:
gdb/ChangeLog
gdb/ada-lang.c
gdb/break-catch-sig.c
gdb/break-catch-syscall.c
gdb/break-catch-throw.c
gdb/breakpoint.c
gdb/cli/cli-decode.c
gdb/cli/cli-decode.h
gdb/cli/cli-dump.c
gdb/cli/cli-style.c
gdb/command.h
gdb/guile/scm-cmd.c
gdb/guile/scm-param.c
gdb/python/py-cmd.c
gdb/python/py-param.c
gdb/target.c
gdb/tui/tui-layout.c

index 41f98e81287fae70ef7ebef6cd9c0dd99b709076..c523186cdd7986cad4521cb94c269a5ad4cc3018 100644 (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'.
index f2270c0f6afe65d2d1c997e13c6a9d3fe197b8a7..b098991612d08ae9db1cf9050ac18df700117885 100644 (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 = "";
index 9530dea86ba4ab192f3b94192d6929f62d9b688e..5c7d62fe1ecd741400ddc0902bb1752c35410548 100644 (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);
 
index 9100ac6d544415c03c59babfb9c60dd724798cff..78e7079a831b8f3163b9f1686161bfc3dd44fbfc 100644 (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);
 
index 7fc6953b90cd597a871f81d5ab4509920a4cd8f8..f05c2f8a64807071ddc77158bd28641794546967 100644 (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);
 }
index 0595c6f8cbd49aad4b34f567a950451bd0ccff28..dbbea6b8bff79016e25c0d92ec4b3f59477e184b 100644 (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);
 }
 
index 009986c9cb1056287177a4c225213fcadb6748ac..f2fdeb03a285554c24aa223a612832246cd47e3d 100644 (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;
index 9328659775ca83fa8e09c8a7881bc81323cf7ee1..1692a6e28352042f085e2e0ade5b7c196ef14b80 100644 (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.  */
index 95ce85e1c44995b7629e374f2e6cc0a9f163b399..efb400418042fc8c67cc2a74d3c33979edff051b 100644 (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
index 25a1d888f860508be901fe2bc854c4c8e258c1d4..0b88dba562278a3fcae38282e23e6efb74ce85a8 100644 (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);
index f8988e4149438486df70763d47b6e3faba58f348..9413a50c297144c8b8ea4d706c39120d410fcad6 100644 (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.  */
index 39c915e0ab226e525e6f0df812ecce8323a5f0ed..ab3dad7483ccccc2579a1a3d6b78c97b5653706d 100644 (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))
     {
index 5f02e13ae49a5a8be301ca695c0ba92ed772ea34..86f61057a32f843c96921ee3102505fd6056bbbe 100644 (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;
 }
 
index 4f01fc0b5f35d71cf2b22665da8ea5a914d45c42..0467ebd673490fea333c099bf74598f7f96cb5b5 100644 (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)
index d0a4850bdc04c63e5afa66973201aaabaf5c6bcc..f9dcb076c60396de56a4dd52bfd147dad9145b67 100644 (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 ();
index 6babfc562563d6d09dddcbb955ecaa11a9171fb6..767685fbca39bf9906bf10f1c480371e62b9fd89 100644 (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);
 }
index b54e748194576de1cc249a485cd9c81d1c423bec..f9c94dea96cd46b863c029f253c51ec4fcc3a453 100644 (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;