static int do_timings = 0;
-char *current_token;
+const char *current_token;
/* Few commands would like to know if options like --thread-group were
explicitly specified. This variable keeps the current parsed
command including all option, and make it possible. */
current_command_ts = context->cmd_start;
scoped_restore save_token = make_scoped_restore (¤t_token,
- context->token);
+ context->token.c_str ());
mi->running_result_record_printed = 0;
mi->mi_proceeded = 0;
if (mi_debug_p)
gdb_printf (gdb_stdlog,
" token=`%s' command=`%s' args=`%s'\n",
- context->token, context->command, context->args ());
+ context->token.c_str (), context->command, context->args ());
mi_cmd_execute (context);
uiout will most likely crash in the mi_out_* routines. */
if (!mi->running_result_record_printed)
{
- gdb_puts (context->token, mi->raw_stdout);
+ 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
{
if (!mi->running_result_record_printed)
{
- gdb_puts (context->token, mi->raw_stdout);
+ gdb_puts (context->token.c_str (), mi->raw_stdout);
gdb_puts ("^done", mi->raw_stdout);
mi_out_put (uiout, mi->raw_stdout);
mi_out_rewind (uiout);
void
mi_execute_command (const char *cmd, int from_tty)
{
- char *token;
+ std::string token;
std::unique_ptr<struct mi_parse> command;
/* This is to handle EOF (^D). We just quit gdb. */
}
catch (const gdb_exception &exception)
{
- mi_print_exception (token, exception);
- xfree (token);
+ mi_print_exception (token.c_str (), exception);
}
if (command != NULL)
{
- command->token = token;
+ command->token = std::move (token);
if (do_timings)
{
/* The command execution failed and error() was called
somewhere. */
- mi_print_exception (command->token, result);
+ mi_print_exception (command->token.c_str (), result);
mi_out_rewind (current_uiout);
/* Throw to a higher level catch for SIGTERM sent to GDB. */
error (_("Command is not an MI command"));
scoped_restore save_token = make_scoped_restore (¤t_token,
- context->token);
+ context->token.c_str ());
scoped_restore save_debug = make_scoped_restore (&mi_debug_p, 0);
mi_cmd_execute (context);
mi_parse::~mi_parse ()
{
xfree (command);
- xfree (token);
freeargv (argv);
}
}
std::unique_ptr<struct mi_parse>
-mi_parse::make (const char *cmd, char **token)
+mi_parse::make (const char *cmd, std::string *token)
{
const char *chp;
/* Find/skip any token and then extract it. */
for (chp = cmd; *chp >= '0' && *chp <= '9'; chp++)
;
- *token = (char *) xmalloc (chp - cmd + 1);
- memcpy (*token, cmd, (chp - cmd));
- (*token)[chp - cmd] = '\0';
+ *token = std::string (cmd, chp - cmd);
/* This wasn't a real MI command. Return it as a CLI_COMMAND. */
if (*chp != '-')
std::unique_ptr<struct mi_parse> parse (new struct mi_parse);
parse->command = command.release ();
- parse->token = xstrdup ("");
+ parse->token = "";
if (parse->command[0] != '-')
throw_error (UNDEFINED_COMMAND_ERROR,
/* Attempts to parse CMD returning a ``struct mi_parse''. If CMD is
invalid, an exception is thrown. For an MI_COMMAND COMMAND, ARGS
and OP are initialized. Un-initialized fields are zero. *TOKEN is
- set to the token, even if an exception is thrown. It is allocated
- with xmalloc; it must either be freed with xfree, or assigned to
- the TOKEN field of the resultant mi_parse object, to be freed by
- mi_parse_free. */
+ set to the token, even if an exception is thrown. It can be
+ assigned to the TOKEN field of the resultant mi_parse object,
+ to be freed by mi_parse_free. */
static std::unique_ptr<struct mi_parse> make (const char *cmd,
- char **token);
+ std::string *token);
/* Create an mi_parse object given the command name and a vector
of arguments. Unlike with the other constructor, here the
enum mi_command_type op = MI_COMMAND;
char *command = nullptr;
- char *token = nullptr;
+ std::string token;
const struct mi_command *cmd = nullptr;
struct mi_timestamp *cmd_start = nullptr;
char **argv = nullptr;