/* GDB CLI command scripting.
- Copyright (C) 1986-2017 Free Software Foundation, Inc.
+ Copyright (C) 1986-2018 Free Software Foundation, Inc.
This file is part of GDB.
/* Handle pre-post hooks. */
-static void
-clear_hook_in_cleanup (void *data)
+class scoped_restore_hook_in
{
- struct cmd_list_element *c = (struct cmd_list_element *) data;
+public:
- c->hook_in = 0; /* Allow hook to work again once it is complete. */
-}
+ scoped_restore_hook_in (struct cmd_list_element *c)
+ : m_cmd (c)
+ {
+ }
+
+ ~scoped_restore_hook_in ()
+ {
+ m_cmd->hook_in = 0;
+ }
+
+ scoped_restore_hook_in (const scoped_restore_hook_in &) = delete;
+ scoped_restore_hook_in &operator= (const scoped_restore_hook_in &) = delete;
+
+private:
+
+ struct cmd_list_element *m_cmd;
+};
void
execute_cmd_pre_hook (struct cmd_list_element *c)
{
if ((c->hook_pre) && (!c->hook_in))
{
- struct cleanup *cleanups = make_cleanup (clear_hook_in_cleanup, c);
+ scoped_restore_hook_in restore_hook (c);
c->hook_in = 1; /* Prevent recursive hooking. */
- execute_user_command (c->hook_pre, (char *) 0);
- do_cleanups (cleanups);
+ execute_user_command (c->hook_pre, nullptr);
}
}
{
if ((c->hook_post) && (!c->hook_in))
{
- struct cleanup *cleanups = make_cleanup (clear_hook_in_cleanup, c);
-
+ scoped_restore_hook_in restore_hook (c);
c->hook_in = 1; /* Prevent recursive hooking. */
- execute_user_command (c->hook_post, (char *) 0);
- do_cleanups (cleanups);
+ execute_user_command (c->hook_post, nullptr);
}
}
void
-execute_user_command (struct cmd_list_element *c, char *args)
+execute_user_command (struct cmd_list_element *c, const char *args)
{
struct ui *ui = current_ui;
struct command_line *cmdlines;
printf_filtered ("%s\n", cmd);
}
-enum command_control_type
-execute_control_command (struct command_line *cmd)
+/* Helper for execute_control_command. */
+
+static enum command_control_type
+execute_control_command_1 (struct command_line *cmd)
{
struct command_line *current;
struct value *val;
{
/* A simple command, execute it and return. */
std::string new_line = insert_user_defined_cmd_args (cmd->line);
- execute_command (&new_line[0], 0);
+ execute_command (new_line.c_str (), 0);
ret = cmd->control_type;
break;
}
{
scoped_restore save_nesting
= make_scoped_restore (&command_nest_depth, command_nest_depth + 1);
- ret = execute_control_command (current);
+ ret = execute_control_command_1 (current);
/* If we got an error, or a "break" command, then stop
looping. */
{
scoped_restore save_nesting
= make_scoped_restore (&command_nest_depth, command_nest_depth + 1);
- ret = execute_control_command (current);
+ ret = execute_control_command_1 (current);
/* If we got an error, get out. */
if (ret != simple_control)
return ret;
}
+enum command_control_type
+execute_control_command (struct command_line *cmd)
+{
+ /* Make sure we use the console uiout. It's possible that we are executing
+ breakpoint commands while running the MI interpreter. */
+ interp *console = interp_lookup (current_ui, INTERP_CONSOLE);
+ scoped_restore save_uiout
+ = make_scoped_restore (¤t_uiout, interp_ui_out (console));
+
+ return execute_control_command_1 (cmd);
+}
+
/* Like execute_control_command, but first set
suppress_next_print_command_trace. */
loop condition is nonzero. */
static void
-while_command (char *arg, int from_tty)
+while_command (const char *arg, int from_tty)
{
control_level = 1;
command_line_up command = get_command_line (while_control, arg);
on the value of the if conditional. */
static void
-if_command (char *arg, int from_tty)
+if_command (const char *arg, int from_tty)
{
control_level = 1;
command_line_up command = get_command_line (if_control, arg);
prefix. */
static struct cmd_list_element **
-validate_comname (char **comname)
+validate_comname (const char **comname)
{
struct cmd_list_element **list = &cmdlist;
- char *p, *last_word;
+ const char *p, *last_word;
if (*comname == 0)
error_no_arg (_("name of command to define"));
if (last_word != *comname)
{
struct cmd_list_element *c;
- char saved_char;
- const char *tem = *comname;
/* Separate the prefix and the command. */
- saved_char = last_word[-1];
- last_word[-1] = '\0';
+ std::string prefix (*comname, last_word - 1);
+ const char *tem = prefix.c_str ();
c = lookup_cmd (&tem, cmdlist, "", 0, 1);
if (c->prefixlist == NULL)
- error (_("\"%s\" is not a prefix command."), *comname);
+ error (_("\"%s\" is not a prefix command."), prefix.c_str ());
list = c->prefixlist;
- last_word[-1] = saved_char;
*comname = last_word;
}
/* This is just a placeholder in the command data structures. */
static void
-user_defined_command (char *ignore, int from_tty)
+user_defined_command (const char *ignore, int from_tty)
{
}
static void
-define_command (char *comname, int from_tty)
+define_command (const char *comname, int from_tty)
{
#define MAX_TMPBUF 128
enum cmd_hook_type
CMD_POST_HOOK
};
struct cmd_list_element *c, *newc, *hookc = 0, **list;
- char *tem, *comfull;
- const char *tem_c;
+ const char *tem, *comfull;
char tmpbuf[MAX_TMPBUF];
int hook_type = CMD_NO_HOOK;
int hook_name_size = 0;
list = validate_comname (&comname);
/* Look it up, and verify that we got an exact match. */
- tem_c = comname;
- c = lookup_cmd (&tem_c, *list, "", -1, 1);
+ tem = comname;
+ c = lookup_cmd (&tem, *list, "", -1, 1);
if (c && strcmp (comname, c->name) != 0)
c = 0;
if (hook_type != CMD_NO_HOOK)
{
/* Look up cmd it hooks, and verify that we got an exact match. */
- tem_c = comname + hook_name_size;
- hookc = lookup_cmd (&tem_c, *list, "", -1, 0);
+ tem = comname + hook_name_size;
+ hookc = lookup_cmd (&tem, *list, "", -1, 0);
if (hookc && strcmp (comname + hook_name_size, hookc->name) != 0)
hookc = 0;
if (!hookc)
}
static void
-document_command (char *comname, int from_tty)
+document_command (const char *comname, int from_tty)
{
struct cmd_list_element *c, **list;
const char *tem;
- char *comfull;
+ const char *comfull;
char tmpbuf[128];
comfull = comname;