aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Tromey <tromey@adacore.com>2023-03-20 10:42:43 -0600
committerTom Tromey <tromey@adacore.com>2023-05-23 10:09:27 -0600
commit72654e04dab3d41417c2f422c8825d2b659a66fe (patch)
treee6217c852faf72a83c119b591ce6a1bfe0bed4da
parentc55db01a31c84f2223e18cd274203d1c3ccc7844 (diff)
downloadfsf-binutils-gdb-72654e04dab3d41417c2f422c8825d2b659a66fe.zip
fsf-binutils-gdb-72654e04dab3d41417c2f422c8825d2b659a66fe.tar.gz
fsf-binutils-gdb-72654e04dab3d41417c2f422c8825d2b659a66fe.tar.bz2
Use accessor for mi_parse::args
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.
-rw-r--r--gdb/mi/mi-cmds.c6
-rw-r--r--gdb/mi/mi-main.c2
-rw-r--r--gdb/mi/mi-parse.c3
-rw-r--r--gdb/mi/mi-parse.h13
-rw-r--r--gdb/python/py-micmd.c5
5 files changed, 20 insertions, 9 deletions
diff --git a/gdb/mi/mi-cmds.c b/gdb/mi/mi-cmds.c
index 284453d..ca8c633 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 840663e..aaebce4 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 bda554a..bf3b534 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 75bb36b..d4ac3f0 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 d7d9591..88d52db 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;