2011-07-21 Phil Muldoon <pmuldoon@redhat.com>
[deliverable/binutils-gdb.git] / gdb / top.c
index 702e05b271cff0418e8df60f9fd5c6128d57e823..3ffd000257544e6d3182bc6f108804a46a75e017 100644 (file)
--- a/gdb/top.c
+++ b/gdb/top.c
@@ -102,8 +102,8 @@ static void
 show_caution (struct ui_file *file, int from_tty,
              struct cmd_list_element *c, const char *value)
 {
-  fprintf_filtered (file, _("\
-Whether to confirm potentially dangerous operations is %s.\n"),
+  fprintf_filtered (file, _("Whether to confirm potentially "
+                           "dangerous operations is %s.\n"),
                    value);
 }
 
@@ -137,8 +137,8 @@ int xgdb_verbose;
 /* Buffer used for reading command lines, and the size
    allocated for it so far.  */
 
-char *line;
-int linesize = 100;
+char *saved_command_line;
+int saved_command_line_size = 100;
 
 /* Nonzero if the current command is modified by "server ".  This
    affects things like recording into the command history, commands
@@ -250,7 +250,7 @@ void (*deprecated_detach_hook) (void);
 
 void (*deprecated_interactive_hook) (void);
 
-/* Tell the GUI someone changed the register REGNO. -1 means
+/* Tell the GUI someone changed the register REGNO.  -1 means
    that the caller does not know which register changed or
    that several registers have changed (see value_assign).  */
 void (*deprecated_register_changed_hook) (int regno);
@@ -282,7 +282,7 @@ void (*deprecated_context_hook) (int id);
 #ifdef SIGHUP
 /* NOTE 1999-04-29: This function will be static again, once we modify
    gdb to use the event loop as the default command loop and we merge
-   event-top.c into this file, top.c */
+   event-top.c into this file, top.c */
 /* static */ int
 quit_cover (void *s)
 {
@@ -294,16 +294,16 @@ quit_cover (void *s)
 }
 #endif /* defined SIGHUP */
 \f
-/* Line number we are currently in in a file which is being sourced.  */
+/* Line number we are currently in, in a file which is being sourced.  */
 /* NOTE 1999-04-29: This variable will be static again, once we modify
    gdb to use the event loop as the default command loop and we merge
-   event-top.c into this file, top.c */
+   event-top.c into this file, top.c */
 /* static */ int source_line_number;
 
 /* Name of the file we are sourcing.  */
 /* NOTE 1999-04-29: This variable will be static again, once we modify
    gdb to use the event loop as the default command loop and we merge
-   event-top.c into this file, top.c */
+   event-top.c into this file, top.c */
 /* static */ const char *source_file_name;
 
 /* Clean up on error during a "source" command (or execution of a
@@ -339,10 +339,14 @@ do_chdir_cleanup (void *old_dir)
 }
 #endif
 
-void
+struct cleanup *
 prepare_execute_command (void)
 {
-  free_all_values ();
+  struct value *mark;
+  struct cleanup *cleanup;
+
+  mark = value_mark ();
+  cleanup = make_cleanup_value_free_to_mark (mark);
 
   /* With multiple threads running while the one we're examining is
      stopped, the dcache can get stale without us being able to detect
@@ -350,6 +354,8 @@ prepare_execute_command (void)
      help things like backtrace.  */
   if (non_stop)
     target_dcache_invalidate ();
+
+  return cleanup;
 }
 
 /* Execute the line P as a command, in the current user context.
@@ -358,12 +364,13 @@ prepare_execute_command (void)
 void
 execute_command (char *p, int from_tty)
 {
+  struct cleanup *cleanup;
   struct cmd_list_element *c;
   enum language flang;
   static int warned = 0;
   char *line;
 
-  prepare_execute_command ();
+  cleanup = prepare_execute_command ();
 
   /* Force cleanup of any alloca areas if using C alloca instead of
      a builtin alloca.  */
@@ -371,7 +378,10 @@ execute_command (char *p, int from_tty)
 
   /* This can happen when command_line_input hits end of file.  */
   if (p == NULL)
-    return;
+    {
+      do_cleanups (cleanup);
+      return;
+    }
 
   target_log_command (p);
 
@@ -462,6 +472,8 @@ execute_command (char *p, int from_tty)
          warned = 1;
        }
     }
+
+    do_cleanups (cleanup);
 }
 
 /* Run execute_command for P and FROM_TTY.  Capture its output into the
@@ -528,12 +540,15 @@ command_loop (void)
        reinitialize_more_filter ();
       old_chain = make_cleanup (null_cleanup, 0);
 
-      /* Get a command-line. This calls the readline package.  */
+      /* Get a command-line.  This calls the readline package.  */
       command = command_line_input (instream == stdin ?
                                    get_prompt () : (char *) NULL,
                                    instream == stdin, "prompt");
       if (command == 0)
-       return;
+       {
+         do_cleanups (old_chain);
+         return;
+       }
 
       make_command_stats_cleanup (1);
 
@@ -546,20 +561,38 @@ command_loop (void)
     }
 }
 \f
+/* When nonzero, cause dont_repeat to do nothing.  This should only be
+   set via prevent_dont_repeat.  */
+
+static int suppress_dont_repeat = 0;
+
 /* Commands call this if they do not want to be repeated by null lines.  */
 
 void
 dont_repeat (void)
 {
-  if (server_command)
+  if (suppress_dont_repeat || server_command)
     return;
 
   /* If we aren't reading from standard input, we are saving the last
      thing read from stdin in line and don't want to delete it.  Null
      lines won't repeat here in any case.  */
   if (instream == stdin)
-    *line = 0;
+    *saved_command_line = 0;
 }
+
+/* Prevent dont_repeat from working, and return a cleanup that
+   restores the previous state.  */
+
+struct cleanup *
+prevent_dont_repeat (void)
+{
+  struct cleanup *result = make_cleanup_restore_integer (&suppress_dont_repeat);
+
+  suppress_dont_repeat = 1;
+  return result;
+}
+
 \f
 /* Read a line from the stream "instream" without command line editing.
 
@@ -630,7 +663,7 @@ static int command_editing_p;
 
 /* NOTE 1999-04-29: This variable will be static again, once we modify
    gdb to use the event loop as the default command loop and we merge
-   event-top.c into this file, top.c */
+   event-top.c into this file, top.c */
 
 /* static */ int history_expansion_p;
 
@@ -657,8 +690,8 @@ static void
 show_history_filename (struct ui_file *file, int from_tty,
                       struct cmd_list_element *c, const char *value)
 {
-  fprintf_filtered (file, _("\
-The filename in which to record the command history is \"%s\".\n"),
+  fprintf_filtered (file, _("The filename in which to record "
+                           "the command history is \"%s\".\n"),
                    value);
 }
 
@@ -990,7 +1023,8 @@ command_line_input (char *prompt_arg, int repeat, char *annotation_suffix)
          if (expanded < 0)
            {
              xfree (history_value);
-             return command_line_input (prompt_arg, repeat, annotation_suffix);
+             return command_line_input (prompt_arg, repeat,
+                                        annotation_suffix);
            }
          if (strlen (history_value) > linelength)
            {
@@ -1006,10 +1040,10 @@ command_line_input (char *prompt_arg, int repeat, char *annotation_suffix)
   /* If we just got an empty line, and that is supposed to repeat the
      previous command, return the value in the global buffer.  */
   if (repeat && p == linebuffer)
-    return line;
+    return saved_command_line;
   for (p1 = linebuffer; *p1 == ' ' || *p1 == '\t'; p1++);
   if (repeat && !*p1)
-    return line;
+    return saved_command_line;
 
   *p = 0;
 
@@ -1030,13 +1064,13 @@ command_line_input (char *prompt_arg, int repeat, char *annotation_suffix)
   /* Save into global buffer if appropriate.  */
   if (repeat)
     {
-      if (linelength > linesize)
+      if (linelength > saved_command_line_size)
        {
-         line = xrealloc (line, linelength);
-         linesize = linelength;
+         saved_command_line = xrealloc (saved_command_line, linelength);
+         saved_command_line_size = linelength;
        }
-      strcpy (line, linebuffer);
-      return line;
+      strcpy (saved_command_line, linebuffer);
+      return saved_command_line;
     }
 
   return linebuffer;
@@ -1054,7 +1088,8 @@ print_gdb_version (struct ui_file *stream)
 
   /* Second line is a copyright notice.  */
 
-  fprintf_filtered (stream, "Copyright (C) 2011 Free Software Foundation, Inc.\n");
+  fprintf_filtered (stream,
+                   "Copyright (C) 2011 Free Software Foundation, Inc.\n");
 
   /* Following the copyright is a brief statement that the program is
      free software, that users are free to copy and change it on
@@ -1062,8 +1097,8 @@ print_gdb_version (struct ui_file *stream)
      there is no warranty.  */
 
   fprintf_filtered (stream, "\
-License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>\n\
-This is free software: you are free to change and redistribute it.\n\
+License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>\
+\nThis is free software: you are free to change and redistribute it.\n\
 There is NO WARRANTY, to the extent permitted by law.  Type \"show copying\"\n\
 and \"show warranty\" for details.\n");
 
@@ -1072,7 +1107,8 @@ and \"show warranty\" for details.\n");
   fprintf_filtered (stream, "This GDB was configured as \"");
   if (strcmp (host_name, target_name) != 0)
     {
-      fprintf_filtered (stream, "--host=%s --target=%s", host_name, target_name);
+      fprintf_filtered (stream, "--host=%s --target=%s",
+                       host_name, target_name);
     }
   else
     {
@@ -1097,14 +1133,17 @@ get_prompt (void)
 }
 
 void
-set_prompt (char *s)
+set_prompt (const char *s)
 {
-/* ??rehrauer: I don't know why this fails, since it looks as though
-   assignments to prompt are wrapped in calls to xstrdup...
-   if (prompt != NULL)
-     xfree (prompt);
- */
-  PROMPT (0) = xstrdup (s);
+  char *p = xstrdup (s);
+
+  xfree (PROMPT (0));
+  PROMPT (0) = p;
+
+  /* Also, free and set new_async_prompt so prompt changes sync up
+     with set/show prompt.  */
+  xfree (new_async_prompt);
+  new_async_prompt = xstrdup (PROMPT (0));
 }
 \f
 
@@ -1260,38 +1299,12 @@ quit_force (char *args, int from_tty)
   exit (exit_code);
 }
 
-/* If OFF, the debugger will run in non-interactive mode, which means
-   that it will automatically select the default answer to all the
-   queries made to the user.  If ON, gdb will wait for the user to
-   answer all queries.  If AUTO, gdb will determine whether to run
-   in interactive mode or not depending on whether stdin is a terminal
-   or not.  */
-static enum auto_boolean interactive_mode = AUTO_BOOLEAN_AUTO;
-
-/* Implement the "show interactive-mode" option.  */
-
-static void
-show_interactive_mode (struct ui_file *file, int from_tty,
-                       struct cmd_list_element *c,
-                       const char *value)
-{
-  if (interactive_mode == AUTO_BOOLEAN_AUTO)
-    fprintf_filtered (file, "\
-Debugger's interactive mode is %s (currently %s).\n",
-                      value, input_from_terminal_p () ? "on" : "off");
-  else
-    fprintf_filtered (file, "Debugger's interactive mode is %s.\n", value);
-}
-
 /* Returns whether GDB is running on a terminal and input is
    currently coming from that terminal.  */
 
 int
 input_from_terminal_p (void)
 {
-  if (interactive_mode != AUTO_BOOLEAN_AUTO)
-    return interactive_mode == AUTO_BOOLEAN_TRUE;
-
   if (batch_flag)
     return 0;
 
@@ -1310,8 +1323,9 @@ input_from_terminal_p (void)
 static void
 dont_repeat_command (char *ignored, int from_tty)
 {
-  *line = 0;                   /* Can't call dont_repeat here because we're 
-                                  not necessarily reading from stdin.  */
+  /* Can't call dont_repeat here because we're not necessarily reading
+     from stdin.  */
+  *saved_command_line = 0;
 }
 \f
 /* Functions to manipulate command line editing control variables.  */
@@ -1409,7 +1423,8 @@ set_history_size_command (char *args, int from_tty, struct cmd_list_element *c)
 void
 set_history (char *args, int from_tty)
 {
-  printf_unfiltered (_("\"set history\" must be followed by the name of a history subcommand.\n"));
+  printf_unfiltered (_("\"set history\" must be followed "
+                      "by the name of a history subcommand.\n"));
   help_list (sethistlist, "set history ", -1, gdb_stdout);
 }
 
@@ -1429,6 +1444,7 @@ set_verbose (char *args, int from_tty, struct cmd_list_element *c)
   struct cmd_list_element *showcmd;
 
   showcmd = lookup_cmd_1 (&cmdname, showlist, NULL, 1);
+  gdb_assert (showcmd != NULL && showcmd != CMD_LIST_AMBIGUOUS);
 
   if (info_verbose)
     {
@@ -1491,8 +1507,8 @@ static void
 show_async_command_editing_p (struct ui_file *file, int from_tty,
                              struct cmd_list_element *c, const char *value)
 {
-  fprintf_filtered (file, _("\
-Editing of command lines as they are typed is %s.\n"),
+  fprintf_filtered (file, _("Editing of command lines as "
+                           "they are typed is %s.\n"),
                    value);
 }
 
@@ -1507,8 +1523,8 @@ static void
 show_exec_done_display_p (struct ui_file *file, int from_tty,
                          struct cmd_list_element *c, const char *value)
 {
-  fprintf_filtered (file, _("\
-Notification of completion for asynchronous execution commands is %s.\n"),
+  fprintf_filtered (file, _("Notification of completion for "
+                           "asynchronous execution commands is %s.\n"),
                    value);
 }
 static void
@@ -1550,16 +1566,16 @@ init_main (void)
   rl_add_defun ("operate-and-get-next", gdb_rl_operate_and_get_next, 15);
 
   add_setshow_string_cmd ("prompt", class_support,
-                         &new_async_prompt, _("\
-Set gdb's prompt"), _("\
-Show gdb's prompt"), NULL,
-                         set_async_prompt,
+                         &new_async_prompt,
+                         _("Set gdb's prompt"),
+                         _("Show gdb's prompt"),
+                         NULL, set_async_prompt,
                          show_new_async_prompt,
                          &setlist, &showlist);
 
   add_com ("dont-repeat", class_support, dont_repeat_command, _("\
-Don't repeat this command.\n\
-Primarily used inside of user-defined commands that should not be repeated when\n\
+Don't repeat this command.\nPrimarily \
+used inside of user-defined commands that should not be repeated when\n\
 hitting return."));
 
   add_setshow_boolean_cmd ("editing", class_support,
@@ -1623,18 +1639,6 @@ Use \"on\" to enable the notification, and \"off\" to disable it."),
                           show_exec_done_display_p,
                           &setlist, &showlist);
 
-  add_setshow_auto_boolean_cmd ("interactive-mode", class_support,
-                                &interactive_mode, _("\
-Set whether GDB should run in interactive mode or not"), _("\
-Show whether GDB runs in interactive mode"), _("\
-If on, run in interactive mode and wait for the user to answer\n\
-all queries.  If off, run in non-interactive mode and automatically\n\
-assume the default answer to all queries.  If auto (the default),\n\
-determine which mode to use based on the standard input settings"),
-                        NULL,
-                        show_interactive_mode,
-                        &setlist, &showlist);
-
   add_setshow_filename_cmd ("data-directory", class_maintenance,
                            &gdb_datadir, _("Set GDB's data directory."),
                            _("Show GDB's data directory."),
@@ -1688,7 +1692,7 @@ gdb_init (char *argv0)
   set_language (language_c);
   expected_language = current_language;        /* Don't warn about the change.  */
 
-  /* Allow another UI to initialize. If the UI fails to initialize,
+  /* Allow another UI to initialize.  If the UI fails to initialize,
      and it wants GDB to revert to the CLI, it should clear
      deprecated_init_ui_hook.  */
   if (deprecated_init_ui_hook)
This page took 0.030438 seconds and 4 git commands to generate.