* Makefile.in (diststuff): Make all-doc; diststuff target does not
[deliverable/binutils-gdb.git] / gdb / main.c
index e7c8070a1cd408d2c2b9bd547ceb26f9eccf568a..42621ffa6ffde1fb39041a26367216843ec4eab2 100644 (file)
@@ -1,5 +1,5 @@
 /* Top level stuff for GDB, the GNU debugger.
-   Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994
+   Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995
    Free Software Foundation, Inc.
 
 This file is part of GDB.
@@ -28,12 +28,11 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #include "getopt.h"
 
 #include <sys/types.h>
-#include <sys/stat.h>
+#include "gdb_stat.h"
 #include <ctype.h>
 
-#include <string.h>
-/* R_OK lives in either unistd.h or sys/file.h.  */
-#ifdef USG
+#include "gdb_string.h"
+#ifdef HAVE_UNISTD_H
 #include <unistd.h>
 #endif
 #ifndef        NO_SYS_FILE
@@ -41,6 +40,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #endif
 
 /* Temporary variable for SET_TOP_LEVEL.  */
+
 static int top_level_val;
 
 /* Do a setjmp on error_return and quit_return.  catch_errors is
@@ -52,6 +52,14 @@ static int top_level_val;
     ? (PTR) 0 : (PTR) memcpy (quit_return, error_return, sizeof (jmp_buf))) \
    , top_level_val)
 
+/* If nonzero, display time usage both at startup and for each command.  */
+
+int display_time;
+
+/* If nonzero, display space usage both at startup and for each command.  */
+
+int display_space;
+
 extern void gdb_init PARAMS ((void));
 
 int
@@ -93,15 +101,15 @@ main (argc, argv)
 
   register int i;
 
-/* start-sanitize-mpw */
+  long time_at_startup = get_run_time ();
+
+  START_PROGRESS (argv[0], 0);
+
 #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");
   /* Do all Mac-specific setup. */
   mac_init ();
 #endif /* MPW */
-/* end-sanitize-mpw */
+
   /* This needs to happen before the first use of malloc.  */
   init_malloc ((PTR) NULL);
 
@@ -132,6 +140,7 @@ main (argc, argv)
   current_directory = gdb_dirbuf;
 
   /* Parse arguments and options.  */
+#ifndef WIN32
   {
     int c;
     /* When var field is 0, use flag field to record the equivalent
@@ -174,13 +183,16 @@ main (argc, argv)
        {"tty", required_argument, 0, 't'},
        {"baud", required_argument, 0, 'b'},
        {"b", required_argument, 0, 'b'},
-       {"nw", no_argument, &no_windows, 1},
-       {"nowindows", no_argument, &no_windows, 1},
+       {"nw", no_argument, &use_windows, 0},
+       {"nowindows", no_argument, &use_windows, 0},
+       {"w", no_argument, &use_windows, 1},
+       {"windows", no_argument, &use_windows, 1},
+       {"statistics", no_argument, 0, 13},
 /* Allow machine descriptions to add more options... */
 #ifdef ADDITIONAL_OPTIONS
        ADDITIONAL_OPTIONS
 #endif
-       {0, no_argument, 0, 0},
+       {0, no_argument, 0, 0}
       };
 
     while (1)
@@ -212,8 +224,15 @@ main (argc, argv)
            /* FIXME: what if the syntax is wrong (e.g. not digits)?  */
            annotation_level = atoi (optarg);
            break;
+         case 13:
+           /* Enable the display of both time and space usage.  */
+           display_time = 1;
+           display_space = 1;
+           break;
          case 'f':
            annotation_level = 1;
+/* We have probably been invoked from emacs.  Disable window interface.  */
+           use_windows = 0;
            break;
          case 's':
            symarg = optarg;
@@ -300,6 +319,7 @@ main (argc, argv)
       quiet = 1;
   }
 
+#endif
   gdb_init ();
 
   /* Do these (and anything which might call wrap_here or *_filtered)
@@ -325,12 +345,6 @@ 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\
@@ -339,24 +353,27 @@ Options:\n\
   --quiet            Do not print version number on startup.\n\
   --fullname         Output information used by emacs-GDB interface.\n\
   --epoch            Output information used by epoch emacs-GDB interface.\n\
+", gdb_stdout);
+      fputs_unfiltered ("\
   --batch            Exit after processing options.\n\
   --nx               Do not read .gdbinit file.\n\
   --tty=TTY          Use TTY for input/output by the program being debugged.\n\
   --cd=DIR           Change current directory to DIR.\n\
   --directory=DIR    Search for source files in DIR.\n\
+", gdb_stdout);
+      fputs_unfiltered ("\
   --command=FILE     Execute GDB commands from FILE.\n\
   --symbols=SYMFILE  Read symbols from SYMFILE.\n\
   --exec=EXECFILE    Use EXECFILE as the executable.\n\
   --se=FILE          Use FILE as symbol file and executable file.\n\
+", gdb_stdout);
+      fputs_unfiltered ("\
   --core=COREFILE    Analyze the core dump COREFILE.\n\
   -b BAUDRATE        Set serial port baud rate used for remote debugging.\n\
   --mapped           Use mapped symbol files if supported on this system.\n\
   --readnow          Fully read symbol files on first access.\n\
   --nw              Do not use a window interface.\n\
 ", gdb_stdout);
-/* start-sanitize-mpw */
-#endif /* MPW_C */
-/* end-sanitize-mpw */
 #ifdef ADDITIONAL_OPTION_HELP
       fputs_unfiltered (ADDITIONAL_OPTION_HELP, gdb_stdout);
 #endif
@@ -379,6 +396,8 @@ GDB manual (available as on-line info or a printed manual).\n", gdb_stdout);
     }
 
   error_pre_print = "\n\n";
+  quit_pre_print = error_pre_print;
+
   /* We may get more than one warning, don't double space all of them... */
   warning_pre_print = "\nwarning: ";
 
@@ -459,6 +478,7 @@ GDB manual (available as on-line info or a printed manual).\n", gdb_stdout);
   if (!quiet)
     printf_filtered ("\n");
   error_pre_print = "\n";
+  quit_pre_print = error_pre_print;
   warning_pre_print = "\nwarning: ";
 
   if (corearg != NULL)
@@ -478,7 +498,8 @@ GDB manual (available as on-line info or a printed manual).\n", gdb_stdout);
 #endif
 
   /* Error messages should no longer be distinguished with extra output. */
-  error_pre_print = 0;
+  error_pre_print = NULL;
+  quit_pre_print = NULL;
   warning_pre_print = "warning: ";
 
   /* Read the .gdbinit file in the current directory, *if* it isn't
@@ -522,8 +543,31 @@ GDB manual (available as on-line info or a printed manual).\n", gdb_stdout);
   BEFORE_MAIN_LOOP_HOOK;
 #endif
 
-  /* The command loop.  */
+  END_PROGRESS (argv[0]);
+
+  /* Show time and/or space usage.  */
+
+  if (display_time)
+    {
+      long init_time = get_run_time () - time_at_startup;
+
+      printf_unfiltered ("Startup time: %ld.%06ld\n",
+                        init_time / 1000000, init_time % 1000000);
+    }
+
+  if (display_space)
+    {
+      extern char **environ;
+      char *lim = (char *) sbrk (0);
+
+      printf_unfiltered ("Startup size: data size %ld\n",
+                        (long) (lim - (char *) &environ));
+    }
 
+  /* The default command loop. 
+     The WIN32 Gui calls this main to set up gdb's state, and 
+     has its own command loop. */
+#if !defined (WIN32)
   while (1)
     {
       if (!SET_TOP_LEVEL ())
@@ -539,7 +583,10 @@ GDB manual (available as on-line info or a printed manual).\n", gdb_stdout);
           quit_command ((char *)0, instream == stdin);
        }
     }
+
   /* No exit -- exit is through quit_command.  */
+#endif
+
 }
 \f
 void
@@ -570,7 +617,12 @@ fputs_unfiltered (linebuffer, stream)
 {
   if (fputs_unfiltered_hook)
     {
-      fputs_unfiltered_hook (linebuffer);
+      /* FIXME: I think we should only be doing this for stdout or stderr.
+        Either that or we should be passing stream to the hook so it can
+        deal with it.  If that is cleaned up, this function can go back
+        into utils.c and the fputs_unfiltered_hook can replace the current
+        ability to avoid this function by not linking with main.c.  */
+      fputs_unfiltered_hook (linebuffer, stream);
       return;
     }
 
This page took 0.035227 seconds and 4 git commands to generate.