From 72654e04dab3d41417c2f422c8825d2b659a66fe Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Mon, 20 Mar 2023 10:42:43 -0600 Subject: [PATCH] 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. --- 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.30.2