*** empty log message ***
[deliverable/binutils-gdb.git] / gdb / main.c
index 7ccc47fbd424d5c047de068795dd8b39c7e2d0ef..f7aa5188f39eae71af441108199ab6b1d99f1400 100644 (file)
@@ -1,6 +1,6 @@
 /* Top level stuff for GDB, the GNU debugger.
-   Copyright 1986, 87, 88, 89, 90, 91, 92, 93, 94, 95, 1999
-   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.
 
@@ -23,7 +23,8 @@
 #include "top.h"
 #include "target.h"
 #include "inferior.h"
-#include "call-cmds.h"
+#include "symfile.h"
+#include "gdbcore.h"
 
 #include "getopt.h"
 
@@ -33,7 +34,9 @@
 
 #include "gdb_string.h"
 #include "event-loop.h"
-#if defined (TUI) || defined (GDBTK)
+#include "ui-out.h"
+
+#if defined (TUI)
 /* FIXME: cagney/2000-01-31: This #include is to allow older code such
    as that found in the TUI to continue to build. */
 #include "tui/tui-file.h"
@@ -53,6 +56,11 @@ int display_space;
    processes UI events asynchronously. */
 int event_loop_p = 1;
 
+#ifdef UI_OUT
+/* Has an interpreter been specified and if so, which. */
+char *interpreter_p;
+#endif
+
 /* Whether this is the command line version or not */
 int tui_version = 0;
 
@@ -62,10 +70,10 @@ int xdb_commands = 0;
 /* Whether dbx commands will be handled */
 int dbx_commands = 0;
 
-GDB_FILE *gdb_stdout;
-GDB_FILE *gdb_stderr;
-GDB_FILE *gdb_stdlog;
-GDB_FILE *gdb_stdtarg;
+struct ui_file *gdb_stdout;
+struct ui_file *gdb_stderr;
+struct ui_file *gdb_stdlog;
+struct ui_file *gdb_stdtarg;
 
 /* Used to initialize error() - defined in utils.c */
 
@@ -74,7 +82,7 @@ extern void error_init (void);
 /* Whether to enable writing into executable and core files */
 extern int write_files;
 
-static void print_gdb_help PARAMS ((GDB_FILE *));
+static void print_gdb_help (struct ui_file *);
 
 /* These two are used to set the external editor commands when gdb is farming
    out files to be edited by another program. */
@@ -82,11 +90,6 @@ static void print_gdb_help PARAMS ((GDB_FILE *));
 extern int enable_external_editor;
 extern char *external_editor_command;
 
-#ifdef __CYGWIN__
-#include <windows.h>           /* for MAX_PATH */
-#include <sys/cygwin.h>                /* for cygwin32_conv_to_posix_path */
-#endif
-
 /* Call command_loop.  If it happens to return, pass that through as a
    non-zero return status. */
 
@@ -100,7 +103,7 @@ captured_command_loop (void *data)
   /* FIXME: cagney/1999-11-05: A correct command_loop() implementaton
      would clean things up (restoring the cleanup chain) to the state
      they were just prior to the call.  Technically, this means that
-     the do_cleanups() below is redundant.  Unfortunatly, many FUNC's
+     the do_cleanups() below is redundant.  Unfortunately, many FUNCs
      are not that well behaved.  do_cleanups should either be replaced
      with a do_cleanups call (to cover the problem) or an assertion
      check to detect bad FUNCs code. */
@@ -192,10 +195,7 @@ captured_main (void *data)
   getcwd (gdb_dirbuf, sizeof (gdb_dirbuf));
   current_directory = gdb_dirbuf;
 
-#if defined (TUI) || defined (GDBTK)
-  /* Older code uses the tui_file and fputs_unfiltered_hook().  It
-     should be using a customized GDB_FILE object and re-initializing
-     within its own _initialize function.  */
+#if defined (TUI)
   gdb_stdout = tui_fileopen (stdout);
   gdb_stderr = tui_fileopen (stderr);
   gdb_stdlog = gdb_stdout;     /* for moment */
@@ -255,6 +255,16 @@ captured_main (void *data)
       {"command", required_argument, 0, 'x'},
       {"version", no_argument, &print_version, 1},
       {"x", required_argument, 0, 'x'},
+#ifdef GDBTK
+      {"tclcommand", required_argument, 0, 'z'},
+      {"enable-external-editor", no_argument, 0, 'y'},
+      {"editor-command", required_argument, 0, 'w'},
+#endif
+#ifdef UI_OUT
+      {"ui", required_argument, 0, 'i'},
+      {"interpreter", required_argument, 0, 'i'},
+      {"i", required_argument, 0, 'i'},
+#endif
       {"directory", required_argument, 0, 'd'},
       {"d", required_argument, 0, 'd'},
       {"cd", required_argument, 0, 11},
@@ -331,6 +341,45 @@ captured_main (void *data)
                                             cmdsize * sizeof (*cmdarg));
              }
            break;
+#ifdef GDBTK
+         case 'z':
+           {
+extern int gdbtk_test (char *);
+             if (!gdbtk_test (optarg))
+               {
+                 fprintf_unfiltered (gdb_stderr, "%s: unable to load tclcommand file \"%s\"",
+                                     argv[0], optarg);
+                 exit (1);
+               }
+             break;
+           }
+         case 'y':
+           {
+             /*
+              * This enables the edit/button in the main window, even
+              * when IDE_ENABLED is set to false. In this case you must
+              * use --tclcommand to specify a tcl/script to be called,
+              * Tcl/Variable to store the edit/command is:
+              * external_editor
+              */
+             enable_external_editor = 1;
+             break;
+           }
+         case 'w':
+           {
+             /*
+              * if editor command is enabled, both flags are set
+              */
+             enable_external_editor = 1;
+             external_editor_command = xstrdup (optarg);
+             break;
+           }
+#endif /* GDBTK */
+#ifdef UI_OUT
+         case 'i':
+           interpreter_p = optarg;
+           break;
+#endif
          case 'd':
            dirarg[ndir++] = optarg;
            if (ndir >= dirsize)
@@ -420,6 +469,7 @@ captured_main (void *data)
          execarg = argv[optind];
          break;
        case 2:
+         /* FIXME: The documentation says this can be a "ProcID". as well. */
          corearg = argv[optind];
          break;
        case 3:
@@ -480,21 +530,7 @@ captured_main (void *data)
      *before* all the command line arguments are processed; it sets
      global parameters, which are independent of what file you are
      debugging or what directory you are in.  */
-#ifdef __CYGWIN32__
-  {
-    char *tmp = getenv ("HOME");
-
-    if (tmp != NULL)
-      {
-       homedir = (char *) alloca (MAX_PATH + 1);
-       cygwin32_conv_to_posix_path (tmp, homedir);
-      }
-    else
-      homedir = NULL;
-  }
-#else
   homedir = getenv ("HOME");
-#endif
   if (homedir)
     {
       homeinit = (char *) alloca (strlen (homedir) +
@@ -529,7 +565,7 @@ captured_main (void *data)
 
   for (i = 0; i < ndir; i++)
     catch_command_errors (directory_command, dirarg[i], 0, RETURN_MASK_ALL);
-  free ((PTR) dirarg);
+  xfree (dirarg);
 
   if (execarg != NULL
       && symarg != NULL
@@ -538,15 +574,15 @@ captured_main (void *data)
       /* The exec file and the symbol-file are the same.  If we can't
          open it, better only print one error message.
          catch_command_errors returns non-zero on success! */
-      if (catch_command_errors (exec_file_command, execarg, !batch, RETURN_MASK_ALL))
-       catch_command_errors (symbol_file_command, symarg, 0, RETURN_MASK_ALL);
+      if (catch_command_errors (exec_file_attach, execarg, !batch, RETURN_MASK_ALL))
+       catch_command_errors (symbol_file_add_main, symarg, 0, RETURN_MASK_ALL);
     }
   else
     {
       if (execarg != NULL)
-       catch_command_errors (exec_file_command, execarg, !batch, RETURN_MASK_ALL);
+       catch_command_errors (exec_file_attach, execarg, !batch, RETURN_MASK_ALL);
       if (symarg != NULL)
-       catch_command_errors (symbol_file_command, symarg, 0, RETURN_MASK_ALL);
+       catch_command_errors (symbol_file_add_main, symarg, 0, RETURN_MASK_ALL);
     }
 
   /* After the symbol file has been read, print a newline to get us
@@ -611,7 +647,7 @@ captured_main (void *data)
 #endif
       catch_command_errors (source_command, cmdarg[i], !batch, RETURN_MASK_ALL);
     }
-  free ((PTR) cmdarg);
+  xfree (cmdarg);
 
   /* Read in the old history after all the command files have been read. */
   init_history ();
@@ -652,13 +688,6 @@ captured_main (void *data)
 #endif
     }
 
-  /* 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 || defined __GNUC__
-  /* GUIs generally have their own command loop, mainloop, or
-     whatever.  This is a good place to gain control because many
-     error conditions will end up here via longjmp(). */
 #if 0
   /* FIXME: cagney/1999-11-06: The original main loop was like: */
   while (1)
@@ -694,7 +723,6 @@ captured_main (void *data)
     {
       catch_errors (captured_command_loop, 0, "", RETURN_MASK_ALL);
     }
-#endif
   /* No exit -- exit is through quit_command.  */
 }
 
@@ -714,8 +742,7 @@ main (int argc, char **argv)
    to print.  */
 
 static void
-print_gdb_help (stream)
-     GDB_FILE *stream;
+print_gdb_help (struct ui_file *stream)
 {
   fputs_unfiltered ("\
 This is the GNU debugger.  Usage:\n\n\
@@ -739,6 +766,10 @@ Options:\n\n\
   --exec=EXECFILE    Use EXECFILE as the executable.\n\
   --fullname         Output information used by emacs-GDB interface.\n\
   --help             Print this message.\n\
+", stream);
+  fputs_unfiltered ("\
+  --interpreter=INTERP\n\
+                     Select a specific interpreter / user interface\n\
 ", stream);
   fputs_unfiltered ("\
   --mapped           Use mapped symbol files if supported on this system.\n\
This page took 0.032062 seconds and 4 git commands to generate.