From: Simon Marchi <simark@simark.ca>
To: Jan Vrany <jan.vrany@fit.cvut.cz>, gdb-patches@sourceware.org
Cc: Didier Nadeau <didier.nadeau@gmail.com>
Subject: Re: [PATCH v2 2/5] Use classes to represent MI Command instead of structures
Date: Fri, 17 May 2019 03:12:00 -0000 [thread overview]
Message-ID: <7dffd6b7-855c-2dea-8cee-64d895b38bff@simark.ca> (raw)
In-Reply-To: <20190514112418.24091-3-jan.vrany@fit.cvut.cz>
Hi Jan,
This looks ok to me, I have noted a few styling issues, I fixed them as I went
through the code, so see the patch at the end which you can apply to your patch.
> @@ -36,9 +37,9 @@ static bool
> insert_mi_cmd_entry (mi_cmd_up command)
> {
> gdb_assert (command != NULL);
> - gdb_assert (command->name != NULL);
> + gdb_assert (! command->name ().empty ());
Remove space after !.
> /* Create and register a new MI command with a pure MI implementation. */
>
> static void
> add_mi_cmd_mi (const char *name, mi_cmd_argv_ftype function,
> int *suppress_notification = NULL)
> {
> - mi_cmd_up cmd_up = create_mi_cmd (name);
> -
> - cmd_up->cli.cmd = NULL;
> - cmd_up->cli.args_p = 0;
> - cmd_up->argv_func = function;
> - cmd_up->suppress_notification = suppress_notification;
> + mi_command *micommand = new mi_command_mi (name, function,
> + suppress_notification);
>
> - bool success = insert_mi_cmd_entry (std::move (cmd_up));
> + bool success = insert_mi_cmd_entry (std::move (mi_cmd_up (micommand)));
It would make more sense to make the local variable an mi_cmd_up.
> gdb_assert (success);
> }
>
> @@ -83,17 +68,74 @@ static void
> add_mi_cmd_cli (const char *name, const char *cli_name, int args_p,
> int *suppress_notification = NULL)
> {
> - mi_cmd_up cmd_up = create_mi_cmd (name);
> + mi_command *micommand = new mi_command_cli (name, cli_name, args_p,
> + suppress_notification);
Likewise.
>
> - cmd_up->cli.cmd = cli_name;
> - cmd_up->cli.args_p = args_p;
> - cmd_up->argv_func = NULL;
> - cmd_up->suppress_notification = suppress_notification;
> -
> - bool success = insert_mi_cmd_entry (std::move (cmd_up));
> + bool success = insert_mi_cmd_entry (std::move (mi_cmd_up (micommand)));
> gdb_assert (success);
> }
>
> +/* See mi-cmds.h */
> +mi_command::mi_command (const char *name, int *suppress_notification)
> + : m_name (name),
> + m_suppress_notification (suppress_notification)
> +{}
> +
> +
> +void
> +mi_command::invoke (struct mi_parse *parse)
> +{
> + gdb::optional<scoped_restore_tmpl<int>> restore
> + = do_suppress_notification ();
> + this->do_invoke(parse);
Missing space.
> +}
> +
> +gdb::optional<scoped_restore_tmpl<int>>
> +mi_command::do_suppress_notification ()
> +{
> + if (m_suppress_notification != NULL)
> + return scoped_restore_tmpl<int> (m_suppress_notification, 1);
> + else
> + {
> + return gdb::optional<scoped_restore_tmpl<int>> ();
> + }
Remove the curly braces. Also, this can be shortened to "return {};".
> @@ -126,38 +126,69 @@ extern mi_cmd_argv_ftype mi_cmd_enable_pretty_printing;
> extern mi_cmd_argv_ftype mi_cmd_enable_frame_filters;
> extern mi_cmd_argv_ftype mi_cmd_var_set_update_range;
>
> -/* Description of a single command. */
> +/* mi_command base virtual class. */
>
> -struct mi_cli
> +class mi_command
> {
> - /* Corresponding CLI command. If ARGS_P is non-zero, the MI
> - command's argument list is appended to the CLI command. */
> - const char *cmd;
> - int args_p;
> + public:
> + mi_command (const char *name, int *suppress_notification);
> + virtual ~mi_command () {};
Use the default destructor:
virtual ~mi_command () = default;
> +
> + const std::string &name ()
> + { return m_name; }
> +
> + /* Execute the MI command. */
> + void invoke (struct mi_parse *parse);
> +
> + protected:
> + gdb::optional<scoped_restore_tmpl<int>> do_suppress_notification ();
> + virtual void do_invoke(struct mi_parse *parse) = 0;
It would be useful to have some short doc for these.
Also, I think do_invoke could be private.
> +
> + private:
> +
> + /* The name of the command. */
> + std::string m_name;
> +
> + /* Pointer to integer to set during command's invocation. */
> + int *m_suppress_notification;
> };
Unindent the content of the class: the public/private should be at the
same column as the "class" keyword.
> diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
> index 17ca807471..481f09f799 100644
> --- a/gdb/mi/mi-main.c
> +++ b/gdb/mi/mi-main.c
> @@ -90,9 +90,6 @@ int running_result_record_printed = 1;
> int mi_proceeded;
>
> static void mi_cmd_execute (struct mi_parse *parse);
> -
> -static void mi_execute_cli_command (const char *cmd, int args_p,
> - const char *args);
> static void mi_execute_async_cli_command (const char *cli_command,
> char **argv, int argc);
> static bool register_changed_p (int regnum, readonly_detached_regcache *,
> @@ -1954,9 +1951,6 @@ mi_execute_command (const char *cmd, int from_tty)
>
> gdb::optional<scoped_restore_tmpl<int>> restore_suppress;
This ends up ununsed and can be removed.
>
> - if (command->cmd != NULL && command->cmd->suppress_notification != NULL)
> - restore_suppress.emplace (command->cmd->suppress_notification, 1);
> -
> command->token = token;
>
> if (do_timings)
> @@ -2095,17 +2089,9 @@ mi_cmd_execute (struct mi_parse *parse)
>
> current_context = parse;
>
> - if (parse->cmd->argv_func != NULL)
> - {
> - parse->cmd->argv_func (parse->command, parse->argv, parse->argc);
> - }
> - else if (parse->cmd->cli.cmd != 0)
> + if (parse->cmd != NULL)
> {
> - /* FIXME: DELETE THIS. */
> - /* The operation is still implemented by a cli command. */
> - /* Must be a synchronous one. */
> - mi_execute_cli_command (parse->cmd->cli.cmd, parse->cmd->cli.args_p,
> - parse->args);
> + parse->cmd->invoke (parse);
Remove resulting extra curly braces.
Here's the diff that should fix pretty much all these comments.
From 6e7b648b887e59eaadb01919ca0d665dae2b3e19 Mon Sep 17 00:00:00 2001
From: Simon Marchi <simon.marchi@polymtl.ca>
Date: Thu, 16 May 2019 22:00:00 -0400
Subject: [PATCH] fixup patch 2
---
gdb/mi/mi-cmds.c | 21 ++++++++---------
gdb/mi/mi-cmds.h | 60 +++++++++++++++++++++++++-----------------------
gdb/mi/mi-main.c | 6 +----
3 files changed, 41 insertions(+), 46 deletions(-)
diff --git a/gdb/mi/mi-cmds.c b/gdb/mi/mi-cmds.c
index 44f3813fdc9a..7702011e39df 100644
--- a/gdb/mi/mi-cmds.c
+++ b/gdb/mi/mi-cmds.c
@@ -37,7 +37,7 @@ static bool
insert_mi_cmd_entry (mi_cmd_up command)
{
gdb_assert (command != NULL);
- gdb_assert (! command->name ().empty ());
+ gdb_assert (!command->name ().empty ());
const std::string &name = command->name ();
@@ -55,10 +55,9 @@ static void
add_mi_cmd_mi (const char *name, mi_cmd_argv_ftype function,
int *suppress_notification = NULL)
{
- mi_command *micommand = new mi_command_mi (name, function,
- suppress_notification);
+ mi_cmd_up command (new mi_command_mi (name, function, suppress_notification));
- bool success = insert_mi_cmd_entry (std::move (mi_cmd_up (micommand)));
+ bool success = insert_mi_cmd_entry (std::move (command));
gdb_assert (success);
}
@@ -68,14 +67,15 @@ static void
add_mi_cmd_cli (const char *name, const char *cli_name, int args_p,
int *suppress_notification = NULL)
{
- mi_command *micommand = new mi_command_cli (name, cli_name, args_p,
- suppress_notification);
+ mi_cmd_up command (new mi_command_cli (name, cli_name, args_p,
+ suppress_notification));
- bool success = insert_mi_cmd_entry (std::move (mi_cmd_up (micommand)));
+ bool success = insert_mi_cmd_entry (std::move (command));
gdb_assert (success);
}
/* See mi-cmds.h */
+
mi_command::mi_command (const char *name, int *suppress_notification)
: m_name (name),
m_suppress_notification (suppress_notification)
@@ -87,7 +87,7 @@ mi_command::invoke (struct mi_parse *parse)
{
gdb::optional<scoped_restore_tmpl<int>> restore
= do_suppress_notification ();
- this->do_invoke(parse);
+ this->do_invoke (parse);
}
gdb::optional<scoped_restore_tmpl<int>>
@@ -96,9 +96,7 @@ mi_command::do_suppress_notification ()
if (m_suppress_notification != NULL)
return scoped_restore_tmpl<int> (m_suppress_notification, 1);
else
- {
- return gdb::optional<scoped_restore_tmpl<int>> ();
- }
+ return {};
}
mi_command_mi::mi_command_mi (const char *name, mi_cmd_argv_ftype func,
@@ -303,4 +301,3 @@ _initialize_mi_cmds (void)
{
build_table ();
}
-
diff --git a/gdb/mi/mi-cmds.h b/gdb/mi/mi-cmds.h
index fc432a16b9cc..12b9696c5f41 100644
--- a/gdb/mi/mi-cmds.h
+++ b/gdb/mi/mi-cmds.h
@@ -130,58 +130,60 @@ extern mi_cmd_argv_ftype mi_cmd_var_set_update_range;
class mi_command
{
- public:
- mi_command (const char *name, int *suppress_notification);
- virtual ~mi_command () {};
+public:
+ mi_command (const char *name, int *suppress_notification);
+ virtual ~mi_command () = default;
- const std::string &name ()
- { return m_name; }
+ const std::string &name ()
+ { return m_name; }
- /* Execute the MI command. */
- void invoke (struct mi_parse *parse);
+ /* Execute the MI command. */
+ void invoke (struct mi_parse *parse);
- protected:
- gdb::optional<scoped_restore_tmpl<int>> do_suppress_notification ();
- virtual void do_invoke(struct mi_parse *parse) = 0;
+protected:
+ /* Set the notification suppression flag for the command. Return a
+ scoped_restore that undoes it. */
+ gdb::optional<scoped_restore_tmpl<int>> do_suppress_notification ();
- private:
+private:
+ /* Implementation of the behavior of the MI command, to be implemented by
+ child classes. */
+ virtual void do_invoke (struct mi_parse *parse) = 0;
- /* The name of the command. */
- std::string m_name;
+ /* The name of the command. */
+ std::string m_name;
- /* Pointer to integer to set during command's invocation. */
- int *m_suppress_notification;
+ /* Pointer to integer to set during command's invocation. */
+ int *m_suppress_notification;
};
/* MI command with a pure MI implementation. */
class mi_command_mi : public mi_command
{
- public:
- mi_command_mi (const char *name, mi_cmd_argv_ftype func,
- int *suppress_notification);
+public:
+ mi_command_mi (const char *name, mi_cmd_argv_ftype func,
+ int *suppress_notification);
- protected:
- void do_invoke(struct mi_parse *parse) override;
+private:
+ virtual void do_invoke (struct mi_parse *parse) override;
- private:
- mi_cmd_argv_ftype *m_argv_function;
+ mi_cmd_argv_ftype *m_argv_function;
};
/* MI command implemented on top of a CLI command. */
class mi_command_cli : public mi_command
{
- public:
- mi_command_cli (const char *name, const char *cli_name, int args_p,
+public:
+ mi_command_cli (const char *name, const char *cli_name, int args_p,
int *suppress_notification);
- protected:
- void do_invoke(struct mi_parse *parse) override;
+private:
+ virtual void do_invoke (struct mi_parse *parse) override;
- private:
- std::string m_cli_name;
- int m_args_p;
+ std::string m_cli_name;
+ int m_args_p;
};
typedef std::unique_ptr<mi_command> mi_cmd_up;
diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
index 754091656248..ccb7bf45bdf5 100644
--- a/gdb/mi/mi-main.c
+++ b/gdb/mi/mi-main.c
@@ -1949,8 +1949,6 @@ mi_execute_command (const char *cmd, int from_tty)
{
ptid_t previous_ptid = inferior_ptid;
- gdb::optional<scoped_restore_tmpl<int>> restore_suppress;
-
command->token = token;
if (do_timings)
@@ -2090,9 +2088,7 @@ mi_cmd_execute (struct mi_parse *parse)
current_context = parse;
if (parse->cmd != NULL)
- {
- parse->cmd->invoke (parse);
- }
+ parse->cmd->invoke (parse);
else
{
/* FIXME: DELETE THIS. */
--
2.21.0
next prev parent reply other threads:[~2019-05-17 3:12 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-18 15:23 [RFC 0/8] Create MI commands using python Jan Vrany
2019-04-18 15:23 ` [RFC 1/8] Use std::map for MI commands in mi-cmds.c Jan Vrany
2019-04-25 19:13 ` Tom Tromey
2019-04-25 19:15 ` Tom Tromey
2019-04-25 19:34 ` Jan Vrany
2019-05-03 22:40 ` Simon Marchi
2019-05-03 22:45 ` Simon Marchi
2019-04-18 15:24 ` [RFC 3/8] Create MI commands using python Jan Vrany
2019-04-25 19:42 ` Tom Tromey
2019-04-18 15:24 ` [RFC 4/8] mi/python: C++ify python MI command handling code Jan Vrany
2019-04-25 19:43 ` Tom Tromey
2019-04-18 15:24 ` [RFC 8/8] mi/python: Allow redefinition of python MI commands Jan Vrany
2019-04-25 19:50 ` Tom Tromey
2019-05-03 15:26 ` Jan Vrany
2019-05-06 21:40 ` Tom Tromey
2019-05-07 11:26 ` Jan Vrany
2019-05-07 13:09 ` Simon Marchi
2019-05-07 13:19 ` Jan Vrany
2019-05-08 0:10 ` Simon Marchi
2019-05-08 18:00 ` Tom Tromey
2019-04-18 15:24 ` [RFC 6/8] mi/python: Handle python exception when executiong python-defined " Jan Vrany
2019-04-25 19:46 ` Tom Tromey
2019-04-26 10:19 ` Jan Vrany
2019-04-18 15:24 ` [RFC 7/8] mi/python: Add tests for " Jan Vrany
2019-04-25 19:48 ` Tom Tromey
2019-04-18 15:24 ` [RFC 2/8] Use classes to represent MI Command instead of structures Jan Vrany
2019-04-25 19:25 ` Tom Tromey
2019-05-03 22:49 ` Simon Marchi
2019-05-03 22:57 ` Simon Marchi
2019-04-18 16:03 ` [RFC 0/8] Create MI commands using python Simon Marchi
2019-04-20 7:20 ` Jan Vrany
2019-04-18 16:12 ` [RFC 5/8] mi/python: Polish MI output of python commands Jan Vrany
2019-04-25 19:50 ` Tom Tromey
2019-04-25 18:03 ` [RFC 0/8] Create MI commands using python Tom Tromey
2019-04-25 19:00 ` Simon Marchi
2019-04-25 19:01 ` Simon Marchi
2019-05-14 11:24 ` [PATCH v2 3/5] " Jan Vrany
2019-05-17 4:29 ` Simon Marchi
2019-05-28 20:35 ` Jan Vrany
2019-05-14 11:24 ` [PATCH v2 2/5] Use classes to represent MI Command instead of structures Jan Vrany
2019-05-17 3:12 ` Simon Marchi [this message]
2019-05-14 11:24 ` [PATCH v2 1/5] Use std::map for MI commands in mi-cmds.c Jan Vrany
2019-05-14 11:24 ` [PATCH v2 0/5] Create MI commands using python Jan Vrany
2019-05-14 11:24 ` [PATCH v2 5/5] mi/python: Add tests for python-defined MI commands Jan Vrany
2019-05-14 11:57 ` [PATCH v2 4/5] mi/python: Allow redefinition of python " Jan Vrany
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=7dffd6b7-855c-2dea-8cee-64d895b38bff@simark.ca \
--to=simark@simark.ca \
--cc=didier.nadeau@gmail.com \
--cc=gdb-patches@sourceware.org \
--cc=jan.vrany@fit.cvut.cz \
/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