2012-03-01 Pedro Alves <palves@redhat.com>
[deliverable/binutils-gdb.git] / gdb / top.c
index ac371763dc601bed3c95402fe17eb79b5e3cb62e..55e4504009ae6ff7cae7661c83a9a48ca1fa78d5 100644 (file)
--- a/gdb/top.c
+++ b/gdb/top.c
@@ -1,8 +1,6 @@
 /* Top level stuff for GDB, the GNU debugger.
 
-   Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
-   1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
-   2008, 2009, 2010, 2011 Free Software Foundation, Inc.
+   Copyright (C) 1986-2012 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -100,11 +98,13 @@ int use_windows = 0;
 
 extern char lang_frame_mismatch_warn[];                /* language.c */
 
-/* Flag for whether we want all the "from_tty" gubbish printed.  */
+/* Flag for whether we want to confirm potentially dangerous
+   operations.  Default is yes.  */
+
+int confirm = 1;
 
-int caution = 1;               /* Default is yes, sigh.  */
 static void
-show_caution (struct ui_file *file, int from_tty,
+show_confirm (struct ui_file *file, int from_tty,
              struct cmd_list_element *c, const char *value)
 {
   fprintf_filtered (file, _("Whether to confirm potentially "
@@ -288,14 +288,13 @@ void (*deprecated_context_hook) (int id);
 /* 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.  */
-/* static */ int
-quit_cover (void *s)
+/* static */ void
+quit_cover (void)
 {
-  caution = 0;                 /* Throw caution to the wind -- we're exiting.
-                                  This prevents asking the user dumb 
-                                  questions.  */
+  /* Stop asking user for confirmation --- we're exiting.  This
+     prevents asking the user dumb questions.  */
+  confirm = 0;
   quit_command ((char *) 0, 0);
-  return 0;
 }
 #endif /* defined SIGHUP */
 \f
@@ -363,6 +362,47 @@ prepare_execute_command (void)
   return cleanup;
 }
 
+/* Tell the user if the language has changed (except first time) after
+   executing a command.  */
+
+void
+check_frame_language_change (void)
+{
+  static int warned = 0;
+
+  /* First make sure that a new frame has been selected, in case the
+     command or the hooks changed the program state.  */
+  deprecated_safe_get_selected_frame ();
+  if (current_language != expected_language)
+    {
+      if (language_mode == language_mode_auto && info_verbose)
+       {
+         language_info (1);    /* Print what changed.  */
+       }
+      warned = 0;
+    }
+
+  /* Warn the user if the working language does not match the language
+     of the current frame.  Only warn the user if we are actually
+     running the program, i.e. there is a stack.  */
+  /* FIXME: This should be cacheing the frame and only running when
+     the frame changes.  */
+
+  if (has_stack_frames ())
+    {
+      enum language flang;
+
+      flang = get_frame_language ();
+      if (!warned
+         && flang != language_unknown
+         && flang != current_language->la_language)
+       {
+         printf_filtered ("%s\n", lang_frame_mismatch_warn);
+         warned = 1;
+       }
+    }
+}
+
 /* Execute the line P as a command, in the current user context.
    Pass FROM_TTY as second argument to the defining function.  */
 
@@ -371,8 +411,6 @@ execute_command (char *p, int from_tty)
 {
   struct cleanup *cleanup_if_error, *cleanup;
   struct cmd_list_element *c;
-  enum language flang;
-  static int warned = 0;
   char *line;
 
   cleanup_if_error = make_bpstat_clear_actions_cleanup ();
@@ -432,22 +470,23 @@ execute_command (char *p, int from_tty)
       if (c->flags & DEPRECATED_WARN_USER)
        deprecated_cmd_warning (&line);
 
-      if (c->class == class_user)
+      /* c->user_commands would be NULL in the case of a python command.  */
+      if (c->class == class_user && c->user_commands)
        execute_user_command (c, arg);
       else if (c->type == set_cmd || c->type == show_cmd)
-       do_setshow_command (arg, from_tty & caution, c);
+       do_setshow_command (arg, from_tty, c);
       else if (!cmd_func_p (c))
        error (_("That is not a command, just a help topic."));
       else if (deprecated_call_command_hook)
-       deprecated_call_command_hook (c, arg, from_tty & caution);
+       deprecated_call_command_hook (c, arg, from_tty);
       else
-       cmd_func (c, arg, from_tty & caution);
+       cmd_func (c, arg, from_tty);
 
       /* If the interpreter is in sync mode (we're running a user
         command's list, running command hooks or similars), and we
         just ran a synchronous command that started the target, wait
         for that command to end.  */
-      if (!interpreter_async && sync_execution && is_running (inferior_ptid))
+      if (!interpreter_async && sync_execution)
        {
          while (gdb_do_one_event () >= 0)
            if (!sync_execution)
@@ -459,36 +498,7 @@ execute_command (char *p, int from_tty)
 
     }
 
-  /* Tell the user if the language has changed (except first time).
-     First make sure that a new frame has been selected, in case this
-     command or the hooks changed the program state.  */
-  deprecated_safe_get_selected_frame ();
-  if (current_language != expected_language)
-    {
-      if (language_mode == language_mode_auto && info_verbose)
-       {
-         language_info (1);    /* Print what changed.  */
-       }
-      warned = 0;
-    }
-
-  /* Warn the user if the working language does not match the
-     language of the current frame.  Only warn the user if we are
-     actually running the program, i.e. there is a stack.  */
-  /* FIXME:  This should be cacheing the frame and only running when
-     the frame changes.  */
-
-  if (has_stack_frames ())
-    {
-      flang = get_frame_language ();
-      if (!warned
-         && flang != language_unknown
-         && flang != current_language->la_language)
-       {
-         printf_filtered ("%s\n", lang_frame_mismatch_warn);
-         warned = 1;
-       }
-    }
+  check_frame_language_change ();
 
   do_cleanups (cleanup);
   discard_cleanups (cleanup_if_error);
@@ -554,7 +564,7 @@ command_loop (void)
   while (instream && !feof (instream))
     {
       if (window_hook && instream == stdin)
-       (*window_hook) (instream, get_prompt (0));
+       (*window_hook) (instream, get_prompt ());
 
       quit_flag = 0;
       if (instream == stdin && stdin_is_tty)
@@ -563,7 +573,7 @@ command_loop (void)
 
       /* Get a command-line.  This calls the readline package.  */
       command = command_line_input (instream == stdin ?
-                                   get_prompt (0) : (char *) NULL,
+                                   get_prompt () : (char *) NULL,
                                    instream == stdin, "prompt");
       if (command == 0)
        {
@@ -1109,7 +1119,7 @@ print_gdb_version (struct ui_file *stream)
   /* Second line is a copyright notice.  */
 
   fprintf_filtered (stream,
-                   "Copyright (C) 2011 Free Software Foundation, Inc.\n");
+                   "Copyright (C) 2012 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
@@ -1145,97 +1155,27 @@ and \"show warranty\" for details.\n");
 }
 \f
 
-/* get_prefix: access method for the GDB prefix string.  */
-
-char *
-get_prefix (int level)
-{
-  return PREFIX (level);
-}
+/* The current top level prompt, settable with "set prompt", and/or
+   with the python `gdb.prompt_hook' hook.  */
+static char *top_prompt;
 
-/* set_prefix: set method for the GDB prefix string.  */
-
-void
-set_prefix (const char *s, int level)
-{
-  /* If S is NULL, just free the PREFIX at level LEVEL and set to
-     NULL.  */
-  if (s == NULL)
-    {
-      xfree (PREFIX (level));
-      PREFIX (level) = NULL;
-    }
-  else
-    {
-      char *p = xstrdup (s);
-
-      xfree (PREFIX (level));
-      PREFIX (level) =  p;
-    }
-}
-
-/* get_suffix: access method for the GDB suffix string.  */
+/* Access method for the GDB prompt string.  */
 
 char *
-get_suffix (int level)
+get_prompt (void)
 {
-  return SUFFIX (level);
+  return top_prompt;
 }
 
-/* set_suffix: set method for the GDB suffix string.  */
+/* Set method for the GDB prompt string.  */
 
 void
-set_suffix (const char *s, int level)
+set_prompt (const char *s)
 {
-  /* If S is NULL, just free the SUFFIX at level LEVEL and set to
-     NULL.  */
-  if (s == NULL)
-    {
-      xfree (SUFFIX (level));
-      SUFFIX (level) = NULL;
-    }
-  else
-    {
-      char *p = xstrdup (s);
-
-      xfree (SUFFIX (level));
-      SUFFIX (level) =  p;
-    }
-}
-
- /* get_prompt: access method for the GDB prompt string.  */
-
-char *
-get_prompt (int level)
-{
-  return PROMPT (level);
-}
-
-void
-set_prompt (const char *s, int level)
-{
-  /* If S is NULL, just free the PROMPT at level LEVEL and set to
-     NULL.  */
-  if (s == NULL)
-    {
-      xfree (PROMPT (level));
-      PROMPT (level) = NULL;
-    }
-  else
-    {
-      char *p = xstrdup (s);
+  char *p = xstrdup (s);
 
-      xfree (PROMPT (0));
-      PROMPT (0) = p;
-
-      if (level == 0)
-       {
-         /* 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));
-         }
-      }
+  xfree (top_prompt);
+  top_prompt = p;
 }
 \f
 
@@ -1589,8 +1529,8 @@ init_history (void)
 }
 
 static void
-show_new_async_prompt (struct ui_file *file, int from_tty,
-                      struct cmd_list_element *c, const char *value)
+show_prompt (struct ui_file *file, int from_tty,
+            struct cmd_list_element *c, const char *value)
 {
   fprintf_filtered (file, _("Gdb's prompt is \"%s\".\n"), value);
 }
@@ -1622,22 +1562,14 @@ show_exec_done_display_p (struct ui_file *file, int from_tty,
 static void
 init_main (void)
 {
-  /* initialize the prompt stack to a simple "(gdb) " prompt or to
-     whatever the DEFAULT_PROMPT is.  */
-  the_prompts.top = 0;
-  PREFIX (0) = "";
-  set_prompt (DEFAULT_PROMPT, 0);
-  SUFFIX (0) = "";
+  /* Initialize the prompt to a simple "(gdb) " prompt or to whatever
+     the DEFAULT_PROMPT is.  */
+  set_prompt (DEFAULT_PROMPT);
+
   /* Set things up for annotation_level > 1, if the user ever decides
      to use it.  */
   async_annotation_suffix = "prompt";
 
-  /* If gdb was started with --annotate=2, this is equivalent to the
-     user entering the command 'set annotate 2' at the gdb prompt, so
-     we need to do extra processing.  */
-  if (annotation_level > 1)
-    set_async_annotation_level (NULL, 0, NULL);
-
   /* Set the important stuff up for command editing.  */
   command_editing_p = 1;
   history_expansion_p = 0;
@@ -1656,11 +1588,11 @@ 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,
+                         &top_prompt,
                          _("Set gdb's prompt"),
                          _("Show gdb's prompt"),
-                         NULL, set_async_prompt,
-                         show_new_async_prompt,
+                         NULL, NULL,
+                         show_prompt,
                          &setlist, &showlist);
 
   add_com ("dont-repeat", class_support, dont_repeat_command, _("\
@@ -1704,11 +1636,11 @@ Show the filename in which to record the command history"), _("\
                            show_history_filename,
                            &sethistlist, &showhistlist);
 
-  add_setshow_boolean_cmd ("confirm", class_support, &caution, _("\
+  add_setshow_boolean_cmd ("confirm", class_support, &confirm, _("\
 Set whether to confirm potentially dangerous operations."), _("\
 Show whether to confirm potentially dangerous operations."), NULL,
                           NULL,
-                          show_caution,
+                          show_confirm,
                           &setlist, &showlist);
 
   add_setshow_zinteger_cmd ("annotate", class_obscure, &annotation_level, _("\
@@ -1716,7 +1648,7 @@ Set annotation_level."), _("\
 Show annotation_level."), _("\
 0 == normal;     1 == fullname (for use when running under emacs)\n\
 2 == output annotated suitably for use by programs that control GDB."),
-                           set_async_annotation_level,
+                           NULL,
                            show_annotation_level,
                            &setlist, &showlist);
 
This page took 0.030066 seconds and 4 git commands to generate.