* event-top.c (async_stop_sig) [HAVE_SIGPROCMASK]: Some
[deliverable/binutils-gdb.git] / gdb / top.c
index f80be47e13c3934950650114e68b0e1840bb2d24..5d644dc00b4e4fc44b8f17dfa1223c0e63572004 100644 (file)
--- a/gdb/top.c
+++ b/gdb/top.c
@@ -1,5 +1,6 @@
 /* Top level stuff for GDB, the GNU debugger.
-   Copyright 1986-2000 Free Software Foundation, Inc.
+   Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
+   1996, 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
 #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"
 #include "symtab.h"
 #include "inferior.h"
-#include "signals.h"
+#include <signal.h>
 #include "target.h"
 #include "breakpoint.h"
 #include "gdbtypes.h"
@@ -35,6 +39,8 @@
 #include "completer.h"
 #include "top.h"
 #include "version.h"
+#include "serial.h"
+#include "doublest.h"
 
 /* readline include files */
 #include <readline/readline.h>
 #include "cli-out.h"
 #endif
 
-/* From completer.c */
-
-extern int is_complete_command (void (*func) (char *args, int from_tty));
-
-/* From cli/cli-cmds.c */
-
-extern void init_cmd_lists (void);
-
-extern void init_cli_cmds (void);
-
-extern void execute_user_command (struct cmd_list_element *c, char *args);
-
-/* From cli/cli-setshow.c */
-
-extern void do_setshow_command (char *, int, struct cmd_list_element *);
-
-/* Exported to CLI cli/cli-cmds.c. */
-
-void set_verbose (char *, int, struct cmd_list_element *);
-
-void show_history (char *, int);
-
-void set_history (char *, int);
-
-void show_commands (char *, int);
-
-void do_restore_instream_cleanup (void *stream);
-
-/* Prototypes for local functions */
-
-static void dont_repeat_command (char *, int);
-
-static void init_signals (void);
-
-#ifdef STOP_SIGNAL
-static void stop_sig (int);
-#endif
-
-static char *readline_line_completion_function (char *, int);
-
-static void init_main (void);
-
-static void float_handler (int);
-
-static void init_signals (void);
-
-static void set_history_size_command (char *, int, struct cmd_list_element *);
-
-static void do_nothing (int);
-
-#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 */
-/* static */ int quit_cover (PTR);
-
-static void disconnect (int);
-#endif
-
 /* Default command line prompt.  This is overriden in some configs. */
 
 #ifndef DEFAULT_PROMPT
@@ -165,7 +112,6 @@ int xgdb_verbose;
 
 /* gdb prints this when reading a command interactively */
 static char *gdb_prompt_string;        /* the global prompt string */
-extern char *get_prompt (void);        /* access function for prompt string */
 
 /* Buffer used for reading command lines, and the size
    allocated for it so far.  */
@@ -223,21 +169,6 @@ int target_executing = 0;
 /* Level of control structure.  */
 static int control_level;
 
-/* Structure for arguments to user defined functions.  */
-#define MAXUSERARGS 10
-struct user_args
-  {
-    struct user_args *next;
-    struct
-      {
-       char *arg;
-       int len;
-      }
-    a[MAXUSERARGS];
-    int count;
-  }
- *user_args;
-
 /* Signal to catch ^Z typed while reading a command: SIGTSTP or SIGCONT.  */
 
 #ifndef STOP_SIGNAL
@@ -247,19 +178,6 @@ static void stop_sig (int);
 #endif
 #endif
 
-/* Some System V have job control but not sigsetmask(). */
-#if !defined (HAVE_SIGSETMASK)
-#if !defined (USG)
-#define HAVE_SIGSETMASK 1
-#else
-#define HAVE_SIGSETMASK 0
-#endif
-#endif
-
-#if 0 == (HAVE_SIGSETMASK)
-#define sigsetmask(n)
-#endif
-
 /* Hooks for alternate command interfaces.  */
 
 /* Called after most modules have been initialized, but before taking users
@@ -340,7 +258,8 @@ void (*memory_changed_hook) (CORE_ADDR addr, int len);
 /* Called when going to wait for the target.  Usually allows the GUI to run
    while waiting for target events.  */
 
-int (*target_wait_hook) (int pid, struct target_waitstatus * status);
+ptid_t (*target_wait_hook) (ptid_t ptid,
+                            struct target_waitstatus * status);
 
 /* Used by UI as a wrapper around command execution.  May do various things
    like enabling/disabling buttons, etc...  */
@@ -367,12 +286,12 @@ NORETURN void (*error_hook) (void) ATTR_NORETURN;
    directly.  */
 #if defined(HAVE_SIGSETJMP)
 #define SIGJMP_BUF             sigjmp_buf
-#define SIGSETJMP(buf)         sigsetjmp(buf, 1)
-#define SIGLONGJMP(buf,val)    siglongjmp(buf,val)
+#define SIGSETJMP(buf)         sigsetjmp((buf), 1)
+#define SIGLONGJMP(buf,val)    siglongjmp((buf), (val))
 #else
 #define SIGJMP_BUF             jmp_buf
 #define SIGSETJMP(buf)         setjmp(buf)
-#define SIGLONGJMP(buf,val)    longjmp(buf,val)
+#define SIGLONGJMP(buf,val)    longjmp((buf), (val))
 #endif
 
 /* Where to go for return_to_top_level.  */
@@ -447,7 +366,7 @@ return_to_top_level (enum return_reason reason)
    between utils.c and top.c? */
 
 int
-catch_errors (catch_errors_ftype *func, PTR args, char *errstring,
+catch_errors (catch_errors_ftype *func, void * args, char *errstring,
              return_mask mask)
 {
   SIGJMP_BUF *saved_catch;
@@ -575,28 +494,28 @@ catch_command_errors (catch_command_errors_ftype * command,
 /* Handler for SIGHUP.  */
 
 #ifdef SIGHUP
-static void
-disconnect (int signo)
-{
-  catch_errors (quit_cover, NULL,
-             "Could not kill the program being debugged", RETURN_MASK_ALL);
-  signal (SIGHUP, SIG_DFL);
-  kill (getpid (), SIGHUP);
-}
-
 /* Just a little helper function for disconnect().  */
 
 /* 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 (PTR s)
+quit_cover (void *s)
 {
   caution = 0;                 /* Throw caution to the wind -- we're exiting.
                                   This prevents asking the user dumb questions.  */
   quit_command ((char *) 0, 0);
   return 0;
 }
+
+static void
+disconnect (int signo)
+{
+  catch_errors (quit_cover, NULL,
+             "Could not kill the program being debugged", RETURN_MASK_ALL);
+  signal (SIGHUP, SIG_DFL);
+  kill (getpid (), SIGHUP);
+}
 #endif /* defined SIGHUP */
 \f
 /* Line number we are currently in in a file which is being sourced.  */
@@ -648,8 +567,6 @@ read_command_file (FILE *stream)
   do_cleanups (cleanups);
 }
 \f
-extern void init_proc (void);
-
 void (*pre_init_ui_hook) (void);
 
 #ifdef __MSDOS__
@@ -657,70 +574,10 @@ void
 do_chdir_cleanup (void *old_dir)
 {
   chdir (old_dir);
-  free (old_dir);
+  xfree (old_dir);
 }
 #endif
 
-void
-gdb_init (char *argv0)
-{
-  if (pre_init_ui_hook)
-    pre_init_ui_hook ();
-
-  /* Run the init function of each source file */
-
-  getcwd (gdb_dirbuf, sizeof (gdb_dirbuf));
-  current_directory = gdb_dirbuf;
-
-#ifdef __MSDOS__
-  /* Make sure we return to the original directory upon exit, come
-     what may, since the OS doesn't do that for us.  */
-  make_final_cleanup (do_chdir_cleanup, xstrdup (current_directory));
-#endif
-
-  init_cmd_lists ();           /* This needs to be done first */
-  initialize_targets ();       /* Setup target_terminal macros for utils.c */
-  initialize_utils ();         /* Make errors and warnings possible */
-  initialize_all_files ();
-  initialize_current_architecture ();
-  init_cli_cmds();
-  init_main ();                        /* But that omits this file!  Do it now */
-
-  /* The signal handling mechanism is different depending whether or
-     not the async version is run. NOTE: in the future we plan to make
-     the event loop be the default engine of gdb, and this difference
-     will disappear. */
-  if (event_loop_p)
-    async_init_signals ();
-  else
-    init_signals ();
-
-  /* We need a default language for parsing expressions, so simple things like
-     "set width 0" won't fail if no language is explicitly set in a config file
-     or implicitly set by reading an executable during startup. */
-  set_language (language_c);
-  expected_language = current_language;                /* don't warn about the change.  */
-
-#ifdef UI_OUT
-  /* Install the default UI */
-  uiout = cli_out_new (gdb_stdout);
-#endif
-
-#ifdef UI_OUT
-  /* All the interpreters should have had a look at things by now.
-     Initialize the selected interpreter. */
-  if (interpreter_p && !init_ui_hook)
-    {
-      fprintf_unfiltered (gdb_stderr, "Interpreter `%s' unrecognized.\n",
-                         interpreter_p);
-      exit (1);
-    }
-#endif
-
-  if (init_ui_hook)
-    init_ui_hook (argv0);
-}
-
 /* Execute the line P as a command.
    Pass FROM_TTY as second argument to the defining function.  */
 
@@ -731,9 +588,7 @@ execute_command (char *p, int from_tty)
   register enum language flang;
   static int warned = 0;
   char *line;
-  /* FIXME: These should really be in an appropriate header file */
-extern void serial_log_command (const char *);
-
+  
   free_all_values ();
 
   /* Force cleanup of any alloca areas if using C alloca instead of
@@ -857,9 +712,6 @@ command_loop (void)
 
   while (instream && !feof (instream))
     {
-#if defined(TUI)
-      extern int insert_mode;
-#endif
       if (window_hook && instream == stdin)
        (*window_hook) (instream, get_prompt ());
 
@@ -868,22 +720,10 @@ command_loop (void)
        reinitialize_more_filter ();
       old_chain = make_cleanup (null_cleanup, 0);
 
-#if defined(TUI)
-      /* A bit of paranoia: I want to make sure the "insert_mode" global
-       * is clear except when it is being used for command-line editing
-       * (see tuiIO.c, utils.c); otherwise normal output will
-       * get messed up in the TUI. So clear it before/after
-       * the command-line-input call. - RT
-       */
-      insert_mode = 0;
-#endif
       /* Get a command-line. This calls the readline package. */
       command = command_line_input (instream == stdin ?
                                    get_prompt () : (char *) NULL,
                                    instream == stdin, "prompt");
-#if defined(TUI)
-      insert_mode = 0;
-#endif
       if (command == 0)
        return;
 
@@ -1000,11 +840,11 @@ gdb_readline (char *prompt_arg)
          character position to be off, since the newline we read from
          the user is not accounted for.  */
       fputs_unfiltered (prompt_arg, gdb_stdout);
-#ifdef MPW
-      /* Move to a new line so the entered line doesn't have a prompt
-         on the front of it. */
-      fputs_unfiltered ("\n", gdb_stdout);
-#endif /* MPW */
+      /* OBSOLETE #ifdef MPW */
+      /* OBSOLETE          Move to a new line so the entered line doesn't have a prompt */
+      /* OBSOLETE          on the front of it. */
+      /* OBSOLETE       fputs_unfiltered ("\n", gdb_stdout); */
+      /* OBSOLETE #endif  *//* MPW */
       gdb_flush (gdb_stdout);
     }
 
@@ -1023,7 +863,7 @@ gdb_readline (char *prompt_arg)
               if we are called again fgetc will still return EOF and
               we'll return NULL then.  */
            break;
-         free (result);
+         xfree (result);
          return NULL;
        }
 
@@ -1062,24 +902,6 @@ static int write_history_p;
 static int history_size;
 static char *history_filename;
 
-/* Functions that are used as part of the fancy command line editing.  */
-
-/* This can be used for functions which don't want to complete on symbols
-   but don't want to complete on anything else either.  */
-/* ARGSUSED */
-char **
-noop_completer (char *text, char *prefix)
-{
-  return NULL;
-}
-
-/* Line completion interface function for readline.  */
-
-static char *
-readline_line_completion_function (char *text, int matches)
-{
-  return line_completion_function (text, matches, rl_line_buffer, rl_point);
-}
 \f
 #ifdef STOP_SIGNAL
 static void
@@ -1087,7 +909,16 @@ stop_sig (int signo)
 {
 #if STOP_SIGNAL == SIGTSTP
   signal (SIGTSTP, SIG_DFL);
+#if HAVE_SIGPROCMASK
+  {
+    sigset_t zero;
+
+    sigemptyset (&zero);
+    sigprocmask (SIG_SETMASK, &zero, 0);
+  }
+#elif HAVE_SIGSETMASK
   sigsetmask (0);
+#endif
   kill (getpid (), SIGTSTP);
   signal (SIGTSTP, stop_sig);
 #else
@@ -1102,6 +933,15 @@ stop_sig (int signo)
 #endif /* STOP_SIGNAL */
 
 /* Initialize signal handlers. */
+static void
+float_handler (int signo)
+{
+  /* This message is based on ANSI C, section 4.7.  Note that integer
+     divide by zero causes this, so "float" is a misnomer.  */
+  signal (SIGFPE, float_handler);
+  error ("Erroneous arithmetic operation.");
+}
+
 static void
 do_nothing (int signo)
 {
@@ -1275,7 +1115,7 @@ command_line_input (char *prompt_arg, int repeat, char *annotation_suffix)
       while (*p1)
        *p++ = *p1++;
 
-      free (rl);               /* Allocated in readline.  */
+      xfree (rl);              /* Allocated in readline.  */
 
       if (p == linebuffer || *(p - 1) != '\\')
        break;
@@ -1323,7 +1163,7 @@ command_line_input (char *prompt_arg, int repeat, char *annotation_suffix)
          /* If there was an error, call this function again.  */
          if (expanded < 0)
            {
-             free (history_value);
+             xfree (history_value);
              return command_line_input (prompt_arg, repeat, annotation_suffix);
            }
          if (strlen (history_value) > linelength)
@@ -1333,7 +1173,7 @@ command_line_input (char *prompt_arg, int repeat, char *annotation_suffix)
            }
          strcpy (linebuffer, history_value);
          p = linebuffer + strlen (linebuffer);
-         free (history_value);
+         xfree (history_value);
        }
     }
 
@@ -1385,16 +1225,16 @@ print_gdb_version (struct ui_file *stream)
      program to parse, and is just canonical program name and version
      number, which starts after last space. */
 
-#ifdef UI_OUT
+#ifdef MI_OUT
   /* Print it console style until a format is defined */
-  fprintf_filtered (stream, "GNU gdb %s (UI_OUT)\n", version);
+  fprintf_filtered (stream, "GNU gdb %s (MI_OUT)\n", version);
 #else
   fprintf_filtered (stream, "GNU gdb %s\n", version);
 #endif
 
   /* Second line is a copyright notice. */
 
-  fprintf_filtered (stream, "Copyright 2000 Free Software Foundation, Inc.\n");
+  fprintf_filtered (stream, "Copyright 2001 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
@@ -1574,7 +1414,7 @@ get_prompt_1 (void *data)
                         from bad user-supplied format string? */
                      sprintf (outp, fmt[0] == 0 ? default_fmt : fmt,
                               tmp);
-                     free (tmp);
+                     xfree (tmp);
                    }
                  else
                    {
@@ -1692,7 +1532,7 @@ set_prompt (char *s)
 /* ??rehrauer: I don't know why this fails, since it looks as though
    assignments to prompt are wrapped in calls to savestring...
    if (prompt != NULL)
-   free (prompt);
+   xfree (prompt);
  */
   if (event_loop_p)
     PROMPT (0) = savestring (s, strlen (s));
@@ -1707,7 +1547,7 @@ set_prompt (char *s)
 int
 quit_confirm (void)
 {
-  if (inferior_pid != 0 && target_has_execution)
+  if (! ptid_equal (inferior_ptid, null_ptid) && target_has_execution)
     {
       char *s;
 
@@ -1744,7 +1584,7 @@ quit_force (char *args, int from_tty)
       exit_code = (int) value_as_long (val);
     }
 
-  if (inferior_pid != 0 && target_has_execution)
+  if (! ptid_equal (inferior_ptid, null_ptid) && target_has_execution)
     {
       if (attach_flag)
        target_detach (args, from_tty);
@@ -1761,16 +1601,6 @@ quit_force (char *args, int from_tty)
 
   do_final_cleanups (ALL_CLEANUPS);    /* Do any final cleanups before exiting */
 
-#if defined(TUI)
-  /* tuiDo((TuiOpaqueFuncPtr)tuiCleanUp); */
-  /* The above does not need to be inside a tuiDo(), since
-   * it is not manipulating the curses screen, but rather,
-   * it is tearing it down.
-   */
-  if (tui_version)
-    tuiCleanUp ();
-#endif
-
   exit (exit_code);
 }
 
@@ -1809,8 +1639,6 @@ show_commands (char *args, int from_tty)
      than the number of the last command).  Relative to history_base.  */
   int hist_len;
 
-extern HIST_ENTRY *history_get (int);
-
   /* Print out some of the commands from the command history.  */
   /* First determine the length of the history list.  */
   hist_len = history_size;
@@ -1925,15 +1753,6 @@ set_verbose (char *args, int from_tty, struct cmd_list_element *c)
     }
 }
 
-static void
-float_handler (int signo)
-{
-  /* This message is based on ANSI C, section 4.7.  Note that integer
-     divide by zero causes this, so "float" is a misnomer.  */
-  signal (SIGFPE, float_handler);
-  error ("Erroneous arithmetic operation.");
-}
-
 /* Init the history buffer.  Note that we are called after the init file(s)
  * have been read so that the user can change the history file via his
  * .gdbinit file (for instance).  The GDBHISTFILE environment variable
@@ -1995,6 +1814,12 @@ init_main (void)
       async_annotation_suffix = "prompt";
       /* Set the variable associated with the setshow prompt command. */
       new_async_prompt = savestring (PROMPT (0), strlen (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);
     }
   gdb_prompt_escape = 0;       /* default to none.  */
 
@@ -2080,11 +1905,12 @@ ie. the number of previous commands to keep a record of.", &sethistlist);
   add_show_from_set (c, &showhistlist);
   c->function.sfunc = set_history_size_command;
 
-  add_show_from_set
-    (add_set_cmd ("filename", no_class, var_filename, (char *) &history_filename,
-                 "Set the filename in which to record the command history\n\
- (the list of previous commands of which a record is kept).", &sethistlist),
-     &showhistlist);
+  c = add_set_cmd ("filename", no_class, var_filename,
+                  (char *) &history_filename,
+                  "Set the filename in which to record the command history\n\
+ (the list of previous commands of which a record is kept).", &sethistlist);
+  c->completer = filename_completer;
+  add_show_from_set (c, &showhistlist);
 
   add_show_from_set
     (add_set_cmd ("confirm", class_support, var_boolean,
@@ -2125,3 +1951,64 @@ Use \"on\" to enable the notification, and \"off\" to disable it.", &setlist),
         &showlist);
     }
 }
+
+void
+gdb_init (char *argv0)
+{
+  if (pre_init_ui_hook)
+    pre_init_ui_hook ();
+
+  /* Run the init function of each source file */
+
+  getcwd (gdb_dirbuf, sizeof (gdb_dirbuf));
+  current_directory = gdb_dirbuf;
+
+#ifdef __MSDOS__
+  /* Make sure we return to the original directory upon exit, come
+     what may, since the OS doesn't do that for us.  */
+  make_final_cleanup (do_chdir_cleanup, xstrdup (current_directory));
+#endif
+
+  init_cmd_lists ();           /* This needs to be done first */
+  initialize_targets ();       /* Setup target_terminal macros for utils.c */
+  initialize_utils ();         /* Make errors and warnings possible */
+  initialize_all_files ();
+  initialize_current_architecture ();
+  init_cli_cmds();
+  init_main ();                        /* But that omits this file!  Do it now */
+
+  /* The signal handling mechanism is different depending whether or
+     not the async version is run. NOTE: in the future we plan to make
+     the event loop be the default engine of gdb, and this difference
+     will disappear. */
+  if (event_loop_p)
+    async_init_signals ();
+  else
+    init_signals ();
+
+  /* We need a default language for parsing expressions, so simple things like
+     "set width 0" won't fail if no language is explicitly set in a config file
+     or implicitly set by reading an executable during startup. */
+  set_language (language_c);
+  expected_language = current_language;                /* don't warn about the change.  */
+
+#ifdef UI_OUT
+  /* Install the default UI */
+  if (!init_ui_hook)
+    {
+      uiout = cli_out_new (gdb_stdout);
+
+      /* All the interpreters should have had a look at things by now.
+        Initialize the selected interpreter. */
+      if (interpreter_p)
+       {
+         fprintf_unfiltered (gdb_stderr, "Interpreter `%s' unrecognized.\n",
+                             interpreter_p);
+         exit (1);
+       }
+    }
+#endif
+
+  if (init_ui_hook)
+    init_ui_hook (argv0);
+}
This page took 0.033119 seconds and 4 git commands to generate.