gdb/riscv: Remove 'Contributed by....' comments
[deliverable/binutils-gdb.git] / gdb / cli / cli-script.c
index dc3e856bcfddda51a0316b9baf114494dd5d5936..366c42227c620b73f5497b18fe0372a2c04d2b3c 100644 (file)
@@ -1,6 +1,6 @@
 /* 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.
 
@@ -340,23 +340,36 @@ print_command_lines (struct ui_out *uiout, struct command_line *cmd,
 
 /* 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);
     }
 }
 
@@ -365,16 +378,14 @@ execute_cmd_post_hook (struct cmd_list_element *c)
 {
   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;
@@ -452,8 +463,10 @@ print_command_trace (const char *cmd)
   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;
@@ -471,7 +484,7 @@ execute_control_command (struct command_line *cmd)
       {
        /* 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;
       }
@@ -530,7 +543,7 @@ execute_control_command (struct command_line *cmd)
              {
                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.  */
@@ -589,7 +602,7 @@ execute_control_command (struct command_line *cmd)
          {
            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)
@@ -633,6 +646,18 @@ execute_control_command (struct command_line *cmd)
   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 (&current_uiout, interp_ui_out (console));
+
+  return execute_control_command_1 (cmd);
+}
+
 /* Like execute_control_command, but first set
    suppress_next_print_command_trace.  */
 
@@ -648,7 +673,7 @@ execute_control_command_untraced (struct command_line *cmd)
    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);
@@ -665,7 +690,7 @@ while_command (char *arg, int from_tty)
    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);
@@ -1341,10 +1366,10 @@ copy_command_lines (struct command_line *cmds)
    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"));
@@ -1361,19 +1386,16 @@ validate_comname (char **comname)
   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;
     }
 
@@ -1390,12 +1412,12 @@ validate_comname (char **comname)
 
 /* 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
@@ -1405,8 +1427,7 @@ define_command (char *comname, int from_tty)
       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;
@@ -1420,8 +1441,8 @@ define_command (char *comname, int from_tty)
   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;
 
@@ -1455,8 +1476,8 @@ define_command (char *comname, int from_tty)
   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)
@@ -1506,11 +1527,11 @@ define_command (char *comname, int from_tty)
 }
 
 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;
This page took 0.028217 seconds and 4 git commands to generate.