From: Jan Vrany <jan.vrany@labware.com>
To: gdb-patches@sourceware.org
Cc: Jan Vrany <jan.vrany@labware.com>
Subject: [PATCH 1/5] gdb/mi: introduce new class mi_command_builtin
Date: Mon, 17 Jan 2022 12:44:21 +0000 [thread overview]
Message-ID: <20220117124425.2658516-2-jan.vrany@labware.com> (raw)
In-Reply-To: <20220117124425.2658516-1-jan.vrany@labware.com>
The motivation for this commit is that GDB/MI commands have their names
statically allocated whereas Python-based commands (that will be
introduced in later) will have their name dynamically allocated.
To support this, this commit introduces new abstract class
`mi_command_builtin` that allows for its name to be statically allocated.
Future Python-based commands will hold onto dynamically allocated
std::string.
---
gdb/mi/mi-cmds.c | 43 ++++++++++++++++++++++++++++++-------------
gdb/mi/mi-cmds.h | 14 +++++---------
2 files changed, 35 insertions(+), 22 deletions(-)
diff --git a/gdb/mi/mi-cmds.c b/gdb/mi/mi-cmds.c
index cd7cabdda9b..57fe32c1cc6 100644
--- a/gdb/mi/mi-cmds.c
+++ b/gdb/mi/mi-cmds.c
@@ -34,16 +34,42 @@ using mi_command_up = std::unique_ptr<struct mi_command>;
static std::map<std::string, mi_command_up> mi_cmd_table;
+/* The abstract base class for all built-in MI command types. */
+
+struct mi_command_builtin : public mi_command
+{
+ /* Constructor. NAME is the name of this MI command, excluding any
+ leading dash, that is the initial string the user will enter to run
+ this command. For SUPPRESS_NOTIFICATION see mi_command
+ constructor, FUNC is the function called from do_invoke, which
+ implements this MI command. */
+ mi_command_builtin (const char *name, int *suppress_notification)
+ : mi_command (suppress_notification),
+ m_name (name)
+ {
+ gdb_assert (m_name != nullptr && m_name[0] != '\0' && m_name[0] != '-');
+ }
+
+ virtual const char *name () const override
+ {
+ return m_name;
+ }
+
+private:
+ /* The name of the command. */
+ const char *m_name;
+};
+
/* MI command with a pure MI implementation. */
-struct mi_command_mi : public mi_command
+struct mi_command_mi : public mi_command_builtin
{
/* Constructor. For NAME and SUPPRESS_NOTIFICATION see mi_command
constructor, FUNC is the function called from do_invoke, which
implements this MI command. */
mi_command_mi (const char *name, mi_cmd_argv_ftype func,
int *suppress_notification)
- : mi_command (name, suppress_notification),
+ : mi_command_builtin (name, suppress_notification),
m_argv_function (func)
{
gdb_assert (func != nullptr);
@@ -72,7 +98,7 @@ struct mi_command_mi : public mi_command
/* MI command implemented on top of a CLI command. */
-struct mi_command_cli : public mi_command
+struct mi_command_cli : public mi_command_builtin
{
/* Constructor. For NAME and SUPPRESS_NOTIFICATION see mi_command
constructor, CLI_NAME is the name of a CLI command that should be
@@ -82,7 +108,7 @@ struct mi_command_cli : public mi_command
false, nullptr is send to CLI_NAME as its argument string. */
mi_command_cli (const char *name, const char *cli_name, bool args_p,
int *suppress_notification)
- : mi_command (name, suppress_notification),
+ : mi_command_builtin (name, suppress_notification),
m_cli_name (cli_name),
m_args_p (args_p)
{ /* Nothing. */ }
@@ -159,15 +185,6 @@ add_mi_cmd_cli (const char *name, const char *cli_name, int args_p,
/* See mi-cmds.h. */
-mi_command::mi_command (const char *name, int *suppress_notification)
- : m_name (name),
- m_suppress_notification (suppress_notification)
-{
- gdb_assert (m_name != nullptr && m_name[0] != '\0');
-}
-
-/* See mi-cmds.h. */
-
void
mi_command::invoke (struct mi_parse *parse) const
{
diff --git a/gdb/mi/mi-cmds.h b/gdb/mi/mi-cmds.h
index 2a93a9f5476..94ecb271d48 100644
--- a/gdb/mi/mi-cmds.h
+++ b/gdb/mi/mi-cmds.h
@@ -143,12 +143,12 @@ extern mi_cmd_argv_ftype mi_cmd_complete;
struct mi_command
{
- /* Constructor. NAME is the name of this MI command, excluding any
- leading dash, that is the initial string the user will enter to run
- this command. The SUPPRESS_NOTIFICATION pointer is a flag which will
+ /* Constructor. The SUPPRESS_NOTIFICATION pointer is a flag which will
be set to 1 when this command is invoked, and reset to its previous
value once the command invocation has completed. */
- mi_command (const char *name, int *suppress_notification);
+ mi_command (int *suppress_notification)
+ : m_suppress_notification (suppress_notification)
+ {}
/* Destructor. */
virtual ~mi_command () = default;
@@ -156,8 +156,7 @@ struct mi_command
/* Return the name of this command. This is the command that the user
will actually type in, without any arguments, and without the leading
dash. */
- const char *name () const
- { return m_name; }
+ virtual const char *name () const = 0;
/* Execute the MI command. Can throw an exception if something goes
wrong. */
@@ -180,9 +179,6 @@ struct mi_command
then this function returns an empty gdb::optional. */
gdb::optional<scoped_restore_tmpl<int>> do_suppress_notification () const;
- /* The name of the command. */
- const char *m_name;
-
/* Pointer to integer to set during command's invocation. */
int *m_suppress_notification;
};
--
2.30.2
next prev parent reply other threads:[~2022-01-17 12:44 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-17 12:44 [PATCH 0/5] create GDB/MI commands using python Jan Vrany
2022-01-17 12:44 ` Jan Vrany [this message]
2022-01-17 12:44 ` [PATCH 2/5] gdb/python: " Jan Vrany
2022-02-06 16:52 ` Lancelot SIX
2022-01-17 12:44 ` [PATCH 3/5] gdb/python: allow redefinition of python GDB/MI commands Jan Vrany
2022-02-06 17:13 ` Lancelot SIX
2022-02-06 20:33 ` Simon Marchi
2022-02-06 20:44 ` Jan Vrany
2022-02-06 20:46 ` Simon Marchi
2022-02-07 9:46 ` Lancelot SIX
2022-01-17 12:44 ` [PATCH 4/5] gdb/testsuite: add tests for python-defined MI commands Jan Vrany
2022-01-17 12:44 ` [PATCH 5/5] gdb/python: document GDB/MI commands in Python Jan Vrany
2022-01-17 13:15 ` Eli Zaretskii
2022-01-17 13:20 ` Eli Zaretskii
2022-01-18 12:34 ` Jan Vrany
2022-01-18 15:09 ` Eli Zaretskii
2022-01-18 13:55 ` [PATCH 0/5] create GDB/MI commands using python Andrew Burgess
2022-01-18 15:13 ` Jan Vrany
2022-01-21 15:22 ` Andrew Burgess
2022-01-24 12:59 ` Jan Vrany
2022-02-02 16:57 ` Andrew Burgess
2022-02-06 21:16 ` Simon Marchi
2022-02-07 15:56 ` [PATCHv2] gdb/python/mi: create MI " Andrew Burgess
2022-02-08 15:16 ` Simon Marchi
2022-02-09 12:25 ` [PATCHv3] " Andrew Burgess
2022-02-09 14:08 ` Simon Marchi
2022-02-10 18:26 ` Andrew Burgess
2022-02-13 14:27 ` Joel Brobecker
2022-02-13 21:46 ` Jan Vrany
2022-02-24 10:37 ` [PATCHv4] " Andrew Burgess
2022-02-25 19:22 ` Tom Tromey
2022-02-25 19:31 ` Jan Vrany
2022-02-28 16:48 ` [PATCHv5] " Andrew Burgess
2022-02-28 18:40 ` Tom Tromey
2022-03-13 4:47 ` Joel Brobecker
2022-03-14 14:13 ` Andrew Burgess
2022-03-16 8:10 ` Joel Brobecker
2022-03-16 12:29 ` Simon Marchi
2022-03-18 15:06 ` Simon Marchi
2022-03-18 16:12 ` Andrew Burgess
2022-03-18 19:57 ` Simon Marchi
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=20220117124425.2658516-2-jan.vrany@labware.com \
--to=jan.vrany@labware.com \
--cc=gdb-patches@sourceware.org \
/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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).