From: Tom Tromey <tromey@adacore.com>
To: gdb-patches@sourceware.org
Subject: [PATCH v2 3/9] Use accessor for mi_parse::args
Date: Thu, 18 May 2023 14:18:09 -0600 [thread overview]
Message-ID: <20230404-dap-loaded-sources-v2-3-93f229095e03@adacore.com> (raw)
In-Reply-To: <20230404-dap-loaded-sources-v2-0-93f229095e03@adacore.com>
This changes mi_parse::args to be a private member, retrieved via
accessor. It also changes this member to be a std::string. This
makes it simpler for a subsequent patch to implement different
behavior for argument parsing.
---
gdb/mi/mi-cmds.c | 6 +++---
gdb/mi/mi-main.c | 2 +-
gdb/mi/mi-parse.c | 3 +--
gdb/mi/mi-parse.h | 13 ++++++++++++-
gdb/python/py-micmd.c | 5 +++--
5 files changed, 20 insertions(+), 9 deletions(-)
diff --git a/gdb/mi/mi-cmds.c b/gdb/mi/mi-cmds.c
index 284453db85d..ca8c633e218 100644
--- a/gdb/mi/mi-cmds.c
+++ b/gdb/mi/mi-cmds.c
@@ -49,11 +49,11 @@ struct mi_command_mi : public mi_command
with arguments contained within PARSE. */
void invoke (struct mi_parse *parse) const override
{
- mi_parse_argv (parse->args, parse);
+ mi_parse_argv (parse->args (), parse);
if (parse->argv == nullptr)
error (_("Problem parsing arguments: %s %s"), parse->command,
- parse->args);
+ parse->args ());
this->m_argv_function (parse->command, parse->argv, parse->argc);
}
@@ -87,7 +87,7 @@ struct mi_command_cli : public mi_command
is passed through to the CLI function as its argument string. */
void invoke (struct mi_parse *parse) const override
{
- const char *args = m_args_p ? parse->args : nullptr;
+ const char *args = m_args_p ? parse->args () : nullptr;
mi_execute_cli_command (m_cli_name, m_args_p, args);
}
diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
index 840663e0fb4..aaebce40fac 100644
--- a/gdb/mi/mi-main.c
+++ b/gdb/mi/mi-main.c
@@ -1813,7 +1813,7 @@ captured_mi_execute_command (struct ui_out *uiout, struct mi_parse *context)
if (mi_debug_p)
gdb_printf (gdb_stdlog,
" token=`%s' command=`%s' args=`%s'\n",
- context->token, context->command, context->args);
+ context->token, context->command, context->args ());
mi_cmd_execute (context);
diff --git a/gdb/mi/mi-parse.c b/gdb/mi/mi-parse.c
index bda554a568e..bf3b534e590 100644
--- a/gdb/mi/mi-parse.c
+++ b/gdb/mi/mi-parse.c
@@ -212,7 +212,6 @@ mi_parse::~mi_parse ()
{
xfree (command);
xfree (token);
- xfree (args);
freeargv (argv);
}
@@ -346,7 +345,7 @@ mi_parse (const char *cmd, char **token)
}
/* Save the rest of the arguments for the command. */
- parse->args = xstrdup (chp);
+ parse->set_args (chp);
/* Fully parsed, flag as an MI command. */
parse->op = MI_COMMAND;
diff --git a/gdb/mi/mi-parse.h b/gdb/mi/mi-parse.h
index 75bb36b1c77..d4ac3f002e4 100644
--- a/gdb/mi/mi-parse.h
+++ b/gdb/mi/mi-parse.h
@@ -46,12 +46,19 @@ struct mi_parse
DISABLE_COPY_AND_ASSIGN (mi_parse);
+ /* Return the full argument string, as used by commands which are
+ implemented as CLI commands. */
+ const char *args () const
+ { return m_args.c_str (); }
+
+ void set_args (const char *args)
+ { m_args = args; }
+
enum mi_command_type op = MI_COMMAND;
char *command = nullptr;
char *token = nullptr;
const struct mi_command *cmd = nullptr;
struct mi_timestamp *cmd_start = nullptr;
- char *args = nullptr;
char **argv = nullptr;
int argc = 0;
int all = 0;
@@ -62,6 +69,10 @@ struct mi_parse
/* The language that should be used to evaluate the MI command.
Ignored if set to language_unknown. */
enum language language = language_unknown;
+
+ private:
+
+ std::string m_args;
};
/* Attempts to parse CMD returning a ``struct mi_parse''. If CMD is
diff --git a/gdb/python/py-micmd.c b/gdb/python/py-micmd.c
index d7d95918cb4..88d52db2202 100644
--- a/gdb/python/py-micmd.c
+++ b/gdb/python/py-micmd.c
@@ -355,10 +355,11 @@ mi_command_py::invoke (struct mi_parse *parse) const
pymicmd_debug_printf ("this = %p, name = %s", this, name ());
- mi_parse_argv (parse->args, parse);
+ mi_parse_argv (parse->args (), parse);
if (parse->argv == nullptr)
- error (_("Problem parsing arguments: %s %s"), parse->command, parse->args);
+ error (_("Problem parsing arguments: %s %s"), parse->command,
+ parse->args ());
gdbpy_enter enter_py;
--
2.40.0
next prev parent reply other threads:[~2023-05-18 20:18 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-18 20:18 [PATCH v2 0/9] Implement the DAP "loadedSources" request Tom Tromey
2023-05-18 20:18 ` [PATCH v2 1/9] Use field_signed from Python MI commands Tom Tromey
2023-05-18 20:18 ` [PATCH v2 2/9] Use member initializers in mi_parse Tom Tromey
2023-05-18 20:18 ` Tom Tromey [this message]
2023-05-18 20:18 ` [PATCH v2 4/9] Change mi_parse_argv to a method Tom Tromey
2023-05-18 20:18 ` [PATCH v2 5/9] Introduce "static constructor" for mi_parse Tom Tromey
2023-08-11 11:02 ` Andrew Burgess
2023-08-11 13:10 ` Tom Tromey
2023-08-11 15:06 ` Andrew Burgess
2023-05-18 20:18 ` [PATCH v2 6/9] Introduce mi_parse helper methods Tom Tromey
2023-05-18 20:18 ` [PATCH v2 7/9] Add second mi_parse constructor Tom Tromey
2023-05-18 20:18 ` [PATCH v2 8/9] Implement gdb.execute_mi Tom Tromey
2023-05-19 5:37 ` Eli Zaretskii
2023-05-29 15:54 ` Simon Marchi
2023-06-02 19:19 ` Tom Tromey
2023-06-08 20:16 ` Tom Tromey
2023-05-18 20:18 ` [PATCH v2 9/9] Implement DAP loadedSources request Tom Tromey
2023-05-23 19:46 ` [PATCH v2 0/9] Implement the DAP "loadedSources" request Tom Tromey
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=20230404-dap-loaded-sources-v2-3-93f229095e03@adacore.com \
--to=tromey@adacore.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).