From: Simon Marchi via Gdb-patches <gdb-patches@sourceware.org>
To: gdb-patches@sourceware.org
Subject: [PATCH 12/16] gdb: rename cfunc to simple_func
Date: Wed, 14 Jul 2021 00:55:16 -0400 [thread overview]
Message-ID: <20210714045520.1623120-13-simon.marchi@polymtl.ca> (raw)
In-Reply-To: <20210714045520.1623120-1-simon.marchi@polymtl.ca>
After browsing the CLI code for quite a while and trying really hard, I
reached the conclusion that I can't give a meaningful explanation of
what "sfunc" and "cfunc" functions are, in cmd_list_element. I don't
see a logic at all. That makes it very difficult to do any kind of
change. Unless somebody can make sense out of all that, I'd like to try
to retro-fit some logic in the cmd_list_element callback function code
so that we can understand what is going on, do some cleanups and add new
features.
The first change is about "cfunc". I can't figure out what the "c" in
cfunc means. It's not const, because there's already "const" in
"cmd_const_cfunc_ftype", and the previous "cmd_cfunc_ftype" had nothing
const.. It's not "cmd" or "command", because there's already "cmd" in
"cmd_const_cfunc_ftype".
The "main" command callback, cmd_list_element::func, has three
parameters, whereas cfunc has two. It is missing the cmd_list_element
parameter. So the only reason I see for cfunc to exist is to be a shim
between the three and two parameter versions. Most commands don't need
to receive the cmd_list_element object, so adding it everywhere would be
long and would just add more unnecessary boilerplate. So since this is
the "simple" version of the callback, compared to the "full", I suggest
renaming cmd_const_cfunc_ftype into cmd_simple_func_ftype, as well as
everything (like the utility functions) that goes with it.
Change-Id: I4e46cacfd77a66bc1cbf683f6a362072504b7868
---
gdb/cli/cli-cmds.c | 2 +-
gdb/cli/cli-decode.c | 44 +++++++++++++++++++++++---------------------
gdb/cli/cli-decode.h | 8 ++++++--
gdb/command.h | 25 ++++++++++++++-----------
gdb/tracepoint.c | 18 +++++++++---------
5 files changed, 53 insertions(+), 44 deletions(-)
diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c
index 56ae12a0c19d..5ff0b77eb68f 100644
--- a/gdb/cli/cli-cmds.c
+++ b/gdb/cli/cli-cmds.c
@@ -443,7 +443,7 @@ complete_command (const char *arg, int from_tty)
int
is_complete_command (struct cmd_list_element *c)
{
- return cmd_cfunc_eq (c, complete_command);
+ return cmd_simple_func_eq (c, complete_command);
}
static void
diff --git a/gdb/cli/cli-decode.c b/gdb/cli/cli-decode.c
index 633a3ad93095..3c39e47ac69b 100644
--- a/gdb/cli/cli-decode.c
+++ b/gdb/cli/cli-decode.c
@@ -94,22 +94,23 @@ print_help_for_command (struct cmd_list_element *c,
\f
/* Set the callback function for the specified command. For each both
the commands callback and func() are set. The latter set to a
- bounce function (unless cfunc / sfunc is NULL that is). */
+ bounce function (unless simple_func / sfunc is NULL that is). */
static void
-do_const_cfunc (struct cmd_list_element *c, const char *args, int from_tty)
+do_simple_func (struct cmd_list_element *c, const char *args, int from_tty)
{
- c->function.const_cfunc (args, from_tty);
+ c->function.simple_func (args, from_tty);
}
static void
-set_cmd_cfunc (struct cmd_list_element *cmd, cmd_const_cfunc_ftype *cfunc)
+set_cmd_simple_func (struct cmd_list_element *cmd, cmd_simple_func_ftype *simple_func)
{
- if (cfunc == NULL)
+ if (simple_func == NULL)
cmd->func = NULL;
else
- cmd->func = do_const_cfunc;
- cmd->function.const_cfunc = cfunc;
+ cmd->func = do_simple_func;
+
+ cmd->function.simple_func = simple_func;
}
static void
@@ -129,9 +130,10 @@ set_cmd_sfunc (struct cmd_list_element *cmd, cmd_const_sfunc_ftype *sfunc)
}
int
-cmd_cfunc_eq (struct cmd_list_element *cmd, cmd_const_cfunc_ftype *cfunc)
+cmd_simple_func_eq (struct cmd_list_element *cmd, cmd_simple_func_ftype *simple_func)
{
- return cmd->func == do_const_cfunc && cmd->function.const_cfunc == cfunc;
+ return (cmd->func == do_simple_func
+ && cmd->function.simple_func == simple_func);
}
void
@@ -238,17 +240,17 @@ add_cmd (const char *name, enum command_class theclass,
{
cmd_list_element *result = do_add_cmd (name, theclass, doc, list);
result->func = NULL;
- result->function.const_cfunc = NULL;
+ result->function.simple_func = NULL;
return result;
}
struct cmd_list_element *
add_cmd (const char *name, enum command_class theclass,
- cmd_const_cfunc_ftype *fun,
+ cmd_simple_func_ftype *fun,
const char *doc, struct cmd_list_element **list)
{
cmd_list_element *result = do_add_cmd (name, theclass, doc, list);
- set_cmd_cfunc (result, fun);
+ set_cmd_simple_func (result, fun);
return result;
}
@@ -256,7 +258,7 @@ add_cmd (const char *name, enum command_class theclass,
struct cmd_list_element *
add_cmd_suppress_notification (const char *name, enum command_class theclass,
- cmd_const_cfunc_ftype *fun, const char *doc,
+ cmd_simple_func_ftype *fun, const char *doc,
struct cmd_list_element **list,
int *suppress_notification)
{
@@ -359,7 +361,7 @@ update_prefix_field_of_prefixed_commands (struct cmd_list_element *c)
struct cmd_list_element *
add_prefix_cmd (const char *name, enum command_class theclass,
- cmd_const_cfunc_ftype *fun,
+ cmd_simple_func_ftype *fun,
const char *doc, struct cmd_list_element **subcommands,
int allow_unknown, struct cmd_list_element **list)
{
@@ -432,7 +434,7 @@ add_show_prefix_cmd (const char *name, enum command_class theclass,
struct cmd_list_element *
add_prefix_cmd_suppress_notification
(const char *name, enum command_class theclass,
- cmd_const_cfunc_ftype *fun,
+ cmd_simple_func_ftype *fun,
const char *doc, struct cmd_list_element **subcommands,
int allow_unknown, struct cmd_list_element **list,
int *suppress_notification)
@@ -448,7 +450,7 @@ add_prefix_cmd_suppress_notification
struct cmd_list_element *
add_abbrev_prefix_cmd (const char *name, enum command_class theclass,
- cmd_const_cfunc_ftype *fun, const char *doc,
+ cmd_simple_func_ftype *fun, const char *doc,
struct cmd_list_element **subcommands,
int allow_unknown, struct cmd_list_element **list)
{
@@ -460,7 +462,7 @@ add_abbrev_prefix_cmd (const char *name, enum command_class theclass,
return c;
}
-/* This is an empty "cfunc". */
+/* This is an empty "simple func". */
void
not_just_help_class_command (const char *args, int from_tty)
{
@@ -951,7 +953,7 @@ delete_cmd (const char *name, struct cmd_list_element **list,
/* Add an element to the list of info subcommands. */
struct cmd_list_element *
-add_info (const char *name, cmd_const_cfunc_ftype *fun, const char *doc)
+add_info (const char *name, cmd_simple_func_ftype *fun, const char *doc)
{
return add_cmd (name, class_info, fun, doc, &infolist);
}
@@ -968,7 +970,7 @@ add_info_alias (const char *name, cmd_list_element *target, int abbrev_flag)
struct cmd_list_element *
add_com (const char *name, enum command_class theclass,
- cmd_const_cfunc_ftype *fun,
+ cmd_simple_func_ftype *fun,
const char *doc)
{
return add_cmd (name, theclass, fun, doc, &cmdlist);
@@ -990,7 +992,7 @@ add_com_alias (const char *name, cmd_list_element *target,
struct cmd_list_element *
add_com_suppress_notification (const char *name, enum command_class theclass,
- cmd_const_cfunc_ftype *fun, const char *doc,
+ cmd_simple_func_ftype *fun, const char *doc,
int *suppress_notification)
{
return add_cmd_suppress_notification (name, theclass, fun, doc,
@@ -2167,5 +2169,5 @@ int
cli_user_command_p (struct cmd_list_element *cmd)
{
return (cmd->theclass == class_user
- && (cmd->func == do_const_cfunc || cmd->func == do_sfunc));
+ && (cmd->func == do_simple_func || cmd->func == do_sfunc));
}
diff --git a/gdb/cli/cli-decode.h b/gdb/cli/cli-decode.h
index 241535ae5b50..4cbdf7ff6d17 100644
--- a/gdb/cli/cli-decode.h
+++ b/gdb/cli/cli-decode.h
@@ -174,8 +174,12 @@ struct cmd_list_element
to one of the below. */
union
{
- /* If type is not_set_cmd, call it like this: */
- cmd_const_cfunc_ftype *const_cfunc;
+ /* Most commands don't need the cmd_list_element parameter passed to FUNC.
+ They therefore register a command of this type, which doesn't have the
+ cmd_list_element parameter. do_simple_func is installed as FUNC, and
+ acts as a shim between the two. */
+ cmd_simple_func_ftype *simple_func;
+
/* If type is set_cmd or show_cmd, first set the variables,
and then call this: */
cmd_const_sfunc_ftype *sfunc;
diff --git a/gdb/command.h b/gdb/command.h
index 711cbdcf43e1..1bda67c937af 100644
--- a/gdb/command.h
+++ b/gdb/command.h
@@ -128,7 +128,10 @@ var_types;
/* This structure records one command'd definition. */
struct cmd_list_element;
-typedef void cmd_const_cfunc_ftype (const char *args, int from_tty);
+/* The "simple" signature of command callbacks, which doesn't include a
+ cmd_list_element parameter. */
+
+typedef void cmd_simple_func_ftype (const char *args, int from_tty);
/* This structure specifies notifications to be suppressed by a cli
command interpreter. */
@@ -158,7 +161,7 @@ extern bool valid_cmd_char_p (int c);
/* Const-correct variant of the above. */
extern struct cmd_list_element *add_cmd (const char *, enum command_class,
- cmd_const_cfunc_ftype *fun,
+ cmd_simple_func_ftype *fun,
const char *,
struct cmd_list_element **);
@@ -170,7 +173,7 @@ extern struct cmd_list_element *add_cmd (const char *, enum command_class,
extern struct cmd_list_element *add_cmd_suppress_notification
(const char *name, enum command_class theclass,
- cmd_const_cfunc_ftype *fun, const char *doc,
+ cmd_simple_func_ftype *fun, const char *doc,
struct cmd_list_element **list,
int *suppress_notification);
@@ -181,7 +184,7 @@ extern struct cmd_list_element *add_alias_cmd (const char *,
extern struct cmd_list_element *add_prefix_cmd (const char *, enum command_class,
- cmd_const_cfunc_ftype *fun,
+ cmd_simple_func_ftype *fun,
const char *,
struct cmd_list_element **,
int,
@@ -203,7 +206,7 @@ extern struct cmd_list_element *add_show_prefix_cmd
extern struct cmd_list_element *add_prefix_cmd_suppress_notification
(const char *name, enum command_class theclass,
- cmd_const_cfunc_ftype *fun,
+ cmd_simple_func_ftype *fun,
const char *doc, struct cmd_list_element **subcommands,
int allow_unknown,
struct cmd_list_element **list,
@@ -211,7 +214,7 @@ extern struct cmd_list_element *add_prefix_cmd_suppress_notification
extern struct cmd_list_element *add_abbrev_prefix_cmd (const char *,
enum command_class,
- cmd_const_cfunc_ftype *fun,
+ cmd_simple_func_ftype *fun,
const char *,
struct cmd_list_element
**, int,
@@ -250,8 +253,8 @@ extern void set_cmd_completer_handle_brkchars (struct cmd_list_element *,
/* HACK: cagney/2002-02-23: Code, mostly in tracepoints.c, grubs
around in cmd objects to test the value of the commands sfunc(). */
-extern int cmd_cfunc_eq (struct cmd_list_element *cmd,
- cmd_const_cfunc_ftype *cfun);
+extern int cmd_simple_func_eq (struct cmd_list_element *cmd,
+ cmd_simple_func_ftype *cfun);
/* 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
@@ -346,7 +349,7 @@ extern int lookup_cmd_composition (const char *text,
struct cmd_list_element **cmd);
extern struct cmd_list_element *add_com (const char *, enum command_class,
- cmd_const_cfunc_ftype *fun,
+ cmd_simple_func_ftype *fun,
const char *);
extern cmd_list_element *add_com_alias (const char *name,
@@ -356,11 +359,11 @@ extern cmd_list_element *add_com_alias (const char *name,
extern struct cmd_list_element *add_com_suppress_notification
(const char *name, enum command_class theclass,
- cmd_const_cfunc_ftype *fun, const char *doc,
+ cmd_simple_func_ftype *fun, const char *doc,
int *supress_notification);
extern struct cmd_list_element *add_info (const char *,
- cmd_const_cfunc_ftype *fun,
+ cmd_simple_func_ftype *fun,
const char *);
extern cmd_list_element *add_info_alias (const char *name,
diff --git a/gdb/tracepoint.c b/gdb/tracepoint.c
index 83a32ec8252d..06cf9cad29ad 100644
--- a/gdb/tracepoint.c
+++ b/gdb/tracepoint.c
@@ -655,7 +655,7 @@ validate_actionline (const char *line, struct breakpoint *b)
if (c == 0)
error (_("`%s' is not a tracepoint action, or is ambiguous."), p);
- if (cmd_cfunc_eq (c, collect_pseudocommand))
+ if (cmd_simple_func_eq (c, collect_pseudocommand))
{
int trace_string = 0;
@@ -723,7 +723,7 @@ validate_actionline (const char *line, struct breakpoint *b)
while (p && *p++ == ',');
}
- else if (cmd_cfunc_eq (c, teval_pseudocommand))
+ else if (cmd_simple_func_eq (c, teval_pseudocommand))
{
do
{ /* Repeat over a comma-separated list. */
@@ -750,7 +750,7 @@ validate_actionline (const char *line, struct breakpoint *b)
while (p && *p++ == ',');
}
- else if (cmd_cfunc_eq (c, while_stepping_pseudocommand))
+ else if (cmd_simple_func_eq (c, while_stepping_pseudocommand))
{
char *endp;
@@ -761,7 +761,7 @@ validate_actionline (const char *line, struct breakpoint *b)
p = endp;
}
- else if (cmd_cfunc_eq (c, end_actions_pseudocommand))
+ else if (cmd_simple_func_eq (c, end_actions_pseudocommand))
;
else
@@ -1308,7 +1308,7 @@ encode_actions_1 (struct command_line *action,
if (cmd == 0)
error (_("Bad action list item: %s"), action_exp);
- if (cmd_cfunc_eq (cmd, collect_pseudocommand))
+ if (cmd_simple_func_eq (cmd, collect_pseudocommand))
{
int trace_string = 0;
@@ -1464,7 +1464,7 @@ encode_actions_1 (struct command_line *action,
}
while (action_exp && *action_exp++ == ',');
} /* if */
- else if (cmd_cfunc_eq (cmd, teval_pseudocommand))
+ else if (cmd_simple_func_eq (cmd, teval_pseudocommand))
{
do
{ /* Repeat over a comma-separated list. */
@@ -1488,7 +1488,7 @@ encode_actions_1 (struct command_line *action,
}
while (action_exp && *action_exp++ == ',');
} /* if */
- else if (cmd_cfunc_eq (cmd, while_stepping_pseudocommand))
+ else if (cmd_simple_func_eq (cmd, while_stepping_pseudocommand))
{
/* We check against nested while-stepping when setting
breakpoint action, so no way to run into nested
@@ -2690,13 +2690,13 @@ trace_dump_actions (struct command_line *action,
if (cmd == 0)
error (_("Bad action list item: %s"), action_exp);
- if (cmd_cfunc_eq (cmd, while_stepping_pseudocommand))
+ if (cmd_simple_func_eq (cmd, while_stepping_pseudocommand))
{
gdb_assert (action->body_list_1 == nullptr);
trace_dump_actions (action->body_list_0.get (),
1, stepping_frame, from_tty);
}
- else if (cmd_cfunc_eq (cmd, collect_pseudocommand))
+ else if (cmd_simple_func_eq (cmd, collect_pseudocommand))
{
/* Display the collected data.
For the trap frame, display only what was collected at
--
2.32.0
next prev parent reply other threads:[~2021-07-14 5:02 UTC|newest]
Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-14 4:55 [PATCH 00/16] Bunch of commands related cleanups Simon Marchi via Gdb-patches
2021-07-14 4:55 ` [PATCH 01/16] gdb/testsuite: split gdb.python/py-parameter.exp in procs Simon Marchi via Gdb-patches
2021-07-14 4:55 ` [PATCH 02/16] gdb.base/setshow.exp: use save_vars to save/restore gdb_prompt Simon Marchi via Gdb-patches
2021-07-14 4:55 ` [PATCH 03/16] gdb.base/setshow.exp: split in procs Simon Marchi via Gdb-patches
2021-07-14 4:55 ` [PATCH 04/16] gdb.base/setshow.exp: fix duplicate test name Simon Marchi via Gdb-patches
2021-07-14 4:55 ` [PATCH 05/16] gdb: un-share set_inferior_cwd declaration Simon Marchi via Gdb-patches
2021-07-14 4:55 ` [PATCH 06/16] gdb: remove inferior::{argc,argv} Simon Marchi via Gdb-patches
2021-07-14 4:55 ` [PATCH 07/16] gdb: add setter/getter for inferior arguments Simon Marchi via Gdb-patches
2021-07-14 4:55 ` [PATCH 08/16] gdb: add setter/getter for inferior cwd Simon Marchi via Gdb-patches
2021-07-14 4:55 ` [PATCH 09/16] gdb: make inferior::m_args an std::string Simon Marchi via Gdb-patches
2021-07-14 4:55 ` [PATCH 10/16] gdb: make inferior::m_cwd " Simon Marchi via Gdb-patches
2021-07-14 4:55 ` [PATCH 11/16] gdb: make inferior::m_terminal " Simon Marchi via Gdb-patches
2021-07-14 4:55 ` Simon Marchi via Gdb-patches [this message]
2021-07-14 4:55 ` [PATCH 13/16] gdb: remove cmd_list_element::function::sfunc Simon Marchi via Gdb-patches
2021-07-28 19:10 ` Tom Tromey
2021-07-28 21:17 ` Simon Marchi via Gdb-patches
2021-07-29 17:33 ` Tom Tromey
2021-07-14 4:55 ` [PATCH 14/16] gdb/testsuite: test get/set value of unregistered Guile parameter Simon Marchi via Gdb-patches
2021-07-23 19:42 ` Simon Marchi via Gdb-patches
2021-07-14 4:55 ` [PATCH 15/16] gdb: make cmd_list_element var an optional union Simon Marchi via Gdb-patches
2021-07-14 12:08 ` Lancelot SIX via Gdb-patches
2021-07-14 17:12 ` Lancelot SIX via Gdb-patches
2021-07-14 19:22 ` Simon Marchi via Gdb-patches
2021-07-14 23:22 ` Lancelot SIX via Gdb-patches
2021-07-19 14:32 ` Simon Marchi via Gdb-patches
2021-07-19 19:52 ` Simon Marchi via Gdb-patches
2021-07-20 23:03 ` Lancelot SIX via Gdb-patches
2021-07-23 19:56 ` Simon Marchi via Gdb-patches
2021-07-23 20:46 ` Lancelot SIX via Gdb-patches
2021-07-23 21:15 ` Simon Marchi via Gdb-patches
2021-07-23 22:55 ` Lancelot SIX via Gdb-patches
2021-07-24 2:04 ` Simon Marchi via Gdb-patches
2021-07-28 20:13 ` Tom Tromey
2021-07-28 20:45 ` Lancelot SIX via Gdb-patches
2021-07-29 17:47 ` Tom Tromey
2021-07-29 20:12 ` Lancelot SIX via Gdb-patches
2021-07-30 2:09 ` Simon Marchi via Gdb-patches
2021-07-30 17:47 ` Lancelot SIX via Gdb-patches
2021-07-18 15:44 ` Lancelot SIX via Gdb-patches
2021-07-19 14:19 ` Simon Marchi via Gdb-patches
2021-07-19 20:58 ` Lancelot SIX via Gdb-patches
2021-07-28 19:47 ` Tom Tromey
2021-07-28 20:59 ` Simon Marchi via Gdb-patches
2021-07-29 17:41 ` Tom Tromey
2021-07-29 17:44 ` Simon Marchi via Gdb-patches
2021-07-29 17:49 ` Tom Tromey
2021-07-29 18:00 ` Simon Marchi via Gdb-patches
2021-07-14 4:55 ` [PATCH 16/16] gdb: make string-like set show commands use std::string variable Simon Marchi via Gdb-patches
2021-07-28 20:27 ` Tom Tromey
2021-07-28 21:03 ` Simon Marchi via Gdb-patches
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=20210714045520.1623120-13-simon.marchi@polymtl.ca \
--to=gdb-patches@sourceware.org \
--cc=simon.marchi@polymtl.ca \
/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