Support R_SPARC_WDISP10 and R_SPARC_H34.
[external/binutils.git] / gdb / cli / cli-script.c
index 660ea46..cfa1c77 100644 (file)
@@ -1,8 +1,6 @@
 /* GDB CLI command scripting.
 
-   Copyright (c) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
-   1996, 1997, 1998, 1999, 2000, 2001, 2002, 2004, 2005, 2006, 2007, 2008,
-   2009, 2010 Free Software Foundation, Inc.
+   Copyright (c) 1986-2002, 2004-2012 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -35,8 +33,9 @@
 #include "gdb_assert.h"
 
 #include "python/python.h"
+#include "interps.h"
 
-/* Prototypes for local functions */
+/* Prototypes for local functions */
 
 static enum command_control_type
 recurse_read_control_structure (char * (*read_next_line_func) (void),
@@ -65,7 +64,8 @@ struct user_args
   {
     struct user_args *next;
     /* It is necessary to store a malloced copy of the command line to
-       ensure that the arguments are not overwritten before they are used.  */
+       ensure that the arguments are not overwritten before they are
+       used.  */
     char *command;
     struct
       {
@@ -142,7 +142,6 @@ print_command_lines (struct ui_out *uiout, struct command_line *cmd,
   list = cmd;
   while (list)
     {
-
       if (depth)
        ui_out_spaces (uiout, 2 * depth);
 
@@ -165,7 +164,8 @@ print_command_lines (struct ui_out *uiout, struct command_line *cmd,
          continue;
        }
 
-      /* loop_break to break out of a while loop, print it and continue.  */
+      /* loop_break to break out of a while loop, print it and
+        continue.  */
       if (list->control_type == break_control)
        {
          ui_out_field_string (uiout, NULL, "loop_break");
@@ -174,13 +174,14 @@ print_command_lines (struct ui_out *uiout, struct command_line *cmd,
          continue;
        }
 
-      /* A while command.  Recursively print its subcommands and continue.  */
+      /* A while command.  Recursively print its subcommands and
+        continue.  */
       if (list->control_type == while_control
          || list->control_type == while_stepping_control)
        {
-         /* For while-stepping, the line includes the 'while-stepping' token.
-            See comment in process_next_line for explanation.  Here,
-            take care not print 'while-stepping' twice.  */
+         /* For while-stepping, the line includes the 'while-stepping'
+            token.  See comment in process_next_line for explanation.
+            Here, take care not print 'while-stepping' twice.  */
          if (list->control_type == while_control)
            ui_out_field_fmt (uiout, NULL, "while %s", list->line);
          else
@@ -195,12 +196,13 @@ print_command_lines (struct ui_out *uiout, struct command_line *cmd,
          continue;
        }
 
-      /* An if command.  Recursively print both arms before continueing.  */
+      /* An if command.  Recursively print both arms before
+        continueing.  */
       if (list->control_type == if_control)
        {
          ui_out_field_fmt (uiout, NULL, "if %s", list->line);
          ui_out_text (uiout, "\n");
-         /* The true arm. */
+         /* The true arm.  */
          print_command_lines (uiout, list->body_list[0], depth + 1);
 
          /* Show the false arm if it exists.  */
@@ -221,7 +223,8 @@ print_command_lines (struct ui_out *uiout, struct command_line *cmd,
          continue;
        }
 
-      /* A commands command.  Print the breakpoint commands and continue.  */
+      /* A commands command.  Print the breakpoint commands and
+        continue.  */
       if (list->control_type == commands_control)
        {
          if (*(list->line))
@@ -252,7 +255,7 @@ print_command_lines (struct ui_out *uiout, struct command_line *cmd,
          continue;
        }
 
-      /* ignore illegal command type and try next */
+      /* Ignore illegal command type and try next.  */
       list = list->next;
     }                          /* while (list) */
 }
@@ -263,7 +266,8 @@ static void
 clear_hook_in_cleanup (void *data)
 {
   struct cmd_list_element *c = data;
-  c->hook_in = 0; /* Allow hook to work again once it is complete */
+
+  c->hook_in = 0; /* Allow hook to work again once it is complete.  */
 }
 
 void
@@ -272,7 +276,7 @@ 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);
-      c->hook_in = 1; /* Prevent recursive hooking */
+      c->hook_in = 1; /* Prevent recursive hooking */
       execute_user_command (c->hook_pre, (char *) 0);
       do_cleanups (cleanups);
     }
@@ -284,7 +288,8 @@ 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);
-      c->hook_in = 1; /* Prevent recursive hooking */
+
+      c->hook_in = 1; /* Prevent recursive hooking.  */
       execute_user_command (c->hook_post, (char *) 0);
       do_cleanups (cleanups);
     }
@@ -294,7 +299,8 @@ execute_cmd_post_hook (struct cmd_list_element *c)
 static void
 do_restore_user_call_depth (void * call_depth)
 {      
-  int * depth = call_depth;
+  int *depth = call_depth;
+
   (*depth)--;
   if ((*depth) == 0)
     in_user_command = 0;
@@ -310,13 +316,13 @@ execute_user_command (struct cmd_list_element *c, char *args)
   static int user_call_depth = 0;
   extern int max_user_call_depth;
 
-  old_chain = setup_user_args (args);
-
   cmdlines = c->user_commands;
   if (cmdlines == 0)
     /* Null command */
     return;
 
+  old_chain = setup_user_args (args);
+
   if (++user_call_depth > max_user_call_depth)
     error (_("Max user call depth exceeded -- command aborted."));
 
@@ -331,6 +337,9 @@ execute_user_command (struct cmd_list_element *c, char *args)
      not confused with Insight.  */
   in_user_command = 1;
 
+  make_cleanup_restore_integer (&interpreter_async);
+  interpreter_async = 0;
+
   command_nest_depth++;
   while (cmdlines)
     {
@@ -346,8 +355,8 @@ execute_user_command (struct cmd_list_element *c, char *args)
   do_cleanups (old_chain);
 }
 
-/* This function is called every time GDB prints a prompt.
-   It ensures that errors and the like to not confuse the command tracing.  */
+/* This function is called every time GDB prints a prompt.  It ensures
+   that errors and the like do not confuse the command tracing.  */
 
 void
 reset_command_nest_depth (void)
@@ -433,6 +442,7 @@ execute_control_command (struct command_line *cmd)
     case while_control:
       {
        char *buffer = alloca (strlen (cmd->line) + 7);
+
        sprintf (buffer, "while %s", cmd->line);
        print_command_trace (buffer);
 
@@ -500,6 +510,7 @@ execute_control_command (struct command_line *cmd)
     case if_control:
       {
        char *buffer = alloca (strlen (cmd->line) + 4);
+
        sprintf (buffer, "if %s", cmd->line);
        print_command_trace (buffer);
 
@@ -518,8 +529,8 @@ execute_control_command (struct command_line *cmd)
        val_mark = value_mark ();
        val = evaluate_expression (expr);
 
-       /* Choose which arm to take commands from based on the value of the
-          conditional expression.  */
+       /* Choose which arm to take commands from based on the value
+          of the conditional expression.  */
        if (value_true (val))
          current = *cmd->body_list;
        else if (cmd->body_count == 2)
@@ -545,8 +556,8 @@ execute_control_command (struct command_line *cmd)
       }
     case commands_control:
       {
-       /* Breakpoint commands list, record the commands in the breakpoint's
-          command list and return.  */
+       /* Breakpoint commands list, record the commands in the
+          breakpoint's command list and return.  */
        new_line = insert_args (cmd->line);
        if (!new_line)
          break;
@@ -572,7 +583,7 @@ execute_control_command (struct command_line *cmd)
 }
 
 /* Like execute_control_command, but first set
-   suppress_next_print_command_trace.   */
+   suppress_next_print_command_trace.  */
 
 enum command_control_type
 execute_control_command_untraced (struct command_line *cmd)
@@ -589,6 +600,7 @@ void
 while_command (char *arg, int from_tty)
 {
   struct command_line *command = NULL;
+  struct cleanup *old_chain;
 
   control_level = 1;
   command = get_command_line (while_control, arg);
@@ -596,8 +608,13 @@ while_command (char *arg, int from_tty)
   if (command == NULL)
     return;
 
+  old_chain = make_cleanup_restore_integer (&interpreter_async);
+  interpreter_async = 0;
+
   execute_control_command_untraced (command);
   free_command_lines (&command);
+
+  do_cleanups (old_chain);
 }
 
 /* "if" command support.  Execute either the true or false arm depending
@@ -607,6 +624,7 @@ void
 if_command (char *arg, int from_tty)
 {
   struct command_line *command = NULL;
+  struct cleanup *old_chain;
 
   control_level = 1;
   command = get_command_line (if_control, arg);
@@ -614,8 +632,13 @@ if_command (char *arg, int from_tty)
   if (command == NULL)
     return;
 
+  old_chain = make_cleanup_restore_integer (&interpreter_async);
+  interpreter_async = 0;
+
   execute_control_command_untraced (command);
   free_command_lines (&command);
+
+  do_cleanups (old_chain);
 }
 
 /* Cleanup */
@@ -623,6 +646,7 @@ static void
 arg_cleanup (void *ignore)
 {
   struct user_args *oargs = user_args;
+
   if (!user_args)
     internal_error (__FILE__, __LINE__,
                    _("arg_cleanup called with no user args.\n"));
@@ -716,8 +740,8 @@ setup_user_args (char *p)
   return old_chain;
 }
 
-/* Given character string P, return a point to the first argument ($arg),
-   or NULL if P contains no arguments.  */
+/* Given character string P, return a point to the first argument
+   ($arg), or NULL if P contains no arguments.  */
 
 static char *
 locate_arg (char *p)
@@ -733,7 +757,8 @@ locate_arg (char *p)
 }
 
 /* Insert the user defined arguments stored in user_arg into the $arg
-   arguments found in line, with the updated copy being placed into nline.  */
+   arguments found in line, with the updated copy being placed into
+   nline.  */
 
 static char *
 insert_args (char *line)
@@ -746,7 +771,8 @@ insert_args (char *line)
   if (user_args == NULL)
     return xstrdup (line);
 
-  /* First we need to know how much memory to allocate for the new line.  */
+  /* First we need to know how much memory to allocate for the new
+     line.  */
   save_line = line;
   len = 0;
   while ((p = locate_arg (line)))
@@ -808,10 +834,10 @@ insert_args (char *line)
          i = p[4] - '0';
          len = user_args->a[i].len;
          if (len)
-         {
-           memcpy (new_line, user_args->a[i].arg, len);
-           new_line += len;
-         }
+           {
+             memcpy (new_line, user_args->a[i].arg, len);
+             new_line += len;
+           }
        }
       line = p + 5;
     }
@@ -878,11 +904,12 @@ read_next_line (void)
   return command_line_input (prompt_ptr, instream == stdin, "commands");
 }
 
-/* Process one input line.  If the command is an "end",
-   return such an indication to the caller.  If PARSE_COMMANDS is true,
-   strip leading whitespace (trailing whitespace is always stripped)
-   in the line, attempt to recognize GDB control commands, and also
-   return an indication if the command is an "else" or a nop.
+/* Process one input line.  If the command is an "end", return such an
+   indication to the caller.  If PARSE_COMMANDS is true, strip leading
+   whitespace (trailing whitespace is always stripped) in the line,
+   attempt to recognize GDB control commands, and also return an
+   indication if the command is an "else" or a nop.
+
    Otherwise, only "end" is recognized.  */
 
 static enum misc_command_type
@@ -907,21 +934,21 @@ process_next_line (char *p, struct command_line **command, int parse_commands,
   while (p_start < p_end && (*p_start == ' ' || *p_start == '\t'))
     p_start++;
 
-  /* 'end' is always recognized, regardless of parse_commands value. 
+  /* 'end' is always recognized, regardless of parse_commands value.
      We also permit whitespace before end and after.  */
   if (p_end - p_start == 3 && !strncmp (p_start, "end", 3))
     return end_command;
   
   if (parse_commands)
     {
-      /* If commands are parsed, we skip initial spaces. Otherwise,
+      /* If commands are parsed, we skip initial spaces.  Otherwise,
         which is the case for Python commands and documentation
         (see the 'document' command), spaces are preserved.  */
       p = p_start;
 
       /* Blanks and comments don't really do anything, but we need to
-        distinguish them from else, end and other commands which can be
-        executed.  */
+        distinguish them from else, end and other commands which can
+        be executed.  */
       if (p_end == p || p[0] == '#')
        return nop_command;
 
@@ -929,26 +956,29 @@ process_next_line (char *p, struct command_line **command, int parse_commands,
       if (p_end - p == 4 && !strncmp (p, "else", 4))
        return else_command;
 
-      /* Check for while, if, break, continue, etc and build a new command
-        line structure for them.  */
+      /* Check for while, if, break, continue, etc and build a new
+        command line structure for them.  */
       if ((p_end - p >= 14 && !strncmp (p, "while-stepping", 14))
-         || (p_end -p >= 2 && !strncmp (p, "ws", 2)))
+         || (p_end - p >= 8 && !strncmp (p, "stepping", 8))
+         || (p_end - p >= 2 && !strncmp (p, "ws", 2)))
        {
          /* Because validate_actionline and encode_action lookup
             command's line as command, we need the line to
             include 'while-stepping'.
 
             For 'ws' alias, the command will have 'ws', not expanded
-            to 'while-stepping'. This is intentional -- we don't
+            to 'while-stepping'.  This is intentional -- we don't
             really want frontend to send a command list with 'ws',
-            and next break-info returning command line with 'while-stepping'.
-            This should work, but might cause the breakpoint to be marked as
-            changed while it's actually not.  */
+            and next break-info returning command line with
+            'while-stepping'.  This should work, but might cause the
+            breakpoint to be marked as changed while it's actually
+            not.  */
          *command = build_command_line (while_stepping_control, p);
        }
       else if (p_end - p > 5 && !strncmp (p, "while", 5))
        {
          char *first_arg;
+
          first_arg = p + 5;
          while (first_arg < p_end && isspace (*first_arg))
            first_arg++;
@@ -957,6 +987,7 @@ process_next_line (char *p, struct command_line **command, int parse_commands,
       else if (p_end - p > 2 && !strncmp (p, "if", 2))
        {
          char *first_arg;
+
          first_arg = p + 2;
          while (first_arg < p_end && isspace (*first_arg))
            first_arg++;
@@ -965,6 +996,7 @@ process_next_line (char *p, struct command_line **command, int parse_commands,
       else if (p_end - p >= 8 && !strncmp (p, "commands", 8))
        {
          char *first_arg;
+
          first_arg = p + 8;
          while (first_arg < p_end && isspace (*first_arg))
            first_arg++;
@@ -1015,6 +1047,7 @@ process_next_line (char *p, struct command_line **command, int parse_commands,
   if (validator)
     {
       volatile struct gdb_exception ex;
+
       TRY_CATCH (ex, RETURN_MASK_ALL)
        {
          validator ((*command)->line, closure);
@@ -1030,11 +1063,9 @@ process_next_line (char *p, struct command_line **command, int parse_commands,
   return ok_command;
 }
 
-/* Recursively read in the control structures and create a command_line 
-   structure from them.  Use read_next_line_func to obtain lines of
-   the command.
-
-*/
+/* Recursively read in the control structures and create a
+   command_line structure from them.  Use read_next_line_func to
+   obtain lines of the command.  */
 
 static enum command_control_type
 recurse_read_control_structure (char * (*read_next_line_func) (void),
@@ -1046,7 +1077,6 @@ recurse_read_control_structure (char * (*read_next_line_func) (void),
   enum misc_command_type val;
   enum command_control_type ret;
   struct command_line **body_ptr, *child_tail, *next;
-  char *p;
 
   child_tail = NULL;
   current_body = 1;
@@ -1169,8 +1199,9 @@ read_command_lines (char *prompt_arg, int from_tty, int parse_commands,
     {
       if (deprecated_readline_begin_hook)
        {
-         /* Note - intentional to merge messages with no newline */
-         (*deprecated_readline_begin_hook) ("%s  %s\n", prompt_arg, END_MESSAGE);
+         /* Note - intentional to merge messages with no newline.  */
+         (*deprecated_readline_begin_hook) ("%s  %s\n", prompt_arg,
+                                            END_MESSAGE);
        }
       else
        {
@@ -1407,8 +1438,8 @@ define_command (char *comname, int from_tty)
       CMD_POST_HOOK
     };
   struct command_line *cmds;
-  struct cmd_list_element *c, *newc, *oldc, *hookc = 0, **list;
-  char *tem, *tem2, *comfull;
+  struct cmd_list_element *c, *newc, *hookc = 0, **list;
+  char *tem, *comfull;
   char tmpbuf[MAX_TMPBUF];
   int  hook_type      = CMD_NO_HOOK;
   int  hook_name_size = 0;
@@ -1430,6 +1461,7 @@ define_command (char *comname, int from_tty)
   if (c)
     {
       int q;
+
       if (c->class == class_user || c->class == class_alias)
        q = query (_("Redefine command \"%s\"? "), c->name);
       else
@@ -1462,7 +1494,8 @@ define_command (char *comname, int from_tty)
        hookc = 0;
       if (!hookc)
        {
-         warning (_("Your new `%s' command does not hook any existing command."),
+         warning (_("Your new `%s' command does not "
+                    "hook any existing command."),
                   comfull);
          if (!query (_("Proceed? ")))
            error (_("Not confirmed."));
@@ -1472,7 +1505,7 @@ define_command (char *comname, int from_tty)
   comname = xstrdup (comname);
 
   /* If the rest of the commands will be case insensitive, this one
-     should behave in the same manner. */
+     should behave in the same manner.  */
   for (tem = comname; *tem; tem++)
     if (isupper (*tem))
       *tem = tolower (*tem);
@@ -1496,14 +1529,15 @@ define_command (char *comname, int from_tty)
         {
         case CMD_PRE_HOOK:
           hookc->hook_pre  = newc;  /* Target gets hooked.  */
-          newc->hookee_pre = hookc; /* We are marked as hooking target cmd. */
+          newc->hookee_pre = hookc; /* We are marked as hooking target cmd.  */
           break;
         case CMD_POST_HOOK:
           hookc->hook_post  = newc;  /* Target gets hooked.  */
-          newc->hookee_post = hookc; /* We are marked as hooking target cmd. */
+          newc->hookee_post = hookc; /* We are marked as hooking
+                                       target cmd.  */
           break;
         default:
-          /* Should never come here as hookc would be 0. */
+          /* Should never come here as hookc would be 0.  */
          internal_error (__FILE__, __LINE__, _("bad switch"));
         }
     }
@@ -1556,59 +1590,46 @@ document_command (char *comname, int from_tty)
 struct source_cleanup_lines_args
 {
   int old_line;
-  char *old_file;
+  const char *old_file;
 };
 
 static void
 source_cleanup_lines (void *args)
 {
   struct source_cleanup_lines_args *p =
-  (struct source_cleanup_lines_args *) args;
+    (struct source_cleanup_lines_args *) args;
+
   source_line_number = p->old_line;
   source_file_name = p->old_file;
 }
 
-struct wrapped_read_command_file_args
-{
-  FILE *stream;
-};
-
-static void
-wrapped_read_command_file (struct ui_out *uiout, void *data)
-{
-  struct wrapped_read_command_file_args *args = data;
-  read_command_file (args->stream);
-}
-
-/* Used to implement source_command */
+/* Used to implement source_command.  */
 
 void
-script_from_file (FILE *stream, char *file)
+script_from_file (FILE *stream, const char *file)
 {
   struct cleanup *old_cleanups;
   struct source_cleanup_lines_args old_lines;
-  int needed_length;
 
   if (stream == NULL)
     internal_error (__FILE__, __LINE__, _("called with NULL file pointer!"));
 
-  old_cleanups = make_cleanup_fclose (stream);
-
   old_lines.old_line = source_line_number;
   old_lines.old_file = source_file_name;
-  make_cleanup (source_cleanup_lines, &old_lines);
+  old_cleanups = make_cleanup (source_cleanup_lines, &old_lines);
   source_line_number = 0;
   source_file_name = file;
-  /* This will get set every time we read a line.  So it won't stay "" for
-     long.  */
+  /* This will get set every time we read a line.  So it won't stay ""
+     for long.  */
   error_pre_print = "";
 
   {
-    struct gdb_exception e;
-    struct wrapped_read_command_file_args args;
-    args.stream = stream;
-    e = catch_exception (uiout, wrapped_read_command_file, &args,
-                        RETURN_MASK_ERROR);
+    volatile struct gdb_exception e;
+
+    TRY_CATCH (e, RETURN_MASK_ERROR)
+      {
+       read_command_file (stream);
+      }
     switch (e.reason)
       {
       case 0:
@@ -1640,6 +1661,7 @@ show_user_1 (struct cmd_list_element *c, char *prefix, char *name,
   if (c->prefixlist != NULL)
     {
       char *prefixname = c->prefixname;
+
       for (c = *c->prefixlist; c != NULL; c = c->next)
        if (c->class == class_user || c->prefixlist != NULL)
          show_user_1 (c, prefixname, c->name, gdb_stdout);
@@ -1651,7 +1673,7 @@ show_user_1 (struct cmd_list_element *c, char *prefix, char *name,
     return;
   fprintf_filtered (stream, "User command \"%s%s\":\n", prefix, name);
 
-  print_command_lines (uiout, cmdlines, 1);
+  print_command_lines (current_uiout, cmdlines, 1);
   fputs_filtered ("\n", stream);
 }