xref: /dflybsd-src/contrib/gdb-7/gdb/main.c (revision ef5ccd6c41237a870dd7242b72b006d6bd42cd07)
15796c8dcSSimon Schubert /* Top level stuff for GDB, the GNU debugger.
25796c8dcSSimon Schubert 
3*ef5ccd6cSJohn Marino    Copyright (C) 1986-2013 Free Software Foundation, Inc.
45796c8dcSSimon Schubert 
55796c8dcSSimon Schubert    This file is part of GDB.
65796c8dcSSimon Schubert 
75796c8dcSSimon Schubert    This program is free software; you can redistribute it and/or modify
85796c8dcSSimon Schubert    it under the terms of the GNU General Public License as published by
95796c8dcSSimon Schubert    the Free Software Foundation; either version 3 of the License, or
105796c8dcSSimon Schubert    (at your option) any later version.
115796c8dcSSimon Schubert 
125796c8dcSSimon Schubert    This program is distributed in the hope that it will be useful,
135796c8dcSSimon Schubert    but WITHOUT ANY WARRANTY; without even the implied warranty of
145796c8dcSSimon Schubert    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
155796c8dcSSimon Schubert    GNU General Public License for more details.
165796c8dcSSimon Schubert 
175796c8dcSSimon Schubert    You should have received a copy of the GNU General Public License
185796c8dcSSimon Schubert    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
195796c8dcSSimon Schubert 
205796c8dcSSimon Schubert #include "defs.h"
215796c8dcSSimon Schubert #include "top.h"
225796c8dcSSimon Schubert #include "target.h"
235796c8dcSSimon Schubert #include "inferior.h"
245796c8dcSSimon Schubert #include "symfile.h"
255796c8dcSSimon Schubert #include "gdbcore.h"
265796c8dcSSimon Schubert 
275796c8dcSSimon Schubert #include "exceptions.h"
285796c8dcSSimon Schubert #include "getopt.h"
295796c8dcSSimon Schubert 
305796c8dcSSimon Schubert #include <sys/types.h>
315796c8dcSSimon Schubert #include "gdb_stat.h"
325796c8dcSSimon Schubert #include <ctype.h>
335796c8dcSSimon Schubert 
345796c8dcSSimon Schubert #include "gdb_string.h"
355796c8dcSSimon Schubert #include "event-loop.h"
365796c8dcSSimon Schubert #include "ui-out.h"
375796c8dcSSimon Schubert 
385796c8dcSSimon Schubert #include "interps.h"
395796c8dcSSimon Schubert #include "main.h"
405796c8dcSSimon Schubert #include "source.h"
41cf7f2e2dSJohn Marino #include "cli/cli-cmds.h"
42cf7f2e2dSJohn Marino #include "python/python.h"
43c50c785cSJohn Marino #include "objfiles.h"
44*ef5ccd6cSJohn Marino #include "auto-load.h"
45*ef5ccd6cSJohn Marino 
46*ef5ccd6cSJohn Marino #include "filenames.h"
475796c8dcSSimon Schubert 
485796c8dcSSimon Schubert /* The selected interpreter.  This will be used as a set command
495796c8dcSSimon Schubert    variable, so it should always be malloc'ed - since
505796c8dcSSimon Schubert    do_setshow_command will free it.  */
515796c8dcSSimon Schubert char *interpreter_p;
525796c8dcSSimon Schubert 
53c50c785cSJohn Marino /* Whether xdb commands will be handled.  */
545796c8dcSSimon Schubert int xdb_commands = 0;
555796c8dcSSimon Schubert 
56c50c785cSJohn Marino /* Whether dbx commands will be handled.  */
575796c8dcSSimon Schubert int dbx_commands = 0;
585796c8dcSSimon Schubert 
595796c8dcSSimon Schubert /* System root path, used to find libraries etc.  */
605796c8dcSSimon Schubert char *gdb_sysroot = 0;
615796c8dcSSimon Schubert 
625796c8dcSSimon Schubert /* GDB datadir, used to store data files.  */
635796c8dcSSimon Schubert char *gdb_datadir = 0;
645796c8dcSSimon Schubert 
65*ef5ccd6cSJohn Marino /* Non-zero if GDB_DATADIR was provided on the command line.
66*ef5ccd6cSJohn Marino    This doesn't track whether data-directory is set later from the
67*ef5ccd6cSJohn Marino    command line, but we don't reread system.gdbinit when that happens.  */
68*ef5ccd6cSJohn Marino static int gdb_datadir_provided = 0;
69*ef5ccd6cSJohn Marino 
70cf7f2e2dSJohn Marino /* If gdb was configured with --with-python=/path,
71cf7f2e2dSJohn Marino    the possibly relocated path to python's lib directory.  */
72cf7f2e2dSJohn Marino char *python_libdir = 0;
73cf7f2e2dSJohn Marino 
745796c8dcSSimon Schubert struct ui_file *gdb_stdout;
755796c8dcSSimon Schubert struct ui_file *gdb_stderr;
765796c8dcSSimon Schubert struct ui_file *gdb_stdlog;
775796c8dcSSimon Schubert struct ui_file *gdb_stdin;
78c50c785cSJohn Marino /* Target IO streams.  */
795796c8dcSSimon Schubert struct ui_file *gdb_stdtargin;
805796c8dcSSimon Schubert struct ui_file *gdb_stdtarg;
815796c8dcSSimon Schubert struct ui_file *gdb_stdtargerr;
825796c8dcSSimon Schubert 
83cf7f2e2dSJohn Marino /* True if --batch or --batch-silent was seen.  */
84cf7f2e2dSJohn Marino int batch_flag = 0;
85cf7f2e2dSJohn Marino 
865796c8dcSSimon Schubert /* Support for the --batch-silent option.  */
875796c8dcSSimon Schubert int batch_silent = 0;
885796c8dcSSimon Schubert 
895796c8dcSSimon Schubert /* Support for --return-child-result option.
905796c8dcSSimon Schubert    Set the default to -1 to return error in the case
915796c8dcSSimon Schubert    that the program does not run or does not complete.  */
925796c8dcSSimon Schubert int return_child_result = 0;
935796c8dcSSimon Schubert int return_child_result_value = -1;
945796c8dcSSimon Schubert 
955796c8dcSSimon Schubert 
965796c8dcSSimon Schubert /* GDB as it has been invoked from the command line (i.e. argv[0]).  */
975796c8dcSSimon Schubert static char *gdb_program_name;
985796c8dcSSimon Schubert 
995796c8dcSSimon Schubert static void print_gdb_help (struct ui_file *);
1005796c8dcSSimon Schubert 
1015796c8dcSSimon Schubert /* Relocate a file or directory.  PROGNAME is the name by which gdb
1025796c8dcSSimon Schubert    was invoked (i.e., argv[0]).  INITIAL is the default value for the
1035796c8dcSSimon Schubert    file or directory.  FLAG is true if the value is relocatable, false
1045796c8dcSSimon Schubert    otherwise.  Returns a newly allocated string; this may return NULL
1055796c8dcSSimon Schubert    under the same conditions as make_relative_prefix.  */
106a45ae5f8SJohn Marino 
1075796c8dcSSimon Schubert static char *
1085796c8dcSSimon Schubert relocate_path (const char *progname, const char *initial, int flag)
1095796c8dcSSimon Schubert {
1105796c8dcSSimon Schubert   if (flag)
1115796c8dcSSimon Schubert     return make_relative_prefix (progname, BINDIR, initial);
1125796c8dcSSimon Schubert   return xstrdup (initial);
1135796c8dcSSimon Schubert }
1145796c8dcSSimon Schubert 
1155796c8dcSSimon Schubert /* Like relocate_path, but specifically checks for a directory.
1165796c8dcSSimon Schubert    INITIAL is relocated according to the rules of relocate_path.  If
1175796c8dcSSimon Schubert    the result is a directory, it is used; otherwise, INITIAL is used.
1185796c8dcSSimon Schubert    The chosen directory is then canonicalized using lrealpath.  This
1195796c8dcSSimon Schubert    function always returns a newly-allocated string.  */
120a45ae5f8SJohn Marino 
121a45ae5f8SJohn Marino char *
122a45ae5f8SJohn Marino relocate_gdb_directory (const char *initial, int flag)
1235796c8dcSSimon Schubert {
1245796c8dcSSimon Schubert   char *dir;
1255796c8dcSSimon Schubert 
126a45ae5f8SJohn Marino   dir = relocate_path (gdb_program_name, initial, flag);
1275796c8dcSSimon Schubert   if (dir)
1285796c8dcSSimon Schubert     {
1295796c8dcSSimon Schubert       struct stat s;
1305796c8dcSSimon Schubert 
131*ef5ccd6cSJohn Marino       if (*dir == '\0' || stat (dir, &s) != 0 || !S_ISDIR (s.st_mode))
1325796c8dcSSimon Schubert 	{
1335796c8dcSSimon Schubert 	  xfree (dir);
1345796c8dcSSimon Schubert 	  dir = NULL;
1355796c8dcSSimon Schubert 	}
1365796c8dcSSimon Schubert     }
1375796c8dcSSimon Schubert   if (!dir)
1385796c8dcSSimon Schubert     dir = xstrdup (initial);
1395796c8dcSSimon Schubert 
1405796c8dcSSimon Schubert   /* Canonicalize the directory.  */
1415796c8dcSSimon Schubert   if (*dir)
1425796c8dcSSimon Schubert     {
1435796c8dcSSimon Schubert       char *canon_sysroot = lrealpath (dir);
144cf7f2e2dSJohn Marino 
1455796c8dcSSimon Schubert       if (canon_sysroot)
1465796c8dcSSimon Schubert 	{
1475796c8dcSSimon Schubert 	  xfree (dir);
1485796c8dcSSimon Schubert 	  dir = canon_sysroot;
1495796c8dcSSimon Schubert 	}
1505796c8dcSSimon Schubert     }
1515796c8dcSSimon Schubert 
1525796c8dcSSimon Schubert   return dir;
1535796c8dcSSimon Schubert }
1545796c8dcSSimon Schubert 
155c50c785cSJohn Marino /* Compute the locations of init files that GDB should source and
156c50c785cSJohn Marino    return them in SYSTEM_GDBINIT, HOME_GDBINIT, LOCAL_GDBINIT.  If
157c50c785cSJohn Marino    there is no system gdbinit (resp. home gdbinit and local gdbinit)
158c50c785cSJohn Marino    to be loaded, then SYSTEM_GDBINIT (resp. HOME_GDBINIT and
159c50c785cSJohn Marino    LOCAL_GDBINIT) is set to NULL.  */
1605796c8dcSSimon Schubert static void
1615796c8dcSSimon Schubert get_init_files (char **system_gdbinit,
1625796c8dcSSimon Schubert 		char **home_gdbinit,
1635796c8dcSSimon Schubert 		char **local_gdbinit)
1645796c8dcSSimon Schubert {
1655796c8dcSSimon Schubert   static char *sysgdbinit = NULL;
1665796c8dcSSimon Schubert   static char *homeinit = NULL;
1675796c8dcSSimon Schubert   static char *localinit = NULL;
1685796c8dcSSimon Schubert   static int initialized = 0;
1695796c8dcSSimon Schubert 
1705796c8dcSSimon Schubert   if (!initialized)
1715796c8dcSSimon Schubert     {
1725796c8dcSSimon Schubert       struct stat homebuf, cwdbuf, s;
173*ef5ccd6cSJohn Marino       char *homedir;
1745796c8dcSSimon Schubert 
1755796c8dcSSimon Schubert       if (SYSTEM_GDBINIT[0])
1765796c8dcSSimon Schubert 	{
177*ef5ccd6cSJohn Marino 	  int datadir_len = strlen (GDB_DATADIR);
178*ef5ccd6cSJohn Marino 	  int sys_gdbinit_len = strlen (SYSTEM_GDBINIT);
179*ef5ccd6cSJohn Marino 	  char *relocated_sysgdbinit;
180*ef5ccd6cSJohn Marino 
181*ef5ccd6cSJohn Marino 	  /* If SYSTEM_GDBINIT lives in data-directory, and data-directory
182*ef5ccd6cSJohn Marino 	     has been provided, search for SYSTEM_GDBINIT there.  */
183*ef5ccd6cSJohn Marino 	  if (gdb_datadir_provided
184*ef5ccd6cSJohn Marino 	      && datadir_len < sys_gdbinit_len
185*ef5ccd6cSJohn Marino 	      && filename_ncmp (SYSTEM_GDBINIT, GDB_DATADIR, datadir_len) == 0
186*ef5ccd6cSJohn Marino 	      && IS_DIR_SEPARATOR (SYSTEM_GDBINIT[datadir_len]))
187*ef5ccd6cSJohn Marino 	    {
188*ef5ccd6cSJohn Marino 	      /* Append the part of SYSTEM_GDBINIT that follows GDB_DATADIR
189*ef5ccd6cSJohn Marino 		 to gdb_datadir.  */
190*ef5ccd6cSJohn Marino 	      char *tmp_sys_gdbinit = xstrdup (SYSTEM_GDBINIT + datadir_len);
191*ef5ccd6cSJohn Marino 	      char *p;
192*ef5ccd6cSJohn Marino 
193*ef5ccd6cSJohn Marino 	      for (p = tmp_sys_gdbinit; IS_DIR_SEPARATOR (*p); ++p)
194*ef5ccd6cSJohn Marino 		continue;
195*ef5ccd6cSJohn Marino 	      relocated_sysgdbinit = concat (gdb_datadir, SLASH_STRING, p,
196*ef5ccd6cSJohn Marino 					     NULL);
197*ef5ccd6cSJohn Marino 	      xfree (tmp_sys_gdbinit);
198*ef5ccd6cSJohn Marino 	    }
199*ef5ccd6cSJohn Marino 	  else
200*ef5ccd6cSJohn Marino 	    {
2015796c8dcSSimon Schubert 	      relocated_sysgdbinit = relocate_path (gdb_program_name,
2025796c8dcSSimon Schubert 						    SYSTEM_GDBINIT,
2035796c8dcSSimon Schubert 						    SYSTEM_GDBINIT_RELOCATABLE);
204*ef5ccd6cSJohn Marino 	    }
2055796c8dcSSimon Schubert 	  if (relocated_sysgdbinit && stat (relocated_sysgdbinit, &s) == 0)
2065796c8dcSSimon Schubert 	    sysgdbinit = relocated_sysgdbinit;
2075796c8dcSSimon Schubert 	  else
2085796c8dcSSimon Schubert 	    xfree (relocated_sysgdbinit);
2095796c8dcSSimon Schubert 	}
2105796c8dcSSimon Schubert 
2115796c8dcSSimon Schubert       homedir = getenv ("HOME");
2125796c8dcSSimon Schubert 
2135796c8dcSSimon Schubert       /* If the .gdbinit file in the current directory is the same as
2145796c8dcSSimon Schubert 	 the $HOME/.gdbinit file, it should not be sourced.  homebuf
2155796c8dcSSimon Schubert 	 and cwdbuf are used in that purpose.  Make sure that the stats
2165796c8dcSSimon Schubert 	 are zero in case one of them fails (this guarantees that they
2175796c8dcSSimon Schubert 	 won't match if either exists).  */
2185796c8dcSSimon Schubert 
2195796c8dcSSimon Schubert       memset (&homebuf, 0, sizeof (struct stat));
2205796c8dcSSimon Schubert       memset (&cwdbuf, 0, sizeof (struct stat));
2215796c8dcSSimon Schubert 
2225796c8dcSSimon Schubert       if (homedir)
2235796c8dcSSimon Schubert 	{
2245796c8dcSSimon Schubert 	  homeinit = xstrprintf ("%s/%s", homedir, gdbinit);
2255796c8dcSSimon Schubert 	  if (stat (homeinit, &homebuf) != 0)
2265796c8dcSSimon Schubert 	    {
2275796c8dcSSimon Schubert 	      xfree (homeinit);
2285796c8dcSSimon Schubert 	      homeinit = NULL;
2295796c8dcSSimon Schubert 	    }
2305796c8dcSSimon Schubert 	}
2315796c8dcSSimon Schubert 
2325796c8dcSSimon Schubert       if (stat (gdbinit, &cwdbuf) == 0)
2335796c8dcSSimon Schubert 	{
2345796c8dcSSimon Schubert 	  if (!homeinit
2355796c8dcSSimon Schubert 	      || memcmp ((char *) &homebuf, (char *) &cwdbuf,
2365796c8dcSSimon Schubert 			 sizeof (struct stat)))
2375796c8dcSSimon Schubert 	    localinit = gdbinit;
2385796c8dcSSimon Schubert 	}
2395796c8dcSSimon Schubert 
2405796c8dcSSimon Schubert       initialized = 1;
2415796c8dcSSimon Schubert     }
2425796c8dcSSimon Schubert 
2435796c8dcSSimon Schubert   *system_gdbinit = sysgdbinit;
2445796c8dcSSimon Schubert   *home_gdbinit = homeinit;
2455796c8dcSSimon Schubert   *local_gdbinit = localinit;
2465796c8dcSSimon Schubert }
2475796c8dcSSimon Schubert 
2485796c8dcSSimon Schubert /* Call command_loop.  If it happens to return, pass that through as a
2495796c8dcSSimon Schubert    non-zero return status.  */
2505796c8dcSSimon Schubert 
2515796c8dcSSimon Schubert static int
2525796c8dcSSimon Schubert captured_command_loop (void *data)
2535796c8dcSSimon Schubert {
254a45ae5f8SJohn Marino   /* Top-level execution commands can be run on the background from
255a45ae5f8SJohn Marino      here on.  */
256a45ae5f8SJohn Marino   interpreter_async = 1;
257a45ae5f8SJohn Marino 
2585796c8dcSSimon Schubert   current_interp_command_loop ();
2595796c8dcSSimon Schubert   /* FIXME: cagney/1999-11-05: A correct command_loop() implementaton
2605796c8dcSSimon Schubert      would clean things up (restoring the cleanup chain) to the state
2615796c8dcSSimon Schubert      they were just prior to the call.  Technically, this means that
2625796c8dcSSimon Schubert      the do_cleanups() below is redundant.  Unfortunately, many FUNCs
2635796c8dcSSimon Schubert      are not that well behaved.  do_cleanups should either be replaced
2645796c8dcSSimon Schubert      with a do_cleanups call (to cover the problem) or an assertion
2655796c8dcSSimon Schubert      check to detect bad FUNCs code.  */
266*ef5ccd6cSJohn Marino   do_cleanups (all_cleanups ());
2675796c8dcSSimon Schubert   /* If the command_loop returned, normally (rather than threw an
2685796c8dcSSimon Schubert      error) we try to quit.  If the quit is aborted, catch_errors()
2695796c8dcSSimon Schubert      which called this catch the signal and restart the command
2705796c8dcSSimon Schubert      loop.  */
2715796c8dcSSimon Schubert   quit_command (NULL, instream == stdin);
2725796c8dcSSimon Schubert   return 1;
2735796c8dcSSimon Schubert }
2745796c8dcSSimon Schubert 
275*ef5ccd6cSJohn Marino /* Arguments of --command option and its counterpart.  */
276*ef5ccd6cSJohn Marino typedef struct cmdarg {
277*ef5ccd6cSJohn Marino   /* Type of this option.  */
278*ef5ccd6cSJohn Marino   enum {
279*ef5ccd6cSJohn Marino     /* Option type -x.  */
280*ef5ccd6cSJohn Marino     CMDARG_FILE,
281*ef5ccd6cSJohn Marino 
282*ef5ccd6cSJohn Marino     /* Option type -ex.  */
283*ef5ccd6cSJohn Marino     CMDARG_COMMAND,
284*ef5ccd6cSJohn Marino 
285*ef5ccd6cSJohn Marino     /* Option type -ix.  */
286*ef5ccd6cSJohn Marino     CMDARG_INIT_FILE,
287*ef5ccd6cSJohn Marino 
288*ef5ccd6cSJohn Marino     /* Option type -iex.  */
289*ef5ccd6cSJohn Marino     CMDARG_INIT_COMMAND
290*ef5ccd6cSJohn Marino   } type;
291*ef5ccd6cSJohn Marino 
292*ef5ccd6cSJohn Marino   /* Value of this option - filename or the GDB command itself.  String memory
293*ef5ccd6cSJohn Marino      is not owned by this structure despite it is 'const'.  */
294*ef5ccd6cSJohn Marino   char *string;
295*ef5ccd6cSJohn Marino } cmdarg_s;
296*ef5ccd6cSJohn Marino 
297*ef5ccd6cSJohn Marino /* Define type VEC (cmdarg_s).  */
298*ef5ccd6cSJohn Marino DEF_VEC_O (cmdarg_s);
299*ef5ccd6cSJohn Marino 
3005796c8dcSSimon Schubert static int
3015796c8dcSSimon Schubert captured_main (void *data)
3025796c8dcSSimon Schubert {
3035796c8dcSSimon Schubert   struct captured_main_args *context = data;
3045796c8dcSSimon Schubert   int argc = context->argc;
3055796c8dcSSimon Schubert   char **argv = context->argv;
3065796c8dcSSimon Schubert   static int quiet = 0;
3075796c8dcSSimon Schubert   static int set_args = 0;
308*ef5ccd6cSJohn Marino   static int inhibit_home_gdbinit = 0;
3095796c8dcSSimon Schubert 
3105796c8dcSSimon Schubert   /* Pointers to various arguments from command line.  */
3115796c8dcSSimon Schubert   char *symarg = NULL;
3125796c8dcSSimon Schubert   char *execarg = NULL;
3135796c8dcSSimon Schubert   char *pidarg = NULL;
3145796c8dcSSimon Schubert   char *corearg = NULL;
3155796c8dcSSimon Schubert   char *pid_or_core_arg = NULL;
3165796c8dcSSimon Schubert   char *cdarg = NULL;
3175796c8dcSSimon Schubert   char *ttyarg = NULL;
3185796c8dcSSimon Schubert 
319c50c785cSJohn Marino   /* These are static so that we can take their address in an
320c50c785cSJohn Marino      initializer.  */
3215796c8dcSSimon Schubert   static int print_help;
3225796c8dcSSimon Schubert   static int print_version;
3235796c8dcSSimon Schubert 
3245796c8dcSSimon Schubert   /* Pointers to all arguments of --command option.  */
325*ef5ccd6cSJohn Marino   VEC (cmdarg_s) *cmdarg_vec = NULL;
326*ef5ccd6cSJohn Marino   struct cmdarg *cmdarg_p;
3275796c8dcSSimon Schubert 
3285796c8dcSSimon Schubert   /* Indices of all arguments of --directory option.  */
3295796c8dcSSimon Schubert   char **dirarg;
3305796c8dcSSimon Schubert   /* Allocated size.  */
3315796c8dcSSimon Schubert   int dirsize;
3325796c8dcSSimon Schubert   /* Number of elements used.  */
3335796c8dcSSimon Schubert   int ndir;
3345796c8dcSSimon Schubert 
3355796c8dcSSimon Schubert   /* gdb init files.  */
3365796c8dcSSimon Schubert   char *system_gdbinit;
3375796c8dcSSimon Schubert   char *home_gdbinit;
3385796c8dcSSimon Schubert   char *local_gdbinit;
3395796c8dcSSimon Schubert 
3405796c8dcSSimon Schubert   int i;
341cf7f2e2dSJohn Marino   int save_auto_load;
342c50c785cSJohn Marino   struct objfile *objfile;
3435796c8dcSSimon Schubert 
344a45ae5f8SJohn Marino   struct cleanup *pre_stat_chain;
345a45ae5f8SJohn Marino 
346a45ae5f8SJohn Marino #ifdef HAVE_SBRK
347a45ae5f8SJohn Marino   /* Set this before calling make_command_stats_cleanup.  */
348a45ae5f8SJohn Marino   lim_at_start = (char *) sbrk (0);
349a45ae5f8SJohn Marino #endif
350a45ae5f8SJohn Marino 
351a45ae5f8SJohn Marino   pre_stat_chain = make_command_stats_cleanup (0);
3525796c8dcSSimon Schubert 
3535796c8dcSSimon Schubert #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
3545796c8dcSSimon Schubert   setlocale (LC_MESSAGES, "");
3555796c8dcSSimon Schubert #endif
3565796c8dcSSimon Schubert #if defined (HAVE_SETLOCALE)
3575796c8dcSSimon Schubert   setlocale (LC_CTYPE, "");
3585796c8dcSSimon Schubert #endif
3595796c8dcSSimon Schubert   bindtextdomain (PACKAGE, LOCALEDIR);
3605796c8dcSSimon Schubert   textdomain (PACKAGE);
3615796c8dcSSimon Schubert 
362*ef5ccd6cSJohn Marino   bfd_init ();
363*ef5ccd6cSJohn Marino 
364*ef5ccd6cSJohn Marino   make_cleanup (VEC_cleanup (cmdarg_s), &cmdarg_vec);
3655796c8dcSSimon Schubert   dirsize = 1;
3665796c8dcSSimon Schubert   dirarg = (char **) xmalloc (dirsize * sizeof (*dirarg));
3675796c8dcSSimon Schubert   ndir = 0;
3685796c8dcSSimon Schubert 
369*ef5ccd6cSJohn Marino   clear_quit_flag ();
370a45ae5f8SJohn Marino   saved_command_line = (char *) xmalloc (saved_command_line_size);
371a45ae5f8SJohn Marino   saved_command_line[0] = '\0';
3725796c8dcSSimon Schubert   instream = stdin;
3735796c8dcSSimon Schubert 
3745796c8dcSSimon Schubert   gdb_stdout = stdio_fileopen (stdout);
3755796c8dcSSimon Schubert   gdb_stderr = stdio_fileopen (stderr);
3765796c8dcSSimon Schubert   gdb_stdlog = gdb_stderr;	/* for moment */
3775796c8dcSSimon Schubert   gdb_stdtarg = gdb_stderr;	/* for moment */
3785796c8dcSSimon Schubert   gdb_stdin = stdio_fileopen (stdin);
3795796c8dcSSimon Schubert   gdb_stdtargerr = gdb_stderr;	/* for moment */
3805796c8dcSSimon Schubert   gdb_stdtargin = gdb_stdin;	/* for moment */
3815796c8dcSSimon Schubert 
382*ef5ccd6cSJohn Marino #ifdef __MINGW32__
383*ef5ccd6cSJohn Marino   /* On Windows, argv[0] is not necessarily set to absolute form when
384*ef5ccd6cSJohn Marino      GDB is found along PATH, without which relocation doesn't work.  */
385*ef5ccd6cSJohn Marino   gdb_program_name = windows_get_absolute_argv0 (argv[0]);
386*ef5ccd6cSJohn Marino #else
3875796c8dcSSimon Schubert   gdb_program_name = xstrdup (argv[0]);
388*ef5ccd6cSJohn Marino #endif
3895796c8dcSSimon Schubert 
3905796c8dcSSimon Schubert   if (! getcwd (gdb_dirbuf, sizeof (gdb_dirbuf)))
3915796c8dcSSimon Schubert     /* Don't use *_filtered or warning() (which relies on
3925796c8dcSSimon Schubert        current_target) until after initialize_all_files().  */
3935796c8dcSSimon Schubert     fprintf_unfiltered (gdb_stderr,
394c50c785cSJohn Marino 			_("%s: warning: error finding "
395c50c785cSJohn Marino 			  "working directory: %s\n"),
3965796c8dcSSimon Schubert                         argv[0], safe_strerror (errno));
3975796c8dcSSimon Schubert 
3985796c8dcSSimon Schubert   current_directory = gdb_dirbuf;
3995796c8dcSSimon Schubert 
4005796c8dcSSimon Schubert   /* Set the sysroot path.  */
401a45ae5f8SJohn Marino   gdb_sysroot = relocate_gdb_directory (TARGET_SYSTEM_ROOT,
4025796c8dcSSimon Schubert 					TARGET_SYSTEM_ROOT_RELOCATABLE);
4035796c8dcSSimon Schubert 
404a45ae5f8SJohn Marino   debug_file_directory = relocate_gdb_directory (DEBUGDIR,
4055796c8dcSSimon Schubert 						 DEBUGDIR_RELOCATABLE);
4065796c8dcSSimon Schubert 
407a45ae5f8SJohn Marino   gdb_datadir = relocate_gdb_directory (GDB_DATADIR,
4085796c8dcSSimon Schubert 					GDB_DATADIR_RELOCATABLE);
4095796c8dcSSimon Schubert 
410cf7f2e2dSJohn Marino #ifdef WITH_PYTHON_PATH
411c50c785cSJohn Marino   {
412cf7f2e2dSJohn Marino     /* For later use in helping Python find itself.  */
413c50c785cSJohn Marino     char *tmp = concat (WITH_PYTHON_PATH, SLASH_STRING, "lib", NULL);
414c50c785cSJohn Marino 
415a45ae5f8SJohn Marino     python_libdir = relocate_gdb_directory (tmp, PYTHON_PATH_RELOCATABLE);
416c50c785cSJohn Marino     xfree (tmp);
417c50c785cSJohn Marino   }
418cf7f2e2dSJohn Marino #endif
419cf7f2e2dSJohn Marino 
4205796c8dcSSimon Schubert #ifdef RELOC_SRCDIR
4215796c8dcSSimon Schubert   add_substitute_path_rule (RELOC_SRCDIR,
422*ef5ccd6cSJohn Marino 			    make_relative_prefix (gdb_program_name, BINDIR,
4235796c8dcSSimon Schubert 						  RELOC_SRCDIR));
4245796c8dcSSimon Schubert #endif
4255796c8dcSSimon Schubert 
4265796c8dcSSimon Schubert   /* There will always be an interpreter.  Either the one passed into
4275796c8dcSSimon Schubert      this captured main, or one specified by the user at start up, or
4285796c8dcSSimon Schubert      the console.  Initialize the interpreter to the one requested by
4295796c8dcSSimon Schubert      the application.  */
4305796c8dcSSimon Schubert   interpreter_p = xstrdup (context->interpreter_p);
4315796c8dcSSimon Schubert 
4325796c8dcSSimon Schubert   /* Parse arguments and options.  */
4335796c8dcSSimon Schubert   {
4345796c8dcSSimon Schubert     int c;
4355796c8dcSSimon Schubert     /* When var field is 0, use flag field to record the equivalent
4365796c8dcSSimon Schubert        short option (or arbitrary numbers starting at 10 for those
4375796c8dcSSimon Schubert        with no equivalent).  */
4385796c8dcSSimon Schubert     enum {
4395796c8dcSSimon Schubert       OPT_SE = 10,
4405796c8dcSSimon Schubert       OPT_CD,
4415796c8dcSSimon Schubert       OPT_ANNOTATE,
4425796c8dcSSimon Schubert       OPT_STATISTICS,
4435796c8dcSSimon Schubert       OPT_TUI,
4445796c8dcSSimon Schubert       OPT_NOWINDOWS,
445*ef5ccd6cSJohn Marino       OPT_WINDOWS,
446*ef5ccd6cSJohn Marino       OPT_IX,
447*ef5ccd6cSJohn Marino       OPT_IEX
4485796c8dcSSimon Schubert     };
4495796c8dcSSimon Schubert     static struct option long_options[] =
4505796c8dcSSimon Schubert     {
4515796c8dcSSimon Schubert       {"tui", no_argument, 0, OPT_TUI},
4525796c8dcSSimon Schubert       {"xdb", no_argument, &xdb_commands, 1},
4535796c8dcSSimon Schubert       {"dbx", no_argument, &dbx_commands, 1},
4545796c8dcSSimon Schubert       {"readnow", no_argument, &readnow_symbol_files, 1},
4555796c8dcSSimon Schubert       {"r", no_argument, &readnow_symbol_files, 1},
4565796c8dcSSimon Schubert       {"quiet", no_argument, &quiet, 1},
4575796c8dcSSimon Schubert       {"q", no_argument, &quiet, 1},
4585796c8dcSSimon Schubert       {"silent", no_argument, &quiet, 1},
459*ef5ccd6cSJohn Marino       {"nh", no_argument, &inhibit_home_gdbinit, 1},
4605796c8dcSSimon Schubert       {"nx", no_argument, &inhibit_gdbinit, 1},
4615796c8dcSSimon Schubert       {"n", no_argument, &inhibit_gdbinit, 1},
4625796c8dcSSimon Schubert       {"batch-silent", no_argument, 0, 'B'},
463cf7f2e2dSJohn Marino       {"batch", no_argument, &batch_flag, 1},
4645796c8dcSSimon Schubert 
465c50c785cSJohn Marino     /* This is a synonym for "--annotate=1".  --annotate is now
466c50c785cSJohn Marino        preferred, but keep this here for a long time because people
467c50c785cSJohn Marino        will be running emacses which use --fullname.  */
4685796c8dcSSimon Schubert       {"fullname", no_argument, 0, 'f'},
4695796c8dcSSimon Schubert       {"f", no_argument, 0, 'f'},
4705796c8dcSSimon Schubert 
4715796c8dcSSimon Schubert       {"annotate", required_argument, 0, OPT_ANNOTATE},
4725796c8dcSSimon Schubert       {"help", no_argument, &print_help, 1},
4735796c8dcSSimon Schubert       {"se", required_argument, 0, OPT_SE},
4745796c8dcSSimon Schubert       {"symbols", required_argument, 0, 's'},
4755796c8dcSSimon Schubert       {"s", required_argument, 0, 's'},
4765796c8dcSSimon Schubert       {"exec", required_argument, 0, 'e'},
4775796c8dcSSimon Schubert       {"e", required_argument, 0, 'e'},
4785796c8dcSSimon Schubert       {"core", required_argument, 0, 'c'},
4795796c8dcSSimon Schubert       {"c", required_argument, 0, 'c'},
4805796c8dcSSimon Schubert       {"pid", required_argument, 0, 'p'},
4815796c8dcSSimon Schubert       {"p", required_argument, 0, 'p'},
4825796c8dcSSimon Schubert       {"command", required_argument, 0, 'x'},
4835796c8dcSSimon Schubert       {"eval-command", required_argument, 0, 'X'},
4845796c8dcSSimon Schubert       {"version", no_argument, &print_version, 1},
4855796c8dcSSimon Schubert       {"x", required_argument, 0, 'x'},
4865796c8dcSSimon Schubert       {"ex", required_argument, 0, 'X'},
487*ef5ccd6cSJohn Marino       {"init-command", required_argument, 0, OPT_IX},
488*ef5ccd6cSJohn Marino       {"init-eval-command", required_argument, 0, OPT_IEX},
489*ef5ccd6cSJohn Marino       {"ix", required_argument, 0, OPT_IX},
490*ef5ccd6cSJohn Marino       {"iex", required_argument, 0, OPT_IEX},
4915796c8dcSSimon Schubert #ifdef GDBTK
4925796c8dcSSimon Schubert       {"tclcommand", required_argument, 0, 'z'},
4935796c8dcSSimon Schubert       {"enable-external-editor", no_argument, 0, 'y'},
4945796c8dcSSimon Schubert       {"editor-command", required_argument, 0, 'w'},
4955796c8dcSSimon Schubert #endif
4965796c8dcSSimon Schubert       {"ui", required_argument, 0, 'i'},
4975796c8dcSSimon Schubert       {"interpreter", required_argument, 0, 'i'},
4985796c8dcSSimon Schubert       {"i", required_argument, 0, 'i'},
4995796c8dcSSimon Schubert       {"directory", required_argument, 0, 'd'},
5005796c8dcSSimon Schubert       {"d", required_argument, 0, 'd'},
501c50c785cSJohn Marino       {"data-directory", required_argument, 0, 'D'},
5025796c8dcSSimon Schubert       {"cd", required_argument, 0, OPT_CD},
5035796c8dcSSimon Schubert       {"tty", required_argument, 0, 't'},
5045796c8dcSSimon Schubert       {"baud", required_argument, 0, 'b'},
5055796c8dcSSimon Schubert       {"b", required_argument, 0, 'b'},
5065796c8dcSSimon Schubert       {"nw", no_argument, NULL, OPT_NOWINDOWS},
5075796c8dcSSimon Schubert       {"nowindows", no_argument, NULL, OPT_NOWINDOWS},
5085796c8dcSSimon Schubert       {"w", no_argument, NULL, OPT_WINDOWS},
5095796c8dcSSimon Schubert       {"windows", no_argument, NULL, OPT_WINDOWS},
5105796c8dcSSimon Schubert       {"statistics", no_argument, 0, OPT_STATISTICS},
5115796c8dcSSimon Schubert       {"write", no_argument, &write_files, 1},
5125796c8dcSSimon Schubert       {"args", no_argument, &set_args, 1},
5135796c8dcSSimon Schubert       {"l", required_argument, 0, 'l'},
5145796c8dcSSimon Schubert       {"return-child-result", no_argument, &return_child_result, 1},
5155796c8dcSSimon Schubert       {0, no_argument, 0, 0}
5165796c8dcSSimon Schubert     };
5175796c8dcSSimon Schubert 
5185796c8dcSSimon Schubert     while (1)
5195796c8dcSSimon Schubert       {
5205796c8dcSSimon Schubert 	int option_index;
5215796c8dcSSimon Schubert 
5225796c8dcSSimon Schubert 	c = getopt_long_only (argc, argv, "",
5235796c8dcSSimon Schubert 			      long_options, &option_index);
5245796c8dcSSimon Schubert 	if (c == EOF || set_args)
5255796c8dcSSimon Schubert 	  break;
5265796c8dcSSimon Schubert 
5275796c8dcSSimon Schubert 	/* Long option that takes an argument.  */
5285796c8dcSSimon Schubert 	if (c == 0 && long_options[option_index].flag == 0)
5295796c8dcSSimon Schubert 	  c = long_options[option_index].val;
5305796c8dcSSimon Schubert 
5315796c8dcSSimon Schubert 	switch (c)
5325796c8dcSSimon Schubert 	  {
5335796c8dcSSimon Schubert 	  case 0:
5345796c8dcSSimon Schubert 	    /* Long option that just sets a flag.  */
5355796c8dcSSimon Schubert 	    break;
5365796c8dcSSimon Schubert 	  case OPT_SE:
5375796c8dcSSimon Schubert 	    symarg = optarg;
5385796c8dcSSimon Schubert 	    execarg = optarg;
5395796c8dcSSimon Schubert 	    break;
5405796c8dcSSimon Schubert 	  case OPT_CD:
5415796c8dcSSimon Schubert 	    cdarg = optarg;
5425796c8dcSSimon Schubert 	    break;
5435796c8dcSSimon Schubert 	  case OPT_ANNOTATE:
5445796c8dcSSimon Schubert 	    /* FIXME: what if the syntax is wrong (e.g. not digits)?  */
5455796c8dcSSimon Schubert 	    annotation_level = atoi (optarg);
5465796c8dcSSimon Schubert 	    break;
5475796c8dcSSimon Schubert 	  case OPT_STATISTICS:
5485796c8dcSSimon Schubert 	    /* Enable the display of both time and space usage.  */
549cf7f2e2dSJohn Marino 	    set_display_time (1);
550cf7f2e2dSJohn Marino 	    set_display_space (1);
5515796c8dcSSimon Schubert 	    break;
5525796c8dcSSimon Schubert 	  case OPT_TUI:
5535796c8dcSSimon Schubert 	    /* --tui is equivalent to -i=tui.  */
5545796c8dcSSimon Schubert #ifdef TUI
5555796c8dcSSimon Schubert 	    xfree (interpreter_p);
5565796c8dcSSimon Schubert 	    interpreter_p = xstrdup (INTERP_TUI);
5575796c8dcSSimon Schubert #else
5585796c8dcSSimon Schubert 	    fprintf_unfiltered (gdb_stderr,
5595796c8dcSSimon Schubert 				_("%s: TUI mode is not supported\n"),
5605796c8dcSSimon Schubert 				argv[0]);
5615796c8dcSSimon Schubert 	    exit (1);
5625796c8dcSSimon Schubert #endif
5635796c8dcSSimon Schubert 	    break;
5645796c8dcSSimon Schubert 	  case OPT_WINDOWS:
5655796c8dcSSimon Schubert 	    /* FIXME: cagney/2003-03-01: Not sure if this option is
5665796c8dcSSimon Schubert                actually useful, and if it is, what it should do.  */
5675796c8dcSSimon Schubert #ifdef GDBTK
5685796c8dcSSimon Schubert 	    /* --windows is equivalent to -i=insight.  */
5695796c8dcSSimon Schubert 	    xfree (interpreter_p);
5705796c8dcSSimon Schubert 	    interpreter_p = xstrdup (INTERP_INSIGHT);
5715796c8dcSSimon Schubert #endif
5725796c8dcSSimon Schubert 	    use_windows = 1;
5735796c8dcSSimon Schubert 	    break;
5745796c8dcSSimon Schubert 	  case OPT_NOWINDOWS:
5755796c8dcSSimon Schubert 	    /* -nw is equivalent to -i=console.  */
5765796c8dcSSimon Schubert 	    xfree (interpreter_p);
5775796c8dcSSimon Schubert 	    interpreter_p = xstrdup (INTERP_CONSOLE);
5785796c8dcSSimon Schubert 	    use_windows = 0;
5795796c8dcSSimon Schubert 	    break;
5805796c8dcSSimon Schubert 	  case 'f':
5815796c8dcSSimon Schubert 	    annotation_level = 1;
582c50c785cSJohn Marino 	    /* We have probably been invoked from emacs.  Disable
583c50c785cSJohn Marino 	       window interface.  */
5845796c8dcSSimon Schubert 	    use_windows = 0;
5855796c8dcSSimon Schubert 	    break;
5865796c8dcSSimon Schubert 	  case 's':
5875796c8dcSSimon Schubert 	    symarg = optarg;
5885796c8dcSSimon Schubert 	    break;
5895796c8dcSSimon Schubert 	  case 'e':
5905796c8dcSSimon Schubert 	    execarg = optarg;
5915796c8dcSSimon Schubert 	    break;
5925796c8dcSSimon Schubert 	  case 'c':
5935796c8dcSSimon Schubert 	    corearg = optarg;
5945796c8dcSSimon Schubert 	    break;
5955796c8dcSSimon Schubert 	  case 'p':
5965796c8dcSSimon Schubert 	    pidarg = optarg;
5975796c8dcSSimon Schubert 	    break;
5985796c8dcSSimon Schubert 	  case 'x':
5995796c8dcSSimon Schubert 	    {
600*ef5ccd6cSJohn Marino 	      struct cmdarg cmdarg = { CMDARG_FILE, optarg };
601*ef5ccd6cSJohn Marino 
602*ef5ccd6cSJohn Marino 	      VEC_safe_push (cmdarg_s, cmdarg_vec, &cmdarg);
6035796c8dcSSimon Schubert 	    }
6045796c8dcSSimon Schubert 	    break;
6055796c8dcSSimon Schubert 	  case 'X':
6065796c8dcSSimon Schubert 	    {
607*ef5ccd6cSJohn Marino 	      struct cmdarg cmdarg = { CMDARG_COMMAND, optarg };
608*ef5ccd6cSJohn Marino 
609*ef5ccd6cSJohn Marino 	      VEC_safe_push (cmdarg_s, cmdarg_vec, &cmdarg);
610*ef5ccd6cSJohn Marino 	    }
611*ef5ccd6cSJohn Marino 	    break;
612*ef5ccd6cSJohn Marino 	  case OPT_IX:
613*ef5ccd6cSJohn Marino 	    {
614*ef5ccd6cSJohn Marino 	      struct cmdarg cmdarg = { CMDARG_INIT_FILE, optarg };
615*ef5ccd6cSJohn Marino 
616*ef5ccd6cSJohn Marino 	      VEC_safe_push (cmdarg_s, cmdarg_vec, &cmdarg);
617*ef5ccd6cSJohn Marino 	    }
618*ef5ccd6cSJohn Marino 	    break;
619*ef5ccd6cSJohn Marino 	  case OPT_IEX:
620*ef5ccd6cSJohn Marino 	    {
621*ef5ccd6cSJohn Marino 	      struct cmdarg cmdarg = { CMDARG_INIT_COMMAND, optarg };
622*ef5ccd6cSJohn Marino 
623*ef5ccd6cSJohn Marino 	      VEC_safe_push (cmdarg_s, cmdarg_vec, &cmdarg);
6245796c8dcSSimon Schubert 	    }
6255796c8dcSSimon Schubert 	    break;
6265796c8dcSSimon Schubert 	  case 'B':
627cf7f2e2dSJohn Marino 	    batch_flag = batch_silent = 1;
6285796c8dcSSimon Schubert 	    gdb_stdout = ui_file_new();
6295796c8dcSSimon Schubert 	    break;
630c50c785cSJohn Marino 	  case 'D':
631c50c785cSJohn Marino 	    xfree (gdb_datadir);
632c50c785cSJohn Marino 	    gdb_datadir = xstrdup (optarg);
633*ef5ccd6cSJohn Marino 	    gdb_datadir_provided = 1;
634c50c785cSJohn Marino 	    break;
6355796c8dcSSimon Schubert #ifdef GDBTK
6365796c8dcSSimon Schubert 	  case 'z':
6375796c8dcSSimon Schubert 	    {
6385796c8dcSSimon Schubert 	      extern int gdbtk_test (char *);
639c50c785cSJohn Marino 
6405796c8dcSSimon Schubert 	      if (!gdbtk_test (optarg))
6415796c8dcSSimon Schubert 		{
642c50c785cSJohn Marino 		  fprintf_unfiltered (gdb_stderr,
643c50c785cSJohn Marino 				      _("%s: unable to load "
644c50c785cSJohn Marino 					"tclcommand file \"%s\""),
6455796c8dcSSimon Schubert 				      argv[0], optarg);
6465796c8dcSSimon Schubert 		  exit (1);
6475796c8dcSSimon Schubert 		}
6485796c8dcSSimon Schubert 	      break;
6495796c8dcSSimon Schubert 	    }
6505796c8dcSSimon Schubert 	  case 'y':
6515796c8dcSSimon Schubert 	    /* Backwards compatibility only.  */
6525796c8dcSSimon Schubert 	    break;
6535796c8dcSSimon Schubert 	  case 'w':
6545796c8dcSSimon Schubert 	    {
655*ef5ccd6cSJohn Marino 	      /* Set the external editor commands when gdb is farming out files
656*ef5ccd6cSJohn Marino 		 to be edited by another program.  */
657*ef5ccd6cSJohn Marino 	      extern char *external_editor_command;
658*ef5ccd6cSJohn Marino 
6595796c8dcSSimon Schubert 	      external_editor_command = xstrdup (optarg);
6605796c8dcSSimon Schubert 	      break;
6615796c8dcSSimon Schubert 	    }
6625796c8dcSSimon Schubert #endif /* GDBTK */
6635796c8dcSSimon Schubert 	  case 'i':
6645796c8dcSSimon Schubert 	    xfree (interpreter_p);
6655796c8dcSSimon Schubert 	    interpreter_p = xstrdup (optarg);
6665796c8dcSSimon Schubert 	    break;
6675796c8dcSSimon Schubert 	  case 'd':
6685796c8dcSSimon Schubert 	    dirarg[ndir++] = optarg;
6695796c8dcSSimon Schubert 	    if (ndir >= dirsize)
6705796c8dcSSimon Schubert 	      {
6715796c8dcSSimon Schubert 		dirsize *= 2;
6725796c8dcSSimon Schubert 		dirarg = (char **) xrealloc ((char *) dirarg,
6735796c8dcSSimon Schubert 					     dirsize * sizeof (*dirarg));
6745796c8dcSSimon Schubert 	      }
6755796c8dcSSimon Schubert 	    break;
6765796c8dcSSimon Schubert 	  case 't':
6775796c8dcSSimon Schubert 	    ttyarg = optarg;
6785796c8dcSSimon Schubert 	    break;
6795796c8dcSSimon Schubert 	  case 'q':
6805796c8dcSSimon Schubert 	    quiet = 1;
6815796c8dcSSimon Schubert 	    break;
6825796c8dcSSimon Schubert 	  case 'b':
6835796c8dcSSimon Schubert 	    {
6845796c8dcSSimon Schubert 	      int i;
6855796c8dcSSimon Schubert 	      char *p;
6865796c8dcSSimon Schubert 
6875796c8dcSSimon Schubert 	      i = strtol (optarg, &p, 0);
6885796c8dcSSimon Schubert 	      if (i == 0 && p == optarg)
6895796c8dcSSimon Schubert 
6905796c8dcSSimon Schubert 		/* Don't use *_filtered or warning() (which relies on
6915796c8dcSSimon Schubert 		   current_target) until after initialize_all_files().  */
6925796c8dcSSimon Schubert 
6935796c8dcSSimon Schubert 		fprintf_unfiltered
6945796c8dcSSimon Schubert 		  (gdb_stderr,
6955796c8dcSSimon Schubert 		   _("warning: could not set baud rate to `%s'.\n"), optarg);
6965796c8dcSSimon Schubert 	      else
6975796c8dcSSimon Schubert 		baud_rate = i;
6985796c8dcSSimon Schubert 	    }
6995796c8dcSSimon Schubert             break;
7005796c8dcSSimon Schubert 	  case 'l':
7015796c8dcSSimon Schubert 	    {
7025796c8dcSSimon Schubert 	      int i;
7035796c8dcSSimon Schubert 	      char *p;
7045796c8dcSSimon Schubert 
7055796c8dcSSimon Schubert 	      i = strtol (optarg, &p, 0);
7065796c8dcSSimon Schubert 	      if (i == 0 && p == optarg)
7075796c8dcSSimon Schubert 
7085796c8dcSSimon Schubert 		/* Don't use *_filtered or warning() (which relies on
7095796c8dcSSimon Schubert 		   current_target) until after initialize_all_files().  */
7105796c8dcSSimon Schubert 
711c50c785cSJohn Marino 		fprintf_unfiltered (gdb_stderr,
712c50c785cSJohn Marino 				    _("warning: could not set "
713c50c785cSJohn Marino 				      "timeout limit to `%s'.\n"), optarg);
7145796c8dcSSimon Schubert 	      else
7155796c8dcSSimon Schubert 		remote_timeout = i;
7165796c8dcSSimon Schubert 	    }
7175796c8dcSSimon Schubert 	    break;
7185796c8dcSSimon Schubert 
7195796c8dcSSimon Schubert 	  case '?':
7205796c8dcSSimon Schubert 	    fprintf_unfiltered (gdb_stderr,
721c50c785cSJohn Marino 				_("Use `%s --help' for a "
722c50c785cSJohn Marino 				  "complete list of options.\n"),
7235796c8dcSSimon Schubert 				argv[0]);
7245796c8dcSSimon Schubert 	    exit (1);
7255796c8dcSSimon Schubert 	  }
7265796c8dcSSimon Schubert       }
7275796c8dcSSimon Schubert 
7285796c8dcSSimon Schubert     /* If --help or --version, disable window interface.  */
7295796c8dcSSimon Schubert     if (print_help || print_version)
7305796c8dcSSimon Schubert       {
7315796c8dcSSimon Schubert 	use_windows = 0;
7325796c8dcSSimon Schubert       }
7335796c8dcSSimon Schubert 
734cf7f2e2dSJohn Marino     if (batch_flag)
735cf7f2e2dSJohn Marino       quiet = 1;
736cf7f2e2dSJohn Marino   }
737cf7f2e2dSJohn Marino 
738cf7f2e2dSJohn Marino   /* Initialize all files.  Give the interpreter a chance to take
739cf7f2e2dSJohn Marino      control of the console via the deprecated_init_ui_hook ().  */
740*ef5ccd6cSJohn Marino   gdb_init (gdb_program_name);
741cf7f2e2dSJohn Marino 
742c50c785cSJohn Marino   /* Now that gdb_init has created the initial inferior, we're in
743c50c785cSJohn Marino      position to set args for that inferior.  */
7445796c8dcSSimon Schubert   if (set_args)
7455796c8dcSSimon Schubert     {
7465796c8dcSSimon Schubert       /* The remaining options are the command-line options for the
7475796c8dcSSimon Schubert 	 inferior.  The first one is the sym/exec file, and the rest
7485796c8dcSSimon Schubert 	 are arguments.  */
7495796c8dcSSimon Schubert       if (optind >= argc)
7505796c8dcSSimon Schubert 	{
7515796c8dcSSimon Schubert 	  fprintf_unfiltered (gdb_stderr,
752c50c785cSJohn Marino 			      _("%s: `--args' specified but "
753c50c785cSJohn Marino 				"no program specified\n"),
7545796c8dcSSimon Schubert 			      argv[0]);
7555796c8dcSSimon Schubert 	  exit (1);
7565796c8dcSSimon Schubert 	}
7575796c8dcSSimon Schubert       symarg = argv[optind];
7585796c8dcSSimon Schubert       execarg = argv[optind];
7595796c8dcSSimon Schubert       ++optind;
7605796c8dcSSimon Schubert       set_inferior_args_vector (argc - optind, &argv[optind]);
7615796c8dcSSimon Schubert     }
7625796c8dcSSimon Schubert   else
7635796c8dcSSimon Schubert     {
7645796c8dcSSimon Schubert       /* OK, that's all the options.  */
7655796c8dcSSimon Schubert 
7665796c8dcSSimon Schubert       /* The first argument, if specified, is the name of the
7675796c8dcSSimon Schubert 	 executable.  */
7685796c8dcSSimon Schubert       if (optind < argc)
7695796c8dcSSimon Schubert 	{
7705796c8dcSSimon Schubert 	  symarg = argv[optind];
7715796c8dcSSimon Schubert 	  execarg = argv[optind];
7725796c8dcSSimon Schubert 	  optind++;
7735796c8dcSSimon Schubert 	}
7745796c8dcSSimon Schubert 
7755796c8dcSSimon Schubert       /* If the user hasn't already specified a PID or the name of a
7765796c8dcSSimon Schubert 	 core file, then a second optional argument is allowed.  If
7775796c8dcSSimon Schubert 	 present, this argument should be interpreted as either a
7785796c8dcSSimon Schubert 	 PID or a core file, whichever works.  */
7795796c8dcSSimon Schubert       if (pidarg == NULL && corearg == NULL && optind < argc)
7805796c8dcSSimon Schubert 	{
7815796c8dcSSimon Schubert 	  pid_or_core_arg = argv[optind];
7825796c8dcSSimon Schubert 	  optind++;
7835796c8dcSSimon Schubert 	}
7845796c8dcSSimon Schubert 
7855796c8dcSSimon Schubert       /* Any argument left on the command line is unexpected and
7865796c8dcSSimon Schubert 	 will be ignored.  Inform the user.  */
7875796c8dcSSimon Schubert       if (optind < argc)
788c50c785cSJohn Marino 	fprintf_unfiltered (gdb_stderr,
789c50c785cSJohn Marino 			    _("Excess command line "
790c50c785cSJohn Marino 			      "arguments ignored. (%s%s)\n"),
7915796c8dcSSimon Schubert 			    argv[optind],
7925796c8dcSSimon Schubert 			    (optind == argc - 1) ? "" : " ...");
7935796c8dcSSimon Schubert     }
7945796c8dcSSimon Schubert 
795c50c785cSJohn Marino   /* Lookup gdbinit files.  Note that the gdbinit file name may be
796c50c785cSJohn Marino      overriden during file initialization, so get_init_files should be
797c50c785cSJohn Marino      called after gdb_init.  */
7985796c8dcSSimon Schubert   get_init_files (&system_gdbinit, &home_gdbinit, &local_gdbinit);
7995796c8dcSSimon Schubert 
8005796c8dcSSimon Schubert   /* Do these (and anything which might call wrap_here or *_filtered)
8015796c8dcSSimon Schubert      after initialize_all_files() but before the interpreter has been
8025796c8dcSSimon Schubert      installed.  Otherwize the help/version messages will be eaten by
8035796c8dcSSimon Schubert      the interpreter's output handler.  */
8045796c8dcSSimon Schubert 
8055796c8dcSSimon Schubert   if (print_version)
8065796c8dcSSimon Schubert     {
8075796c8dcSSimon Schubert       print_gdb_version (gdb_stdout);
8085796c8dcSSimon Schubert       wrap_here ("");
8095796c8dcSSimon Schubert       printf_filtered ("\n");
8105796c8dcSSimon Schubert       exit (0);
8115796c8dcSSimon Schubert     }
8125796c8dcSSimon Schubert 
8135796c8dcSSimon Schubert   if (print_help)
8145796c8dcSSimon Schubert     {
8155796c8dcSSimon Schubert       print_gdb_help (gdb_stdout);
8165796c8dcSSimon Schubert       fputs_unfiltered ("\n", gdb_stdout);
8175796c8dcSSimon Schubert       exit (0);
8185796c8dcSSimon Schubert     }
8195796c8dcSSimon Schubert 
8205796c8dcSSimon Schubert   /* FIXME: cagney/2003-02-03: The big hack (part 1 of 2) that lets
8215796c8dcSSimon Schubert      GDB retain the old MI1 interpreter startup behavior.  Output the
8225796c8dcSSimon Schubert      copyright message before the interpreter is installed.  That way
8235796c8dcSSimon Schubert      it isn't encapsulated in MI output.  */
8245796c8dcSSimon Schubert   if (!quiet && strcmp (interpreter_p, INTERP_MI1) == 0)
8255796c8dcSSimon Schubert     {
826c50c785cSJohn Marino       /* Print all the junk at the top, with trailing "..." if we are
827c50c785cSJohn Marino          about to read a symbol file (possibly slowly).  */
8285796c8dcSSimon Schubert       print_gdb_version (gdb_stdout);
8295796c8dcSSimon Schubert       if (symarg)
8305796c8dcSSimon Schubert 	printf_filtered ("..");
8315796c8dcSSimon Schubert       wrap_here ("");
8325796c8dcSSimon Schubert       printf_filtered ("\n");
833c50c785cSJohn Marino       gdb_flush (gdb_stdout);	/* Force to screen during slow
834c50c785cSJohn Marino 				   operations.  */
8355796c8dcSSimon Schubert     }
8365796c8dcSSimon Schubert 
8375796c8dcSSimon Schubert   /* Install the default UI.  All the interpreters should have had a
8385796c8dcSSimon Schubert      look at things by now.  Initialize the default interpreter.  */
8395796c8dcSSimon Schubert 
8405796c8dcSSimon Schubert   {
8415796c8dcSSimon Schubert     /* Find it.  */
8425796c8dcSSimon Schubert     struct interp *interp = interp_lookup (interpreter_p);
843cf7f2e2dSJohn Marino 
8445796c8dcSSimon Schubert     if (interp == NULL)
8455796c8dcSSimon Schubert       error (_("Interpreter `%s' unrecognized"), interpreter_p);
8465796c8dcSSimon Schubert     /* Install it.  */
8475796c8dcSSimon Schubert     if (!interp_set (interp, 1))
8485796c8dcSSimon Schubert       {
8495796c8dcSSimon Schubert         fprintf_unfiltered (gdb_stderr,
8505796c8dcSSimon Schubert 			    "Interpreter `%s' failed to initialize.\n",
8515796c8dcSSimon Schubert                             interpreter_p);
8525796c8dcSSimon Schubert         exit (1);
8535796c8dcSSimon Schubert       }
8545796c8dcSSimon Schubert   }
8555796c8dcSSimon Schubert 
8565796c8dcSSimon Schubert   /* FIXME: cagney/2003-02-03: The big hack (part 2 of 2) that lets
8575796c8dcSSimon Schubert      GDB retain the old MI1 interpreter startup behavior.  Output the
8585796c8dcSSimon Schubert      copyright message after the interpreter is installed when it is
8595796c8dcSSimon Schubert      any sane interpreter.  */
8605796c8dcSSimon Schubert   if (!quiet && !current_interp_named_p (INTERP_MI1))
8615796c8dcSSimon Schubert     {
862c50c785cSJohn Marino       /* Print all the junk at the top, with trailing "..." if we are
863c50c785cSJohn Marino          about to read a symbol file (possibly slowly).  */
8645796c8dcSSimon Schubert       print_gdb_version (gdb_stdout);
8655796c8dcSSimon Schubert       if (symarg)
8665796c8dcSSimon Schubert 	printf_filtered ("..");
8675796c8dcSSimon Schubert       wrap_here ("");
8685796c8dcSSimon Schubert       printf_filtered ("\n");
869c50c785cSJohn Marino       gdb_flush (gdb_stdout);	/* Force to screen during slow
870c50c785cSJohn Marino 				   operations.  */
8715796c8dcSSimon Schubert     }
8725796c8dcSSimon Schubert 
8735796c8dcSSimon Schubert   /* Set off error and warning messages with a blank line.  */
8745796c8dcSSimon Schubert   error_pre_print = "\n";
8755796c8dcSSimon Schubert   quit_pre_print = error_pre_print;
8765796c8dcSSimon Schubert   warning_pre_print = _("\nwarning: ");
8775796c8dcSSimon Schubert 
8785796c8dcSSimon Schubert   /* Read and execute the system-wide gdbinit file, if it exists.
8795796c8dcSSimon Schubert      This is done *before* all the command line arguments are
8805796c8dcSSimon Schubert      processed; it sets global parameters, which are independent of
8815796c8dcSSimon Schubert      what file you are debugging or what directory you are in.  */
8825796c8dcSSimon Schubert   if (system_gdbinit && !inhibit_gdbinit)
8835796c8dcSSimon Schubert     catch_command_errors (source_script, system_gdbinit, 0, RETURN_MASK_ALL);
8845796c8dcSSimon Schubert 
8855796c8dcSSimon Schubert   /* Read and execute $HOME/.gdbinit file, if it exists.  This is done
8865796c8dcSSimon Schubert      *before* all the command line arguments are processed; it sets
8875796c8dcSSimon Schubert      global parameters, which are independent of what file you are
8885796c8dcSSimon Schubert      debugging or what directory you are in.  */
8895796c8dcSSimon Schubert 
890*ef5ccd6cSJohn Marino   if (home_gdbinit && !inhibit_gdbinit && !inhibit_home_gdbinit)
8915796c8dcSSimon Schubert     catch_command_errors (source_script, home_gdbinit, 0, RETURN_MASK_ALL);
8925796c8dcSSimon Schubert 
893*ef5ccd6cSJohn Marino   /* Process '-ix' and '-iex' options early.  */
894*ef5ccd6cSJohn Marino   for (i = 0; VEC_iterate (cmdarg_s, cmdarg_vec, i, cmdarg_p); i++)
895*ef5ccd6cSJohn Marino     switch (cmdarg_p->type)
896*ef5ccd6cSJohn Marino     {
897*ef5ccd6cSJohn Marino       case CMDARG_INIT_FILE:
898*ef5ccd6cSJohn Marino         catch_command_errors (source_script, cmdarg_p->string,
899*ef5ccd6cSJohn Marino 			      !batch_flag, RETURN_MASK_ALL);
900*ef5ccd6cSJohn Marino 	break;
901*ef5ccd6cSJohn Marino       case CMDARG_INIT_COMMAND:
902*ef5ccd6cSJohn Marino         catch_command_errors (execute_command, cmdarg_p->string,
903*ef5ccd6cSJohn Marino 			      !batch_flag, RETURN_MASK_ALL);
904*ef5ccd6cSJohn Marino 	break;
905*ef5ccd6cSJohn Marino     }
906*ef5ccd6cSJohn Marino 
9075796c8dcSSimon Schubert   /* Now perform all the actions indicated by the arguments.  */
9085796c8dcSSimon Schubert   if (cdarg != NULL)
9095796c8dcSSimon Schubert     {
9105796c8dcSSimon Schubert       catch_command_errors (cd_command, cdarg, 0, RETURN_MASK_ALL);
9115796c8dcSSimon Schubert     }
9125796c8dcSSimon Schubert 
9135796c8dcSSimon Schubert   for (i = 0; i < ndir; i++)
9145796c8dcSSimon Schubert     catch_command_errors (directory_switch, dirarg[i], 0, RETURN_MASK_ALL);
9155796c8dcSSimon Schubert   xfree (dirarg);
9165796c8dcSSimon Schubert 
917cf7f2e2dSJohn Marino   /* Skip auto-loading section-specified scripts until we've sourced
918c50c785cSJohn Marino      local_gdbinit (which is often used to augment the source search
919c50c785cSJohn Marino      path).  */
920*ef5ccd6cSJohn Marino   save_auto_load = global_auto_load;
921*ef5ccd6cSJohn Marino   global_auto_load = 0;
922cf7f2e2dSJohn Marino 
9235796c8dcSSimon Schubert   if (execarg != NULL
9245796c8dcSSimon Schubert       && symarg != NULL
9255796c8dcSSimon Schubert       && strcmp (execarg, symarg) == 0)
9265796c8dcSSimon Schubert     {
9275796c8dcSSimon Schubert       /* The exec file and the symbol-file are the same.  If we can't
9285796c8dcSSimon Schubert          open it, better only print one error message.
9295796c8dcSSimon Schubert          catch_command_errors returns non-zero on success!  */
930c50c785cSJohn Marino       if (catch_command_errors (exec_file_attach, execarg,
931c50c785cSJohn Marino 				!batch_flag, RETURN_MASK_ALL))
932c50c785cSJohn Marino 	catch_command_errors (symbol_file_add_main, symarg,
933c50c785cSJohn Marino 			      !batch_flag, RETURN_MASK_ALL);
9345796c8dcSSimon Schubert     }
9355796c8dcSSimon Schubert   else
9365796c8dcSSimon Schubert     {
9375796c8dcSSimon Schubert       if (execarg != NULL)
938c50c785cSJohn Marino 	catch_command_errors (exec_file_attach, execarg,
939c50c785cSJohn Marino 			      !batch_flag, RETURN_MASK_ALL);
9405796c8dcSSimon Schubert       if (symarg != NULL)
941c50c785cSJohn Marino 	catch_command_errors (symbol_file_add_main, symarg,
942c50c785cSJohn Marino 			      !batch_flag, RETURN_MASK_ALL);
9435796c8dcSSimon Schubert     }
9445796c8dcSSimon Schubert 
9455796c8dcSSimon Schubert   if (corearg && pidarg)
946c50c785cSJohn Marino     error (_("Can't attach to process and specify "
947c50c785cSJohn Marino 	     "a core file at the same time."));
9485796c8dcSSimon Schubert 
9495796c8dcSSimon Schubert   if (corearg != NULL)
9505796c8dcSSimon Schubert     catch_command_errors (core_file_command, corearg,
951cf7f2e2dSJohn Marino 			  !batch_flag, RETURN_MASK_ALL);
9525796c8dcSSimon Schubert   else if (pidarg != NULL)
9535796c8dcSSimon Schubert     catch_command_errors (attach_command, pidarg,
954cf7f2e2dSJohn Marino 			  !batch_flag, RETURN_MASK_ALL);
9555796c8dcSSimon Schubert   else if (pid_or_core_arg)
9565796c8dcSSimon Schubert     {
9575796c8dcSSimon Schubert       /* The user specified 'gdb program pid' or gdb program core'.
9585796c8dcSSimon Schubert 	 If pid_or_core_arg's first character is a digit, try attach
9595796c8dcSSimon Schubert 	 first and then corefile.  Otherwise try just corefile.  */
9605796c8dcSSimon Schubert 
9615796c8dcSSimon Schubert       if (isdigit (pid_or_core_arg[0]))
9625796c8dcSSimon Schubert 	{
9635796c8dcSSimon Schubert 	  if (catch_command_errors (attach_command, pid_or_core_arg,
964cf7f2e2dSJohn Marino 				    !batch_flag, RETURN_MASK_ALL) == 0)
9655796c8dcSSimon Schubert 	    catch_command_errors (core_file_command, pid_or_core_arg,
966cf7f2e2dSJohn Marino 				  !batch_flag, RETURN_MASK_ALL);
9675796c8dcSSimon Schubert 	}
9685796c8dcSSimon Schubert       else /* Can't be a pid, better be a corefile.  */
9695796c8dcSSimon Schubert 	catch_command_errors (core_file_command, pid_or_core_arg,
970cf7f2e2dSJohn Marino 			      !batch_flag, RETURN_MASK_ALL);
9715796c8dcSSimon Schubert     }
9725796c8dcSSimon Schubert 
9735796c8dcSSimon Schubert   if (ttyarg != NULL)
974cf7f2e2dSJohn Marino     set_inferior_io_terminal (ttyarg);
9755796c8dcSSimon Schubert 
9765796c8dcSSimon Schubert   /* Error messages should no longer be distinguished with extra output.  */
9775796c8dcSSimon Schubert   error_pre_print = NULL;
9785796c8dcSSimon Schubert   quit_pre_print = NULL;
9795796c8dcSSimon Schubert   warning_pre_print = _("warning: ");
9805796c8dcSSimon Schubert 
9815796c8dcSSimon Schubert   /* Read the .gdbinit file in the current directory, *if* it isn't
9825796c8dcSSimon Schubert      the same as the $HOME/.gdbinit file (it should exist, also).  */
983*ef5ccd6cSJohn Marino   if (local_gdbinit)
984*ef5ccd6cSJohn Marino     {
985*ef5ccd6cSJohn Marino       auto_load_local_gdbinit_pathname = gdb_realpath (local_gdbinit);
986*ef5ccd6cSJohn Marino 
987*ef5ccd6cSJohn Marino       if (!inhibit_gdbinit && auto_load_local_gdbinit
988*ef5ccd6cSJohn Marino 	  && file_is_auto_load_safe (local_gdbinit,
989*ef5ccd6cSJohn Marino 				     _("auto-load: Loading .gdbinit "
990*ef5ccd6cSJohn Marino 				       "file \"%s\".\n"),
991*ef5ccd6cSJohn Marino 				     local_gdbinit))
992*ef5ccd6cSJohn Marino 	{
993*ef5ccd6cSJohn Marino 	  auto_load_local_gdbinit_loaded = 1;
994*ef5ccd6cSJohn Marino 
995*ef5ccd6cSJohn Marino 	  catch_command_errors (source_script, local_gdbinit, 0,
996*ef5ccd6cSJohn Marino 				RETURN_MASK_ALL);
997*ef5ccd6cSJohn Marino 	}
998*ef5ccd6cSJohn Marino     }
9995796c8dcSSimon Schubert 
1000cf7f2e2dSJohn Marino   /* Now that all .gdbinit's have been read and all -d options have been
1001cf7f2e2dSJohn Marino      processed, we can read any scripts mentioned in SYMARG.
1002cf7f2e2dSJohn Marino      We wait until now because it is common to add to the source search
1003cf7f2e2dSJohn Marino      path in local_gdbinit.  */
1004*ef5ccd6cSJohn Marino   global_auto_load = save_auto_load;
1005c50c785cSJohn Marino   ALL_OBJFILES (objfile)
1006c50c785cSJohn Marino     load_auto_scripts_for_objfile (objfile);
1007cf7f2e2dSJohn Marino 
1008*ef5ccd6cSJohn Marino   /* Process '-x' and '-ex' options.  */
1009*ef5ccd6cSJohn Marino   for (i = 0; VEC_iterate (cmdarg_s, cmdarg_vec, i, cmdarg_p); i++)
1010*ef5ccd6cSJohn Marino     switch (cmdarg_p->type)
10115796c8dcSSimon Schubert     {
1012*ef5ccd6cSJohn Marino       case CMDARG_FILE:
1013*ef5ccd6cSJohn Marino         catch_command_errors (source_script, cmdarg_p->string,
1014cf7f2e2dSJohn Marino 			      !batch_flag, RETURN_MASK_ALL);
1015*ef5ccd6cSJohn Marino 	break;
1016*ef5ccd6cSJohn Marino       case CMDARG_COMMAND:
1017*ef5ccd6cSJohn Marino         catch_command_errors (execute_command, cmdarg_p->string,
1018cf7f2e2dSJohn Marino 			      !batch_flag, RETURN_MASK_ALL);
1019*ef5ccd6cSJohn Marino 	break;
10205796c8dcSSimon Schubert     }
10215796c8dcSSimon Schubert 
1022c50c785cSJohn Marino   /* Read in the old history after all the command files have been
1023c50c785cSJohn Marino      read.  */
10245796c8dcSSimon Schubert   init_history ();
10255796c8dcSSimon Schubert 
1026cf7f2e2dSJohn Marino   if (batch_flag)
10275796c8dcSSimon Schubert     {
10285796c8dcSSimon Schubert       /* We have hit the end of the batch file.  */
10295796c8dcSSimon Schubert       quit_force (NULL, 0);
10305796c8dcSSimon Schubert     }
10315796c8dcSSimon Schubert 
10325796c8dcSSimon Schubert   /* Show time and/or space usage.  */
1033cf7f2e2dSJohn Marino   do_cleanups (pre_stat_chain);
10345796c8dcSSimon Schubert 
10355796c8dcSSimon Schubert   /* NOTE: cagney/1999-11-07: There is probably no reason for not
10365796c8dcSSimon Schubert      moving this loop and the code found in captured_command_loop()
10375796c8dcSSimon Schubert      into the command_loop() proper.  The main thing holding back that
10385796c8dcSSimon Schubert      change - SET_TOP_LEVEL() - has been eliminated.  */
10395796c8dcSSimon Schubert   while (1)
10405796c8dcSSimon Schubert     {
10415796c8dcSSimon Schubert       catch_errors (captured_command_loop, 0, "", RETURN_MASK_ALL);
10425796c8dcSSimon Schubert     }
10435796c8dcSSimon Schubert   /* No exit -- exit is through quit_command.  */
10445796c8dcSSimon Schubert }
10455796c8dcSSimon Schubert 
10465796c8dcSSimon Schubert int
10475796c8dcSSimon Schubert gdb_main (struct captured_main_args *args)
10485796c8dcSSimon Schubert {
10495796c8dcSSimon Schubert   use_windows = args->use_windows;
10505796c8dcSSimon Schubert   catch_errors (captured_main, args, "", RETURN_MASK_ALL);
10515796c8dcSSimon Schubert   /* The only way to end up here is by an error (normal exit is
10525796c8dcSSimon Schubert      handled by quit_force()), hence always return an error status.  */
10535796c8dcSSimon Schubert   return 1;
10545796c8dcSSimon Schubert }
10555796c8dcSSimon Schubert 
10565796c8dcSSimon Schubert 
10575796c8dcSSimon Schubert /* Don't use *_filtered for printing help.  We don't want to prompt
10585796c8dcSSimon Schubert    for continue no matter how small the screen or how much we're going
10595796c8dcSSimon Schubert    to print.  */
10605796c8dcSSimon Schubert 
10615796c8dcSSimon Schubert static void
10625796c8dcSSimon Schubert print_gdb_help (struct ui_file *stream)
10635796c8dcSSimon Schubert {
10645796c8dcSSimon Schubert   char *system_gdbinit;
10655796c8dcSSimon Schubert   char *home_gdbinit;
10665796c8dcSSimon Schubert   char *local_gdbinit;
10675796c8dcSSimon Schubert 
10685796c8dcSSimon Schubert   get_init_files (&system_gdbinit, &home_gdbinit, &local_gdbinit);
10695796c8dcSSimon Schubert 
10705796c8dcSSimon Schubert   fputs_unfiltered (_("\
10715796c8dcSSimon Schubert This is the GNU debugger.  Usage:\n\n\
10725796c8dcSSimon Schubert     gdb [options] [executable-file [core-file or process-id]]\n\
10735796c8dcSSimon Schubert     gdb [options] --args executable-file [inferior-arguments ...]\n\n\
10745796c8dcSSimon Schubert Options:\n\n\
10755796c8dcSSimon Schubert "), stream);
10765796c8dcSSimon Schubert   fputs_unfiltered (_("\
10775796c8dcSSimon Schubert   --args             Arguments after executable-file are passed to inferior\n\
10785796c8dcSSimon Schubert "), stream);
10795796c8dcSSimon Schubert   fputs_unfiltered (_("\
10805796c8dcSSimon Schubert   -b BAUDRATE        Set serial port baud rate used for remote debugging.\n\
10815796c8dcSSimon Schubert   --batch            Exit after processing options.\n\
10825796c8dcSSimon Schubert   --batch-silent     As for --batch, but suppress all gdb stdout output.\n\
10835796c8dcSSimon Schubert   --return-child-result\n\
10845796c8dcSSimon Schubert                      GDB exit code will be the child's exit code.\n\
10855796c8dcSSimon Schubert   --cd=DIR           Change current directory to DIR.\n\
10865796c8dcSSimon Schubert   --command=FILE, -x Execute GDB commands from FILE.\n\
10875796c8dcSSimon Schubert   --eval-command=COMMAND, -ex\n\
10885796c8dcSSimon Schubert                      Execute a single GDB command.\n\
10895796c8dcSSimon Schubert                      May be used multiple times and in conjunction\n\
10905796c8dcSSimon Schubert                      with --command.\n\
1091*ef5ccd6cSJohn Marino   --init-command=FILE, -ix Like -x but execute it before loading inferior.\n\
1092*ef5ccd6cSJohn Marino   --init-eval-command=COMMAND, -iex Like -ex but before loading inferior.\n\
10935796c8dcSSimon Schubert   --core=COREFILE    Analyze the core dump COREFILE.\n\
10945796c8dcSSimon Schubert   --pid=PID          Attach to running process PID.\n\
10955796c8dcSSimon Schubert "), stream);
10965796c8dcSSimon Schubert   fputs_unfiltered (_("\
10975796c8dcSSimon Schubert   --dbx              DBX compatibility mode.\n\
10985796c8dcSSimon Schubert   --directory=DIR    Search for source files in DIR.\n\
10995796c8dcSSimon Schubert   --exec=EXECFILE    Use EXECFILE as the executable.\n\
11005796c8dcSSimon Schubert   --fullname         Output information used by emacs-GDB interface.\n\
11015796c8dcSSimon Schubert   --help             Print this message.\n\
11025796c8dcSSimon Schubert "), stream);
11035796c8dcSSimon Schubert   fputs_unfiltered (_("\
11045796c8dcSSimon Schubert   --interpreter=INTERP\n\
11055796c8dcSSimon Schubert                      Select a specific interpreter / user interface\n\
11065796c8dcSSimon Schubert "), stream);
11075796c8dcSSimon Schubert   fputs_unfiltered (_("\
11085796c8dcSSimon Schubert   -l TIMEOUT         Set timeout in seconds for remote debugging.\n\
11095796c8dcSSimon Schubert   --nw		     Do not use a window interface.\n\
1110*ef5ccd6cSJohn Marino   --nx               Do not read any "), stream);
11115796c8dcSSimon Schubert   fputs_unfiltered (gdbinit, stream);
1112*ef5ccd6cSJohn Marino   fputs_unfiltered (_(" files.\n\
1113*ef5ccd6cSJohn Marino   --nh               Do not read "), stream);
1114*ef5ccd6cSJohn Marino   fputs_unfiltered (gdbinit, stream);
1115*ef5ccd6cSJohn Marino   fputs_unfiltered (_(" file from home directory.\n\
11165796c8dcSSimon Schubert   --quiet            Do not print version number on startup.\n\
11175796c8dcSSimon Schubert   --readnow          Fully read symbol files on first access.\n\
11185796c8dcSSimon Schubert "), stream);
11195796c8dcSSimon Schubert   fputs_unfiltered (_("\
11205796c8dcSSimon Schubert   --se=FILE          Use FILE as symbol file and executable file.\n\
11215796c8dcSSimon Schubert   --symbols=SYMFILE  Read symbols from SYMFILE.\n\
11225796c8dcSSimon Schubert   --tty=TTY          Use TTY for input/output by the program being debugged.\n\
11235796c8dcSSimon Schubert "), stream);
11245796c8dcSSimon Schubert #if defined(TUI)
11255796c8dcSSimon Schubert   fputs_unfiltered (_("\
11265796c8dcSSimon Schubert   --tui              Use a terminal user interface.\n\
11275796c8dcSSimon Schubert "), stream);
11285796c8dcSSimon Schubert #endif
11295796c8dcSSimon Schubert   fputs_unfiltered (_("\
11305796c8dcSSimon Schubert   --version          Print version information and then exit.\n\
11315796c8dcSSimon Schubert   -w                 Use a window interface.\n\
11325796c8dcSSimon Schubert   --write            Set writing into executable and core files.\n\
11335796c8dcSSimon Schubert   --xdb              XDB compatibility mode.\n\
11345796c8dcSSimon Schubert "), stream);
11355796c8dcSSimon Schubert   fputs_unfiltered (_("\n\
11365796c8dcSSimon Schubert At startup, GDB reads the following init files and executes their commands:\n\
11375796c8dcSSimon Schubert "), stream);
11385796c8dcSSimon Schubert   if (system_gdbinit)
11395796c8dcSSimon Schubert     fprintf_unfiltered (stream, _("\
11405796c8dcSSimon Schubert    * system-wide init file: %s\n\
11415796c8dcSSimon Schubert "), system_gdbinit);
11425796c8dcSSimon Schubert   if (home_gdbinit)
11435796c8dcSSimon Schubert     fprintf_unfiltered (stream, _("\
11445796c8dcSSimon Schubert    * user-specific init file: %s\n\
11455796c8dcSSimon Schubert "), home_gdbinit);
11465796c8dcSSimon Schubert   if (local_gdbinit)
11475796c8dcSSimon Schubert     fprintf_unfiltered (stream, _("\
1148*ef5ccd6cSJohn Marino    * local init file (see also 'set auto-load local-gdbinit'): ./%s\n\
11495796c8dcSSimon Schubert "), local_gdbinit);
11505796c8dcSSimon Schubert   fputs_unfiltered (_("\n\
11515796c8dcSSimon Schubert For more information, type \"help\" from within GDB, or consult the\n\
11525796c8dcSSimon Schubert GDB manual (available as on-line info or a printed manual).\n\
11535796c8dcSSimon Schubert "), stream);
11545796c8dcSSimon Schubert   if (REPORT_BUGS_TO[0] && stream == gdb_stdout)
11555796c8dcSSimon Schubert     fprintf_unfiltered (stream, _("\
11565796c8dcSSimon Schubert Report bugs to \"%s\".\n\
11575796c8dcSSimon Schubert "), REPORT_BUGS_TO);
11585796c8dcSSimon Schubert }
1159