* symfile.c (alloc_section_addr_info): Update header. Don't set
[deliverable/binutils-gdb.git] / gdb / top.c
index 58c50755c775bd8688975a371b620f4a4c46f8e4..e06c5ee7760fcebe101495a7b0680b2e7a979be9 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-2013 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -21,7 +19,6 @@
 
 #include "defs.h"
 #include "gdbcmd.h"
-#include "call-cmds.h"
 #include "cli/cli-cmds.h"
 #include "cli/cli-script.h"
 #include "cli/cli-setshow.h"
@@ -48,6 +45,8 @@
 #include "event-loop.h"
 #include "gdbthread.h"
 #include "python/python.h"
+#include "interps.h"
+#include "observer.h"
 
 /* readline include files.  */
 #include "readline/readline.h"
 #include "ui-out.h"
 #include "cli-out.h"
 
+extern void initialize_all_files (void);
+
+#define PROMPT(X) the_prompts.prompt_stack[the_prompts.top + X].prompt
+#define PREFIX(X) the_prompts.prompt_stack[the_prompts.top + X].prefix
+#define SUFFIX(X) the_prompts.prompt_stack[the_prompts.top + X].suffix
+
 /* Default command line prompt.  This is overriden in some configs.  */
 
 #ifndef DEFAULT_PROMPT
@@ -95,11 +100,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 "
@@ -131,9 +138,6 @@ char gdb_dirbuf[1024];
 
 void (*window_hook) (FILE *, char *);
 
-int epoch_interface;
-int xgdb_verbose;
-
 /* Buffer used for reading command lines, and the size
    allocated for it so far.  */
 
@@ -283,14 +287,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
@@ -331,7 +334,7 @@ read_command_file (FILE *stream)
 void (*pre_init_ui_hook) (void);
 
 #ifdef __MSDOS__
-void
+static void
 do_chdir_cleanup (void *old_dir)
 {
   chdir (old_dir);
@@ -358,18 +361,58 @@ 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.  */
 
 void
 execute_command (char *p, int from_tty)
 {
-  struct cleanup *cleanup;
+  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 ();
   cleanup = prepare_execute_command ();
 
   /* Force cleanup of any alloca areas if using C alloca instead of
@@ -378,7 +421,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);
 
@@ -386,13 +432,15 @@ execute_command (char *p, int from_tty)
     p++;
   if (*p)
     {
+      const char *cmd = p;
       char *arg;
       line = p;
 
       /* If trace-commands is set then this will print this command.  */
       print_command_trace (p);
 
-      c = lookup_cmd (&p, cmdlist, "", 0, 1);
+      c = lookup_cmd (&cmd, cmdlist, "", 0, 1);
+      p = (char *) cmd;
 
       /* Pass null arg rather than an empty one.  */
       arg = *p ? p : 0;
@@ -421,56 +469,42 @@ execute_command (char *p, int from_tty)
       execute_cmd_pre_hook (c);
 
       if (c->flags & DEPRECATED_WARN_USER)
-       deprecated_cmd_warning (&line);
+       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);
+      else if (c->type == set_cmd)
+       do_set_command (arg, from_tty, c);
+      else if (c->type == show_cmd)
+       do_show_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);
-       
-      /* If this command has been post-hooked, run the hook last.  */
-      execute_cmd_post_hook (c);
-
-    }
+       cmd_func (c, arg, 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)
+      /* 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)
        {
-         language_info (1);    /* Print what changed.  */
+         while (gdb_do_one_event () >= 0)
+           if (!sync_execution)
+             break;
        }
-      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 this command has been post-hooked, run the hook last.  */
+      execute_cmd_post_hook (c);
 
-  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;
-       }
     }
 
-    do_cleanups (cleanup);
+  check_frame_language_change ();
+
+  do_cleanups (cleanup);
+  discard_cleanups (cleanup_if_error);
 }
 
 /* Run execute_command for P and FROM_TTY.  Capture its output into the
@@ -488,6 +522,9 @@ execute_command_to_string (char *p, int from_tty)
      restoration callbacks.  */
   cleanup = set_batch_flag_and_make_cleanup_restore_page_info ();
 
+  make_cleanup_restore_integer (&interpreter_async);
+  interpreter_async = 0;
+
   str_file = mem_fileopen ();
 
   make_cleanup_ui_file_delete (str_file);
@@ -497,10 +534,10 @@ execute_command_to_string (char *p, int from_tty)
   make_cleanup_restore_ui_file (&gdb_stdtarg);
   make_cleanup_restore_ui_file (&gdb_stdtargerr);
 
-  if (ui_out_redirect (uiout, str_file) < 0)
+  if (ui_out_redirect (current_uiout, str_file) < 0)
     warning (_("Current output protocol does not support redirection"));
   else
-    make_cleanup_ui_out_redirect_pop (uiout);
+    make_cleanup_ui_out_redirect_pop (current_uiout);
 
   gdb_stdout = str_file;
   gdb_stderr = str_file;
@@ -532,7 +569,7 @@ command_loop (void)
       if (window_hook && instream == stdin)
        (*window_hook) (instream, get_prompt ());
 
-      quit_flag = 0;
+      clear_quit_flag ();
       if (instream == stdin && stdin_is_tty)
        reinitialize_more_filter ();
       old_chain = make_cleanup (null_cleanup, 0);
@@ -542,7 +579,10 @@ command_loop (void)
                                    get_prompt () : (char *) NULL,
                                    instream == stdin, "prompt");
       if (command == 0)
-       return;
+       {
+         do_cleanups (old_chain);
+         return;
+       }
 
       make_command_stats_cleanup (1);
 
@@ -670,7 +710,7 @@ show_write_history_p (struct ui_file *file, int from_tty,
                    value);
 }
 
-static int history_size;
+static unsigned int history_size;
 static void
 show_history_size (struct ui_file *file, int from_tty,
                   struct cmd_list_element *c, const char *value)
@@ -787,8 +827,7 @@ gdb_readline_wrapper (char *prompt)
     (*after_char_processing_hook) ();
   gdb_assert (after_char_processing_hook == NULL);
 
-  /* gdb_do_one_event argument is unused.  */
-  while (gdb_do_one_event (NULL) >= 0)
+  while (gdb_do_one_event () >= 0)
     if (gdb_readline_wrapper_done)
       break;
 
@@ -905,6 +944,7 @@ command_line_input (char *prompt_arg, int repeat, char *annotation_suffix)
   /* Control-C quits instantly if typed while in this loop
      since it should not wait until the user types a newline.  */
   immediate_quit++;
+  QUIT;
 #ifdef STOP_SIGNAL
   if (job_control)
     signal (STOP_SIGNAL, handle_stop_sig);
@@ -1083,7 +1123,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) 2013 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
@@ -1118,23 +1158,28 @@ and \"show warranty\" for details.\n");
     }
 }
 \f
-/* get_prompt: access method for the GDB prompt string.  */
+
+/* The current top level prompt, settable with "set prompt", and/or
+   with the python `gdb.prompt_hook' hook.  */
+static char *top_prompt;
+
+/* Access method for the GDB prompt string.  */
 
 char *
 get_prompt (void)
 {
-  return PROMPT (0);
+  return top_prompt;
 }
 
+/* Set method for the GDB prompt string.  */
+
 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 (top_prompt);
+  top_prompt = p;
 }
 \f
 
@@ -1250,14 +1295,14 @@ quit_target (void *arg)
 
   /* Give all pushed targets a chance to do minimal cleanup, and pop
      them all out.  */
-  pop_all_targets (1);
+  pop_all_targets ();
 
   /* Save the history information if it is appropriate to do so.  */
   if (write_history_p && history_filename)
     write_history (history_filename);
 
-  do_final_cleanups (ALL_CLEANUPS);    /* Do any final cleanups before
-                                         exiting.  */
+  do_final_cleanups (all_cleanups ());    /* Do any final cleanups before
+                                            exiting.  */
   return 0;
 }
 
@@ -1335,7 +1380,7 @@ show_commands (char *args, int from_tty)
 
   /* The first command in the history which doesn't exist (i.e. one more
      than the number of the last command).  Relative to history_base.  */
-  int hist_len;
+  unsigned int hist_len;
 
   /* Print out some of the commands from the command history.  */
   /* First determine the length of the history list.  */
@@ -1400,15 +1445,16 @@ show_commands (char *args, int from_tty)
 static void
 set_history_size_command (char *args, int from_tty, struct cmd_list_element *c)
 {
-  if (history_size == INT_MAX)
-    unstifle_history ();
-  else if (history_size >= 0)
-    stifle_history (history_size);
-  else
+  /* The type of parameter in stifle_history is int, so values from INT_MAX up
+     mean 'unlimited'.  */
+  if (history_size >= INT_MAX)
     {
-      history_size = INT_MAX;
-      error (_("History size must be non-negative"));
+      /* Ensure that 'show history size' prints 'unlimited'.  */
+      history_size = UINT_MAX;
+      unstifle_history ();
     }
+  else
+    stifle_history (history_size);
 }
 
 void
@@ -1431,7 +1477,7 @@ int info_verbose = 0;             /* Default verbose msgs off.  */
 void
 set_verbose (char *args, int from_tty, struct cmd_list_element *c)
 {
-  char *cmdname = "verbose";
+  const char *cmdname = "verbose";
   struct cmd_list_element *showcmd;
 
   showcmd = lookup_cmd_1 (&cmdname, showlist, NULL, 1);
@@ -1488,8 +1534,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);
 }
@@ -1518,26 +1564,25 @@ show_exec_done_display_p (struct ui_file *file, int from_tty,
                            "asynchronous execution commands is %s.\n"),
                    value);
 }
+
+/* "set" command for the gdb_datadir configuration variable.  */
+
+static void
+set_gdb_datadir (char *args, int from_tty, struct cmd_list_element *c)
+{
+  observer_notify_gdb_datadir_changed ();
+}
+
 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) = "";
-  PROMPT (0) = xstrdup (DEFAULT_PROMPT);
-  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";
-  /* Set the variable associated with the setshow prompt command.  */
-  new_async_prompt = xstrdup (PROMPT (0));
-
-  /* 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;
@@ -1557,11 +1602,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, _("\
@@ -1589,13 +1634,13 @@ Without an argument, saving is enabled."),
                           show_write_history_p,
                           &sethistlist, &showhistlist);
 
-  add_setshow_integer_cmd ("size", no_class, &history_size, _("\
+  add_setshow_uinteger_cmd ("size", no_class, &history_size, _("\
 Set the size of the command history,"), _("\
 Show the size of the command history,"), _("\
 ie. the number of previous commands to keep a record of."),
-                          set_history_size_command,
-                          show_history_size,
-                          &sethistlist, &showhistlist);
+                           set_history_size_command,
+                           show_history_size,
+                           &sethistlist, &showhistlist);
 
   add_setshow_filename_cmd ("filename", no_class, &history_filename, _("\
 Set the filename in which to record the command history"), _("\
@@ -1605,11 +1650,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, _("\
@@ -1617,7 +1662,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);
 
@@ -1635,7 +1680,7 @@ Use \"on\" to enable the notification, and \"off\" to disable it."),
                            _("Show GDB's data directory."),
                            _("\
 When set, GDB uses the specified path to search for data files."),
-                           NULL, NULL,
+                           set_gdb_datadir, NULL,
                            &setlist,
                            &showlist);
 }
@@ -1670,6 +1715,7 @@ gdb_init (char *argv0)
   initialize_inferiors ();
   initialize_current_architecture ();
   init_cli_cmds();
+  initialize_event_loop ();
   init_main ();                        /* But that omits this file!  Do it now.  */
 
   initialize_stdin_serial ();
This page took 0.030655 seconds and 4 git commands to generate.