parse->parse_argv ();
if (parse->argv == nullptr)
- error (_("Problem parsing arguments: %s %s"), parse->command,
+ error (_("Problem parsing arguments: %s %s"), parse->command.get (),
parse->args ());
- this->m_argv_function (parse->command, parse->argv, parse->argc);
+ this->m_argv_function (parse->command.get (), parse->argv, parse->argc);
}
private:
if (mi_debug_p)
gdb_printf (gdb_stdlog,
" token=`%s' command=`%s' args=`%s'\n",
- context->token.c_str (), context->command, context->args ());
+ context->token.c_str (), context->command.get (),
+ context->args ());
mi_cmd_execute (context);
gdb_puts (context->token.c_str (), mi->raw_stdout);
/* There's no particularly good reason why target-connect results
in not ^done. Should kill ^connected for MI3. */
- gdb_puts (strcmp (context->command, "target-select") == 0
+ gdb_puts (strcmp (context->command.get (), "target-select") == 0
? "^connected" : "^done", mi->raw_stdout);
mi_out_put (uiout, mi->raw_stdout);
mi_out_rewind (uiout);
/* This "feature" will be removed as soon as we have a
complete set of mi commands. */
/* Echo the command on the console. */
- gdb_printf (gdb_stdlog, "%s\n", context->command);
+ gdb_printf (gdb_stdlog, "%s\n", context->command.get ());
/* Call the "console" interpreter. */
argv[0] = INTERP_CONSOLE;
- argv[1] = context->command;
+ argv[1] = context->command.get ();
mi_cmd_interpreter_exec ("-interpreter-exec", argv, 2);
/* If we changed interpreters, DON'T print out anything. */
mi_parse::~mi_parse ()
{
- xfree (command);
freeargv (argv);
}
if (*chp != '-')
{
chp = skip_spaces (chp);
- parse->command = xstrdup (chp);
+ parse->command = make_unique_xstrdup (chp);
parse->op = CLI_COMMAND;
return parse;
for (; *chp && !isspace (*chp); chp++)
;
- parse->command = (char *) xmalloc (chp - tmp + 1);
- memcpy (parse->command, tmp, chp - tmp);
- parse->command[chp - tmp] = '\0';
+ parse->command = make_unique_xstrndup (tmp, chp - tmp);
}
/* Find the command in the MI table. */
- parse->cmd = mi_cmd_lookup (parse->command);
+ parse->cmd = mi_cmd_lookup (parse->command.get ());
if (parse->cmd == NULL)
throw_error (UNDEFINED_COMMAND_ERROR,
- _("Undefined MI command: %s"), parse->command);
+ _("Undefined MI command: %s"), parse->command.get ());
/* Skip white space following the command. */
chp = skip_spaces (chp);
{
std::unique_ptr<struct mi_parse> parse (new struct mi_parse);
- parse->command = command.release ();
+ parse->command = std::move (command);
parse->token = "";
- if (parse->command[0] != '-')
+ if (parse->command.get ()[0] != '-')
throw_error (UNDEFINED_COMMAND_ERROR,
_("MI command '%s' does not start with '-'"),
- parse->command);
+ parse->command.get ());
/* Find the command in the MI table. */
- parse->cmd = mi_cmd_lookup (parse->command + 1);
+ parse->cmd = mi_cmd_lookup (parse->command.get () + 1);
if (parse->cmd == NULL)
throw_error (UNDEFINED_COMMAND_ERROR,
- _("Undefined MI command: %s"), parse->command);
+ _("Undefined MI command: %s"), parse->command.get ());
/* This over-allocates slightly, but it seems unimportant. */
parse->argv = XCNEWVEC (char *, args.size () + 1);
const char *args ();
enum mi_command_type op = MI_COMMAND;
- char *command = nullptr;
+ /* This is not std::string because it avoids a copy in the Python
+ API case. */
+ gdb::unique_xmalloc_ptr<char> command;
std::string token;
const struct mi_command *cmd = nullptr;
struct mi_timestamp *cmd_start = nullptr;
parse->parse_argv ();
if (parse->argv == nullptr)
- error (_("Problem parsing arguments: %s %s"), parse->command,
+ error (_("Problem parsing arguments: %s %s"), parse->command.get (),
parse->args ());