]> Git Repo - binutils.git/blobdiff - gdb/main.c
For sparc64 target, use sparc cpu files and add sparcv9 to extra_defs. No
[binutils.git] / gdb / main.c
index c5cfa38dd980b1e18bbe105d20bc14f320bd67d1..56a34ad8a35888974ba580c46c45071134f9efe6 100644 (file)
@@ -1,5 +1,5 @@
 /* Top level `main' program for GDB, the GNU debugger.
-   Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992
+   Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994
    Free Software Foundation, Inc.
 
 This file is part of GDB.
@@ -30,6 +30,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #include "expression.h"
 #include "language.h"
 #include "terminal.h" /* For job_control.  */
+#include "annotate.h"
 
 #include "getopt.h"
 
@@ -40,8 +41,9 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 /* readline defines this.  */
 #undef savestring
 
-#ifdef USG
 #include <sys/types.h>
+#ifdef USG
+/* What is this for?  X_OK?  */
 #include <unistd.h>
 #endif
 
@@ -54,13 +56,6 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #include <sys/stat.h>
 #include <ctype.h>
 
-#ifdef SET_STACK_LIMIT_HUGE
-#include <sys/time.h>
-#include <sys/resource.h>
-
-int original_stack_limit;
-#endif
-
 /* Prototypes for local functions */
 
 static char *
@@ -146,6 +141,9 @@ show_command PARAMS ((char *, int));
 static void
 info_command PARAMS ((char *, int));
 
+static void
+complete_command PARAMS ((char *, int));
+
 static void
 do_nothing PARAMS ((int));
 
@@ -180,11 +178,11 @@ extern char *version;
 
 /* Canonical host name as a string. */
 
-extern char *host_canonical;
+extern char *host_name;
 
 /* Canonical target name as a string. */
 
-extern char *target_canonical;
+extern char *target_name;
 
 extern char lang_frame_mismatch_warn[];                /* language.c */
 
@@ -304,8 +302,18 @@ static char *prompt;
 char *line;
 int linesize = 100;
 
+/* Nonzero if the current command is modified by "server ".  This
+   affects things like recording into the command history, comamnds
+   repeating on RETURN, etc.  This is so a user interface (emacs, GUI,
+   whatever) can issue its own commands and also send along commands
+   from the user, and have the user not notice that the user interface
+   is issuing commands too.  */
+int server_command;
+
 /* Baud rate specified for talking to serial target systems.  Default
    is left as -1, so targets can choose their own defaults.  */
+/* FIXME: This means that "show remotebaud" and gr_files_info can print -1
+   or (unsigned int)-1.  This is a Bad User Interface.  */
 
 int baud_rate = -1;
 
@@ -324,7 +332,11 @@ static void stop_sig PARAMS ((int));
 
 /* Some System V have job control but not sigsetmask(). */
 #if !defined (HAVE_SIGSETMASK)
-#define HAVE_SIGSETMASK !defined (USG)
+#if !defined (USG)
+#define HAVE_SIGSETMASK 1
+#else
+#define HAVE_SIGSETMASK 0
+#endif
 #endif
 
 #if 0 == (HAVE_SIGSETMASK)
@@ -364,6 +376,18 @@ return_to_top_level (reason)
 
   disable_current_display ();
   do_cleanups (ALL_CLEANUPS);
+
+  if (annotation_level > 1)
+    switch (reason)
+      {
+      case RETURN_QUIT:
+       annotate_quit ();
+       break;
+      case RETURN_ERROR:
+       annotate_error ();
+       break;
+      }
+
   (NORETURN void) longjmp
     (reason == RETURN_ERROR ? error_return : quit_return, 1);
 }
@@ -494,6 +518,28 @@ read_command_file (stream)
   do_cleanups (cleanups);
 }
 \f
+extern void init_proc ();
+
+void
+gdb_init ()
+{
+  /* Run the init function of each source file */
+
+  init_cmd_lists ();   /* This needs to be done first */
+  initialize_all_files ();
+  init_main ();                /* But that omits this file!  Do it now */
+  init_signals ();
+
+  init_proc ();
+
+  /* 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.  */
+}
+
+#ifndef MAIN_OVERRIDE
 int
 main (argc, argv)
      int argc;
@@ -533,6 +579,16 @@ main (argc, argv)
 
   register int i;
 
+/* start-sanitize-mpw */
+#ifdef MPW
+  /* Drop into MacsBug, but only if the executable is specially named. */
+  if (strcmp(argv[0], "DEBUGGDB") == 0)
+    DebugStr("\pat start of GDB main");
+
+  if (StandAlone)
+    mac_app = mac_init ();
+#endif /* MPW */
+/* end-sanitize-mpw */
   /* This needs to happen before the first use of malloc.  */
   init_malloc ((PTR) NULL);
 
@@ -562,19 +618,6 @@ main (argc, argv)
   getcwd (dirbuf, sizeof (dirbuf));
   current_directory = dirbuf;
 
-#ifdef SET_STACK_LIMIT_HUGE
-  {
-    struct rlimit rlim;
-
-    /* Set the stack limit huge so that alloca (particularly stringtab
-     * in dbxread.c) does not fail. */
-    getrlimit (RLIMIT_STACK, &rlim);
-    original_stack_limit = rlim.rlim_cur;
-    rlim.rlim_cur = rlim.rlim_max;
-    setrlimit (RLIMIT_STACK, &rlim);
-  }
-#endif /* SET_STACK_LIMIT_HUGE */
-
   /* Parse arguments and options.  */
   {
     int c;
@@ -594,8 +637,14 @@ main (argc, argv)
        {"n", no_argument, &inhibit_gdbinit, 1},
        {"batch", no_argument, &batch, 1},
        {"epoch", no_argument, &epoch_interface, 1},
-       {"fullname", no_argument, &frame_file_full_name, 1},
-       {"f", no_argument, &frame_file_full_name, 1},
+
+       /* This is a synonym for "--annotate=1".  --annotate is now preferred,
+          but keep this here for a long time because people will be running
+          emacses which use --fullname.  */
+       {"fullname", no_argument, 0, 'f'},
+       {"f", no_argument, 0, 'f'},
+
+       {"annotate", required_argument, 0, 12},
        {"help", no_argument, &print_help, 1},
        {"se", required_argument, 0, 10},
        {"symbols", required_argument, 0, 's'},
@@ -644,6 +693,13 @@ main (argc, argv)
          case 11:
            cdarg = optarg;
            break;
+         case 12:
+           /* FIXME: what if the syntax is wrong (e.g. not digits)?  */
+           annotation_level = atoi (optarg);
+           break;
+         case 'f':
+           annotation_level = 1;
+           break;
          case 's':
            symarg = optarg;
            break;
@@ -684,7 +740,13 @@ main (argc, argv)
 
              i = strtol (optarg, &p, 0);
              if (i == 0 && p == optarg)
-               warning ("Could not set baud rate to `%s'.\n", optarg);
+
+               /* Don't use *_filtered or warning() (which relies on
+                   current_target) until after initialize_all_files(). */
+
+               fprintf_unfiltered
+                 (gdb_stderr,
+                  "warning: could not set baud rate to `%s'.\n", optarg);
              else
                baud_rate = i;
            }
@@ -723,12 +785,7 @@ main (argc, argv)
       quiet = 1;
   }
 
-  /* Run the init function of each source file */
-
-  init_cmd_lists ();   /* This needs to be done first */
-  initialize_all_files ();
-  init_main ();                /* But that omits this file!  Do it now */
-  init_signals ();
+  gdb_init ();
 
   /* Do these (and anything which might call wrap_here or *_filtered)
      after initialize_all_files.  */
@@ -753,6 +810,12 @@ main (argc, argv)
 
       /* But don't use *_filtered here.  We don't want to prompt for continue
         no matter how small the screen or how much we're going to print.  */
+/* start-sanitize-mpw */
+/* For reasons too ugly to describe... */
+#ifdef MPW_C
+      fputs_unfiltered ("This is the GNU debugger.\n", gdb_stdout);
+#else
+/* end-sanitize-mpw */
       fputs_unfiltered ("\
 This is the GNU debugger.  Usage:\n\
     gdb [options] [executable-file [core-file or process-id]]\n\
@@ -775,6 +838,9 @@ Options:\n\
   --mapped           Use mapped symbol files if supported on this system.\n\
   --readnow          Fully read symbol files on first access.\n\
 ", gdb_stdout);
+/* start-sanitize-mpw */
+#endif /* MPW_C */
+/* end-sanitize-mpw */
 #ifdef ADDITIONAL_OPTION_HELP
       fputs_unfiltered (ADDITIONAL_OPTION_HELP, gdb_stdout);
 #endif
@@ -800,12 +866,6 @@ GDB manual (available as on-line info or a printed manual).\n", gdb_stdout);
   /* We may get more than one warning, don't double space all of them... */
   warning_pre_print = "\nwarning: ";
 
-  /* 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.  */
-
   /* Read and execute $HOME/.gdbinit file, if it exists.  This is done
      *before* all the command line arguments are processed; it sets
      global parameters, which are independent of what file you are
@@ -844,7 +904,6 @@ GDB manual (available as on-line info or a printed manual).\n", gdb_stdout);
       if (!SET_TOP_LEVEL ())
        {
          cd_command (cdarg, 0);
-         init_source_path ();
        }
     }
   do_cleanups (ALL_CLEANUPS);
@@ -954,12 +1013,43 @@ GDB manual (available as on-line info or a printed manual).\n", gdb_stdout);
       if (!SET_TOP_LEVEL ())
        {
          do_cleanups (ALL_CLEANUPS);           /* Do complete cleanup */
+/* start-sanitize-mpw */
+#ifdef MPW
+         /* If we're being a Mac application, go into a Mac-specific
+            event-handling loop instead.  We still want to be inside
+            the outer loop, because that will catch longjmps resulting
+            from some command executions. */
+         if (mac_app)
+           mac_command_loop ();
+         else
+#endif /* MPW */
+/* end-sanitize-mpw */
          command_loop ();
           quit_command ((char *)0, instream == stdin);
        }
     }
   /* No exit -- exit is through quit_command.  */
 }
+\f
+void
+init_proc ()
+{
+}
+
+int
+proc_wait (pid, status)
+     int pid;
+     int *status;
+{
+  return wait (status);
+}
+
+void
+proc_remove_foreign (pid)
+     int pid;
+{
+}
+#endif /* MAIN_OVERRIDE */
 
 void
 execute_user_command (c, args)
@@ -1083,7 +1173,7 @@ command_loop ()
        reinitialize_more_filter ();
       old_chain = make_cleanup (command_loop_marker, 0);
       command = command_line_input (instream == stdin ? prompt : (char *) NULL,
-                                     instream == stdin);
+                                   instream == stdin, "prompt");
       if (command == 0)
        return;
       execute_command (command, instream == stdin);
@@ -1098,6 +1188,9 @@ command_loop ()
 void
 dont_repeat ()
 {
+  if (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.  */
@@ -1127,6 +1220,13 @@ gdb_readline (prrompt)
         character position to be off, since the newline we read from
         the user is not accounted for.  */
       fputs_unfiltered (prrompt, gdb_stdout);
+/* start-sanitize-mpw */
+#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 */
+/* end-sanitize-mpw */
       gdb_flush (gdb_stdout);
     }
   
@@ -1311,7 +1411,7 @@ filename_completer (text, word)
    "p b-a" ambiguous (all symbols starting with a)
    "p b-" ambiguous (all symbols)
    "file Make" "file" (word break hard to screw up here)
-   "file ../gdb.stabs/wi" "erd" (needs to not break word at slash)
+   "file ../gdb.stabs/we" "ird" (needs to not break word at slash)
    */
 
 /* Generate completions one by one for the completer.  Each time we are
@@ -1347,8 +1447,6 @@ symbol_completion_function (text, matches)
   /* Pointer within tmp_command which corresponds to text.  */
   char *word;
   struct cmd_list_element *c, *result_list;
-  extern char *rl_line_buffer;
-  extern int rl_point;
 
   if (matches == 0)
     {
@@ -1654,9 +1752,10 @@ init_signals ()
    simple input as the user has requested.  */
 
 char *
-command_line_input (prrompt, repeat)
+command_line_input (prrompt, repeat, annotation_suffix)
      char *prrompt;
      int repeat;
+     char *annotation_suffix;
 {
   static char *linebuffer = 0;
   static unsigned linelength = 0;
@@ -1668,6 +1767,19 @@ command_line_input (prrompt, repeat)
   char *nline;
   char got_eof = 0;
 
+  if (annotation_level > 1 && instream == stdin)
+    {
+      local_prompt = alloca ((prrompt == NULL ? 0 : strlen (prrompt))
+                            + strlen (annotation_suffix) + 40);
+      if (prrompt == NULL)
+       local_prompt[0] = '\0';
+      else
+       strcpy (local_prompt, prrompt);
+      strcat (local_prompt, "\n\032\032");
+      strcat (local_prompt, annotation_suffix);
+      strcat (local_prompt, "\n");
+    }
+
   if (linebuffer == 0)
     {
       linelength = 80;
@@ -1686,10 +1798,9 @@ command_line_input (prrompt, repeat)
 
   while (1)
     {
-      /* Reports are that some Sys V's don't flush gdb_stdout/err on reads
-        from stdin, when stdin/out are sockets rather than ttys.  So we
-        have to do it ourselves, to make emacs-gdb and xxgdb work.
-        On other machines, doing this once per input should be a cheap nop.  */
+      /* Make sure that all output has been output.  Some machines may let
+        you get away with leaving out some of the gdb_flush, but not all.  */
+      wrap_here ("");
       gdb_flush (gdb_stdout);
       gdb_flush (gdb_stderr);
 
@@ -1704,6 +1815,13 @@ command_line_input (prrompt, repeat)
          error_pre_print = source_error;
        }
 
+      if (annotation_level > 1 && instream == stdin)
+       {
+         printf_unfiltered ("\n\032\032pre-");
+         printf_unfiltered (annotation_suffix);
+         printf_unfiltered ("\n");
+       }
+
       /* Don't use fancy stuff if not talking to stdin.  */
       if (command_editing_p && instream == stdin
          && ISATTY (instream))
@@ -1711,6 +1829,13 @@ command_line_input (prrompt, repeat)
       else
        rl = gdb_readline (local_prompt);
 
+      if (annotation_level > 1 && instream == stdin)
+       {
+         printf_unfiltered ("\n\032\032post-");
+         printf_unfiltered (annotation_suffix);
+         printf_unfiltered ("\n");
+       }
+
       if (!rl || rl == (char *) EOF)
        {
          got_eof = 1;
@@ -1747,6 +1872,19 @@ command_line_input (prrompt, repeat)
   if (got_eof)
     return NULL;
 
+#define SERVER_COMMAND_LENGTH 7
+  server_command =
+    (p - linebuffer > SERVER_COMMAND_LENGTH)
+      && STREQN (linebuffer, "server ", SERVER_COMMAND_LENGTH);
+  if (server_command)
+    {
+      /* Note that we don't set `line'.  Between this and the check in
+        dont_repeat, this insures that repeating will still do the
+        right thing.  */
+      *p = '\0';
+      return linebuffer + SERVER_COMMAND_LENGTH;
+    }
+
   /* Do history expansion if that is wished.  */
   if (history_expansion_p && instream == stdin
       && ISATTY (instream))
@@ -1765,7 +1903,7 @@ command_line_input (prrompt, repeat)
          if (expanded < 0)
            {
              free (history_value);
-             return command_line_input (prrompt, repeat);
+             return command_line_input (prrompt, repeat, annotation_suffix);
            }
          if (strlen (history_value) > linelength)
            {
@@ -1799,7 +1937,7 @@ command_line_input (prrompt, repeat)
       && ISATTY (stdin) && *linebuffer)
     add_history (linebuffer);
 
-  /* Note: lines consisting soley of comments are added to the command
+  /* Note: lines consisting solely of comments are added to the command
      history.  This is useful when you type a command, and then
      realize you don't want to execute it quite yet.  You can comment
      out the command and then later fetch it from the value history
@@ -1866,7 +2004,7 @@ read_command_lines ()
   while (1)
     {
       dont_repeat ();
-      p = command_line_input ((char *) NULL, instream == stdin);
+      p = command_line_input ((char *) NULL, instream == stdin, "commands");
       if (p == NULL)
        /* Treat end of file like "end".  */
        break;
@@ -1961,6 +2099,36 @@ info_command (arg, from_tty)
   help_list (infolist, "info ", -1, gdb_stdout);
 }
 
+/* The "complete" command is used by Emacs to implement completion.  */
+
+/* ARGSUSED */
+static void
+complete_command (arg, from_tty)
+     char *arg;
+     int from_tty;
+{
+  int i;
+  char *completion;
+
+  dont_repeat ();
+
+  if (arg == NULL)
+    {
+      rl_line_buffer[0] = '\0';
+      rl_point = 0;
+    }
+  else
+    {
+      strcpy (rl_line_buffer, arg);
+      rl_point = strlen (arg);
+    }
+
+  for (completion = symbol_completion_function (rl_line_buffer, i = 0);
+       completion;
+       completion = symbol_completion_function (rl_line_buffer, ++i))
+    printf_unfiltered ("%s\n", completion);
+}
+
 /* The "show" command with no arguments shows all the settings.  */
 
 /* ARGSUSED */
@@ -2179,14 +2347,14 @@ print_gdb_version (stream)
   GDB_FILE *stream;
 {
   fprintf_filtered (stream, "\
-GDB %s (%s", version, host_canonical);
+GDB %s (%s", version, host_name);
 
-  if (strcmp(host_canonical, target_canonical))
-    fprintf_filtered (stream, " --target %s", target_canonical);
+  if (!STREQ (host_name, target_name))
+    fprintf_filtered (stream, " --target %s", target_name);
 
   fprintf_filtered (stream, "), ");
   wrap_here("");
-  fprintf_filtered (stream, "Copyright 1993 Free Software Foundation, Inc.");
+  fprintf_filtered (stream, "Copyright 1994 Free Software Foundation, Inc.");
 }
 
 /* ARGSUSED */
@@ -2202,7 +2370,8 @@ show_version (args, from_tty)
   immediate_quit--;
 }
 \f
-/* xgdb calls this to reprint the usual GDB prompt.  */
+/* xgdb calls this to reprint the usual GDB prompt.  Obsolete now that xgdb
+   is obsolete.  */
 
 void
 print_prompt ()
@@ -2233,9 +2402,13 @@ quit_command (args, from_tty)
            error ("Not confirmed.");
        }
     }
+  /* UDI wants this, to kill the TIP.  */
+  target_close (1);
+
   /* Save the history information if it is appropriate to do so.  */
   if (write_history_p && history_filename)
     write_history (history_filename);
+
   exit (0);
 }
 
@@ -2475,8 +2648,7 @@ show_commands (args, from_tty)
      than the number of the last command).  Relative to history_base.  */
   int hist_len;
 
-  extern struct _hist_entry *history_get PARAMS ((int));
-  extern int history_base;
+  extern HIST_ENTRY *history_get PARAMS ((int));
 
   /* Print out some of the commands from the command history.  */
   /* First determine the length of the history list.  */
@@ -2840,6 +3012,9 @@ ie. the number of previous commands to keep a record of.", &sethistlist);
                  &infolist, "info ", 0, &cmdlist);
   add_com_alias ("i", "info", class_info, 1);
 
+  add_com ("complete", class_obscure, complete_command,
+          "List the completions for the rest of the line as a command.");
+
   add_prefix_cmd ("show", class_info, show_command,
                  "Generic command for showing things about the debugger.",
                  &showlist, "show ", 0, &cmdlist);
This page took 0.053428 seconds and 4 git commands to generate.