2003-02-04 Andrew Cagney <ac131313@redhat.com>
[external/binutils.git] / gdb / main.c
1 /* Top level stuff for GDB, the GNU debugger.
2    Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
3    1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
4    Free Software Foundation, Inc.
5
6    This file is part of GDB.
7
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 2 of the License, or
11    (at your option) any later version.
12
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 59 Temple Place - Suite 330,
21    Boston, MA 02111-1307, USA.  */
22
23 #include "defs.h"
24 #include "top.h"
25 #include "target.h"
26 #include "inferior.h"
27 #include "symfile.h"
28 #include "gdbcore.h"
29
30 #include "getopt.h"
31
32 #include <sys/types.h>
33 #include "gdb_stat.h"
34 #include <ctype.h>
35
36 #include "gdb_string.h"
37 #include "event-loop.h"
38 #include "ui-out.h"
39
40 #include "main.h"
41
42 /* If nonzero, display time usage both at startup and for each command.  */
43
44 int display_time;
45
46 /* If nonzero, display space usage both at startup and for each command.  */
47
48 int display_space;
49
50 /* Whether this is the async version or not.  The async version is
51    invoked on the command line with the -nw --async options.  In this
52    version, the usual command_loop is substituted by and event loop which
53    processes UI events asynchronously. */
54 int event_loop_p = 1;
55
56 /* Has an interpreter been specified and if so, which. */
57 char *interpreter_p;
58
59 /* Whether this is the command line version or not */
60 int tui_version = 0;
61
62 /* Whether xdb commands will be handled */
63 int xdb_commands = 0;
64
65 /* Whether dbx commands will be handled */
66 int dbx_commands = 0;
67
68 /* System root path, used to find libraries etc.  */
69 char *gdb_sysroot = 0;
70
71 struct ui_file *gdb_stdout;
72 struct ui_file *gdb_stderr;
73 struct ui_file *gdb_stdlog;
74 struct ui_file *gdb_stdtarg;
75
76 /* Used to initialize error() - defined in utils.c */
77
78 extern void error_init (void);
79
80 /* Whether to enable writing into executable and core files */
81 extern int write_files;
82
83 static void print_gdb_help (struct ui_file *);
84
85 /* These two are used to set the external editor commands when gdb is farming
86    out files to be edited by another program. */
87
88 extern char *external_editor_command;
89
90 /* Call command_loop.  If it happens to return, pass that through as a
91    non-zero return status. */
92
93 static int
94 captured_command_loop (void *data)
95 {
96   if (command_loop_hook == NULL)
97     command_loop ();
98   else
99     command_loop_hook ();
100   /* FIXME: cagney/1999-11-05: A correct command_loop() implementaton
101      would clean things up (restoring the cleanup chain) to the state
102      they were just prior to the call.  Technically, this means that
103      the do_cleanups() below is redundant.  Unfortunately, many FUNCs
104      are not that well behaved.  do_cleanups should either be replaced
105      with a do_cleanups call (to cover the problem) or an assertion
106      check to detect bad FUNCs code. */
107   do_cleanups (ALL_CLEANUPS);
108   /* If the command_loop returned, normally (rather than threw an
109      error) we try to quit. If the quit is aborted, catch_errors()
110      which called this catch the signal and restart the command
111      loop. */
112   quit_command (NULL, instream == stdin);
113   return 1;
114 }
115
116 static int
117 captured_main (void *data)
118 {
119   struct captured_main_args *context = data;
120   int argc = context->argc;
121   char **argv = context->argv;
122   int count;
123   static int quiet = 0;
124   static int batch = 0;
125   static int set_args = 0;
126
127   /* Pointers to various arguments from command line.  */
128   char *symarg = NULL;
129   char *execarg = NULL;
130   char *corearg = NULL;
131   char *cdarg = NULL;
132   char *ttyarg = NULL;
133
134   /* These are static so that we can take their address in an initializer.  */
135   static int print_help;
136   static int print_version;
137
138   /* Pointers to all arguments of --command option.  */
139   char **cmdarg;
140   /* Allocated size of cmdarg.  */
141   int cmdsize;
142   /* Number of elements of cmdarg used.  */
143   int ncmd;
144
145   /* Indices of all arguments of --directory option.  */
146   char **dirarg;
147   /* Allocated size.  */
148   int dirsize;
149   /* Number of elements used.  */
150   int ndir;
151
152   struct stat homebuf, cwdbuf;
153   char *homedir, *homeinit;
154
155   register int i;
156
157   long time_at_startup = get_run_time ();
158
159 #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
160   setlocale (LC_MESSAGES, "");
161 #endif
162 #if defined (HAVE_SETLOCALE)
163   setlocale (LC_CTYPE, "");
164 #endif
165   bindtextdomain (PACKAGE, LOCALEDIR);
166   textdomain (PACKAGE);
167
168   START_PROGRESS (argv[0], 0);
169
170   /* This needs to happen before the first use of malloc.  */
171   init_malloc (NULL);
172
173 #if defined (ALIGN_STACK_ON_STARTUP)
174   i = (int) &count & 0x3;
175   if (i != 0)
176     alloca (4 - i);
177 #endif
178
179   cmdsize = 1;
180   cmdarg = (char **) xmalloc (cmdsize * sizeof (*cmdarg));
181   ncmd = 0;
182   dirsize = 1;
183   dirarg = (char **) xmalloc (dirsize * sizeof (*dirarg));
184   ndir = 0;
185
186   quit_flag = 0;
187   line = (char *) xmalloc (linesize);
188   line[0] = '\0';               /* Terminate saved (now empty) cmd line */
189   instream = stdin;
190
191   getcwd (gdb_dirbuf, sizeof (gdb_dirbuf));
192   current_directory = gdb_dirbuf;
193
194   gdb_stdout = stdio_fileopen (stdout);
195   gdb_stderr = stdio_fileopen (stderr);
196   gdb_stdlog = gdb_stderr;      /* for moment */
197   gdb_stdtarg = gdb_stderr;     /* for moment */
198
199   /* initialize error() */
200   error_init ();
201
202   /* Set the sysroot path.  */
203 #ifdef TARGET_SYSTEM_ROOT_RELOCATABLE
204   gdb_sysroot = make_relative_prefix (argv[0], BINDIR, TARGET_SYSTEM_ROOT);
205   if (gdb_sysroot)
206     {
207       struct stat s;
208       int res = 0;
209
210       if (stat (gdb_sysroot, &s) == 0)
211         if (S_ISDIR (s.st_mode))
212           res = 1;
213
214       if (res == 0)
215         {
216           xfree (gdb_sysroot);
217           gdb_sysroot = TARGET_SYSTEM_ROOT;
218         }
219     }
220   else
221     gdb_sysroot = TARGET_SYSTEM_ROOT;
222 #else
223 #if defined (TARGET_SYSTEM_ROOT)
224   gdb_sysroot = TARGET_SYSTEM_ROOT;
225 #else
226   gdb_sysroot = "";
227 #endif
228 #endif
229
230   /* Parse arguments and options.  */
231   {
232     int c;
233     /* When var field is 0, use flag field to record the equivalent
234        short option (or arbitrary numbers starting at 10 for those
235        with no equivalent).  */
236     static struct option long_options[] =
237     {
238       {"async", no_argument, &event_loop_p, 1},
239       {"noasync", no_argument, &event_loop_p, 0},
240 #if defined(TUI)
241       {"tui", no_argument, &tui_version, 1},
242 #endif
243       {"xdb", no_argument, &xdb_commands, 1},
244       {"dbx", no_argument, &dbx_commands, 1},
245       {"readnow", no_argument, &readnow_symbol_files, 1},
246       {"r", no_argument, &readnow_symbol_files, 1},
247       {"mapped", no_argument, &mapped_symbol_files, 1},
248       {"m", no_argument, &mapped_symbol_files, 1},
249       {"quiet", no_argument, &quiet, 1},
250       {"q", no_argument, &quiet, 1},
251       {"silent", no_argument, &quiet, 1},
252       {"nx", no_argument, &inhibit_gdbinit, 1},
253       {"n", no_argument, &inhibit_gdbinit, 1},
254       {"batch", no_argument, &batch, 1},
255       {"epoch", no_argument, &epoch_interface, 1},
256
257     /* This is a synonym for "--annotate=1".  --annotate is now preferred,
258        but keep this here for a long time because people will be running
259        emacses which use --fullname.  */
260       {"fullname", no_argument, 0, 'f'},
261       {"f", no_argument, 0, 'f'},
262
263       {"annotate", required_argument, 0, 12},
264       {"help", no_argument, &print_help, 1},
265       {"se", required_argument, 0, 10},
266       {"symbols", required_argument, 0, 's'},
267       {"s", required_argument, 0, 's'},
268       {"exec", required_argument, 0, 'e'},
269       {"e", required_argument, 0, 'e'},
270       {"core", required_argument, 0, 'c'},
271       {"c", required_argument, 0, 'c'},
272       {"pid", required_argument, 0, 'p'},
273       {"p", required_argument, 0, 'p'},
274       {"command", required_argument, 0, 'x'},
275       {"version", no_argument, &print_version, 1},
276       {"x", required_argument, 0, 'x'},
277 #ifdef GDBTK
278       {"tclcommand", required_argument, 0, 'z'},
279       {"enable-external-editor", no_argument, 0, 'y'},
280       {"editor-command", required_argument, 0, 'w'},
281 #endif
282       {"ui", required_argument, 0, 'i'},
283       {"interpreter", required_argument, 0, 'i'},
284       {"i", required_argument, 0, 'i'},
285       {"directory", required_argument, 0, 'd'},
286       {"d", required_argument, 0, 'd'},
287       {"cd", required_argument, 0, 11},
288       {"tty", required_argument, 0, 't'},
289       {"baud", required_argument, 0, 'b'},
290       {"b", required_argument, 0, 'b'},
291       {"nw", no_argument, &use_windows, 0},
292       {"nowindows", no_argument, &use_windows, 0},
293       {"w", no_argument, &use_windows, 1},
294       {"windows", no_argument, &use_windows, 1},
295       {"statistics", no_argument, 0, 13},
296       {"write", no_argument, &write_files, 1},
297       {"args", no_argument, &set_args, 1},
298       {0, no_argument, 0, 0}
299     };
300
301     while (1)
302       {
303         int option_index;
304
305         c = getopt_long_only (argc, argv, "",
306                               long_options, &option_index);
307         if (c == EOF || set_args)
308           break;
309
310         /* Long option that takes an argument.  */
311         if (c == 0 && long_options[option_index].flag == 0)
312           c = long_options[option_index].val;
313
314         switch (c)
315           {
316           case 0:
317             /* Long option that just sets a flag.  */
318             break;
319           case 10:
320             symarg = optarg;
321             execarg = optarg;
322             break;
323           case 11:
324             cdarg = optarg;
325             break;
326           case 12:
327             /* FIXME: what if the syntax is wrong (e.g. not digits)?  */
328             annotation_level = atoi (optarg);
329             break;
330           case 13:
331             /* Enable the display of both time and space usage.  */
332             display_time = 1;
333             display_space = 1;
334             break;
335           case 'f':
336             annotation_level = 1;
337 /* We have probably been invoked from emacs.  Disable window interface.  */
338             use_windows = 0;
339             break;
340           case 's':
341             symarg = optarg;
342             break;
343           case 'e':
344             execarg = optarg;
345             break;
346           case 'c':
347             corearg = optarg;
348             break;
349           case 'p':
350             /* "corearg" is shared by "--core" and "--pid" */
351             corearg = optarg;
352             break;
353           case 'x':
354             cmdarg[ncmd++] = optarg;
355             if (ncmd >= cmdsize)
356               {
357                 cmdsize *= 2;
358                 cmdarg = (char **) xrealloc ((char *) cmdarg,
359                                              cmdsize * sizeof (*cmdarg));
360               }
361             break;
362 #ifdef GDBTK
363           case 'z':
364             {
365 extern int gdbtk_test (char *);
366               if (!gdbtk_test (optarg))
367                 {
368                   fprintf_unfiltered (gdb_stderr, _("%s: unable to load tclcommand file \"%s\""),
369                                       argv[0], optarg);
370                   exit (1);
371                 }
372               break;
373             }
374           case 'y':
375             /* Backwards compatibility only.  */
376             break;
377           case 'w':
378             {
379               external_editor_command = xstrdup (optarg);
380               break;
381             }
382 #endif /* GDBTK */
383           case 'i':
384             interpreter_p = optarg;
385             break;
386           case 'd':
387             dirarg[ndir++] = optarg;
388             if (ndir >= dirsize)
389               {
390                 dirsize *= 2;
391                 dirarg = (char **) xrealloc ((char *) dirarg,
392                                              dirsize * sizeof (*dirarg));
393               }
394             break;
395           case 't':
396             ttyarg = optarg;
397             break;
398           case 'q':
399             quiet = 1;
400             break;
401           case 'b':
402             {
403               int i;
404               char *p;
405
406               i = strtol (optarg, &p, 0);
407               if (i == 0 && p == optarg)
408
409                 /* Don't use *_filtered or warning() (which relies on
410                    current_target) until after initialize_all_files(). */
411
412                 fprintf_unfiltered
413                   (gdb_stderr,
414                    _("warning: could not set baud rate to `%s'.\n"), optarg);
415               else
416                 baud_rate = i;
417             }
418             break;
419           case 'l':
420             {
421               int i;
422               char *p;
423
424               i = strtol (optarg, &p, 0);
425               if (i == 0 && p == optarg)
426
427                 /* Don't use *_filtered or warning() (which relies on
428                    current_target) until after initialize_all_files(). */
429
430                 fprintf_unfiltered
431                   (gdb_stderr,
432                  _("warning: could not set timeout limit to `%s'.\n"), optarg);
433               else
434                 remote_timeout = i;
435             }
436             break;
437
438           case '?':
439             fprintf_unfiltered (gdb_stderr,
440                         _("Use `%s --help' for a complete list of options.\n"),
441                                 argv[0]);
442             exit (1);
443           }
444       }
445
446     /* If --help or --version, disable window interface.  */
447     if (print_help || print_version)
448       {
449         use_windows = 0;
450 #ifdef TUI
451         /* Disable the TUI as well.  */
452         tui_version = 0;
453 #endif
454       }
455
456 #ifdef TUI
457     /* An explicit --tui flag overrides the default UI, which is the
458        window system.  */
459     if (tui_version)
460       use_windows = 0;
461 #endif
462
463     if (set_args)
464       {
465         /* The remaining options are the command-line options for the
466            inferior.  The first one is the sym/exec file, and the rest
467            are arguments.  */
468         if (optind >= argc)
469           {
470             fprintf_unfiltered (gdb_stderr,
471                                 _("%s: `--args' specified but no program specified\n"),
472                                 argv[0]);
473             exit (1);
474           }
475         symarg = argv[optind];
476         execarg = argv[optind];
477         ++optind;
478         set_inferior_args_vector (argc - optind, &argv[optind]);
479       }
480     else
481       {
482         /* OK, that's all the options.  The other arguments are filenames.  */
483         count = 0;
484         for (; optind < argc; optind++)
485           switch (++count)
486             {
487             case 1:
488               symarg = argv[optind];
489               execarg = argv[optind];
490               break;
491             case 2:
492               /* The documentation says this can be a "ProcID" as well. 
493                  We will try it as both a corefile and a pid.  */
494               corearg = argv[optind];
495               break;
496             case 3:
497               fprintf_unfiltered (gdb_stderr,
498                                   _("Excess command line arguments ignored. (%s%s)\n"),
499                                   argv[optind], (optind == argc - 1) ? "" : " ...");
500               break;
501             }
502       }
503     if (batch)
504       quiet = 1;
505   }
506
507   /* Initialize all files.  Give the interpreter a chance to take
508      control of the console via the init_ui_hook()) */
509   gdb_init (argv[0]);
510
511   /* Do these (and anything which might call wrap_here or *_filtered)
512      after initialize_all_files.  */
513   if (print_version)
514     {
515       print_gdb_version (gdb_stdout);
516       wrap_here ("");
517       printf_filtered ("\n");
518       exit (0);
519     }
520
521   if (print_help)
522     {
523       print_gdb_help (gdb_stdout);
524       fputs_unfiltered ("\n", gdb_stdout);
525       exit (0);
526     }
527
528   if (!quiet)
529     {
530       /* Print all the junk at the top, with trailing "..." if we are about
531          to read a symbol file (possibly slowly).  */
532       print_gdb_version (gdb_stdout);
533       if (symarg)
534         printf_filtered ("..");
535       wrap_here ("");
536       gdb_flush (gdb_stdout);   /* Force to screen during slow operations */
537     }
538
539   error_pre_print = "\n\n";
540   quit_pre_print = error_pre_print;
541
542   /* We may get more than one warning, don't double space all of them... */
543   warning_pre_print = _("\nwarning: ");
544
545   /* Read and execute $HOME/.gdbinit file, if it exists.  This is done
546      *before* all the command line arguments are processed; it sets
547      global parameters, which are independent of what file you are
548      debugging or what directory you are in.  */
549   homedir = getenv ("HOME");
550   if (homedir)
551     {
552       homeinit = (char *) alloca (strlen (homedir) +
553                                   strlen (gdbinit) + 10);
554       strcpy (homeinit, homedir);
555       strcat (homeinit, "/");
556       strcat (homeinit, gdbinit);
557
558       if (!inhibit_gdbinit)
559         {
560           catch_command_errors (source_command, homeinit, 0, RETURN_MASK_ALL);
561         }
562
563       /* Do stats; no need to do them elsewhere since we'll only
564          need them if homedir is set.  Make sure that they are
565          zero in case one of them fails (this guarantees that they
566          won't match if either exists).  */
567
568       memset (&homebuf, 0, sizeof (struct stat));
569       memset (&cwdbuf, 0, sizeof (struct stat));
570
571       stat (homeinit, &homebuf);
572       stat (gdbinit, &cwdbuf);  /* We'll only need this if
573                                    homedir was set.  */
574     }
575
576   /* Now perform all the actions indicated by the arguments.  */
577   if (cdarg != NULL)
578     {
579       catch_command_errors (cd_command, cdarg, 0, RETURN_MASK_ALL);
580     }
581
582   for (i = 0; i < ndir; i++)
583     catch_command_errors (directory_command, dirarg[i], 0, RETURN_MASK_ALL);
584   xfree (dirarg);
585
586   if (execarg != NULL
587       && symarg != NULL
588       && STREQ (execarg, symarg))
589     {
590       /* The exec file and the symbol-file are the same.  If we can't
591          open it, better only print one error message.
592          catch_command_errors returns non-zero on success! */
593       if (catch_command_errors (exec_file_attach, execarg, !batch, RETURN_MASK_ALL))
594         catch_command_errors (symbol_file_add_main, symarg, 0, RETURN_MASK_ALL);
595     }
596   else
597     {
598       if (execarg != NULL)
599         catch_command_errors (exec_file_attach, execarg, !batch, RETURN_MASK_ALL);
600       if (symarg != NULL)
601         catch_command_errors (symbol_file_add_main, symarg, 0, RETURN_MASK_ALL);
602     }
603
604   /* After the symbol file has been read, print a newline to get us
605      beyond the copyright line...  But errors should still set off
606      the error message with a (single) blank line.  */
607   if (!quiet)
608     printf_filtered ("\n");
609   error_pre_print = "\n";
610   quit_pre_print = error_pre_print;
611   warning_pre_print = _("\nwarning: ");
612
613   if (corearg != NULL)
614     {
615       /* corearg may be either a corefile or a pid.
616          If its first character is a digit, try attach first
617          and then corefile.  Otherwise try corefile first. */
618
619       if (isdigit (corearg[0]))
620         {
621           if (catch_command_errors (attach_command, corearg, 
622                                     !batch, RETURN_MASK_ALL) == 0)
623             catch_command_errors (core_file_command, corearg, 
624                                   !batch, RETURN_MASK_ALL);
625         }
626       else /* Can't be a pid, better be a corefile. */
627         catch_command_errors (core_file_command, corearg, 
628                               !batch, RETURN_MASK_ALL);
629     }
630
631   if (ttyarg != NULL)
632     catch_command_errors (tty_command, ttyarg, !batch, RETURN_MASK_ALL);
633
634   /* Error messages should no longer be distinguished with extra output. */
635   error_pre_print = NULL;
636   quit_pre_print = NULL;
637   warning_pre_print = _("warning: ");
638
639   /* Read the .gdbinit file in the current directory, *if* it isn't
640      the same as the $HOME/.gdbinit file (it should exist, also).  */
641
642   if (!homedir
643       || memcmp ((char *) &homebuf, (char *) &cwdbuf, sizeof (struct stat)))
644     if (!inhibit_gdbinit)
645       {
646         catch_command_errors (source_command, gdbinit, 0, RETURN_MASK_ALL);
647       }
648
649   for (i = 0; i < ncmd; i++)
650     {
651 #if 0
652       /* NOTE: cagney/1999-11-03: SET_TOP_LEVEL() was a macro that
653          expanded into a call to setjmp().  */
654       if (!SET_TOP_LEVEL ()) /* NB: This is #if 0'd out */
655         {
656           /* NOTE: I am commenting this out, because it is not clear
657              where this feature is used. It is very old and
658              undocumented. ezannoni: 1999-05-04 */
659 #if 0
660           if (cmdarg[i][0] == '-' && cmdarg[i][1] == '\0')
661             read_command_file (stdin);
662           else
663 #endif
664             source_command (cmdarg[i], !batch);
665           do_cleanups (ALL_CLEANUPS);
666         }
667 #endif
668       catch_command_errors (source_command, cmdarg[i], !batch, RETURN_MASK_ALL);
669     }
670   xfree (cmdarg);
671
672   /* Read in the old history after all the command files have been read. */
673   init_history ();
674
675   if (batch)
676     {
677       /* We have hit the end of the batch file.  */
678       exit (0);
679     }
680
681   /* Do any host- or target-specific hacks.  This is used for i960 targets
682      to force the user to set a nindy target and spec its parameters.  */
683
684 #ifdef BEFORE_MAIN_LOOP_HOOK
685   BEFORE_MAIN_LOOP_HOOK;
686 #endif
687
688   END_PROGRESS (argv[0]);
689
690   /* Show time and/or space usage.  */
691
692   if (display_time)
693     {
694       long init_time = get_run_time () - time_at_startup;
695
696       printf_unfiltered (_("Startup time: %ld.%06ld\n"),
697                          init_time / 1000000, init_time % 1000000);
698     }
699
700   if (display_space)
701     {
702 #ifdef HAVE_SBRK
703       extern char **environ;
704       char *lim = (char *) sbrk (0);
705
706       printf_unfiltered (_("Startup size: data size %ld\n"),
707                          (long) (lim - (char *) &environ));
708 #endif
709     }
710
711 #if 0
712   /* FIXME: cagney/1999-11-06: The original main loop was like: */
713   while (1)
714     {
715       if (!SET_TOP_LEVEL ())
716         {
717           do_cleanups (ALL_CLEANUPS);   /* Do complete cleanup */
718           /* GUIs generally have their own command loop, mainloop, or whatever.
719              This is a good place to gain control because many error
720              conditions will end up here via longjmp(). */
721           if (command_loop_hook)
722             command_loop_hook ();
723           else
724             command_loop ();
725           quit_command ((char *) 0, instream == stdin);
726         }
727     }
728   /* NOTE: If the command_loop() returned normally, the loop would
729      attempt to exit by calling the function quit_command().  That
730      function would either call exit() or throw an error returning
731      control to SET_TOP_LEVEL. */
732   /* NOTE: The function do_cleanups() was called once each time round
733      the loop.  The usefulness of the call isn't clear.  If an error
734      was thrown, everything would have already been cleaned up.  If
735      command_loop() returned normally and quit_command() was called,
736      either exit() or error() (again cleaning up) would be called. */
737 #endif
738   /* NOTE: cagney/1999-11-07: There is probably no reason for not
739      moving this loop and the code found in captured_command_loop()
740      into the command_loop() proper.  The main thing holding back that
741      change - SET_TOP_LEVEL() - has been eliminated. */
742   while (1)
743     {
744       catch_errors (captured_command_loop, 0, "", RETURN_MASK_ALL);
745     }
746   /* No exit -- exit is through quit_command.  */
747 }
748
749 int
750 gdb_main (struct captured_main_args *args)
751 {
752   use_windows = args->use_windows;
753   catch_errors (captured_main, args, "", RETURN_MASK_ALL);
754   return 0;
755 }
756
757
758 /* Don't use *_filtered for printing help.  We don't want to prompt
759    for continue no matter how small the screen or how much we're going
760    to print.  */
761
762 static void
763 print_gdb_help (struct ui_file *stream)
764 {
765   fputs_unfiltered (_("\
766 This is the GNU debugger.  Usage:\n\n\
767     gdb [options] [executable-file [core-file or process-id]]\n\
768     gdb [options] --args executable-file [inferior-arguments ...]\n\n\
769 Options:\n\n\
770 "), stream);
771   fputs_unfiltered (_("\
772   --args             Arguments after executable-file are passed to inferior\n\
773 "), stream);
774   fputs_unfiltered (_("\
775   --[no]async        Enable (disable) asynchronous version of CLI\n\
776 "), stream);
777   fputs_unfiltered (_("\
778   -b BAUDRATE        Set serial port baud rate used for remote debugging.\n\
779   --batch            Exit after processing options.\n\
780   --cd=DIR           Change current directory to DIR.\n\
781   --command=FILE     Execute GDB commands from FILE.\n\
782   --core=COREFILE    Analyze the core dump COREFILE.\n\
783   --pid=PID          Attach to running process PID.\n\
784 "), stream);
785   fputs_unfiltered (_("\
786   --dbx              DBX compatibility mode.\n\
787   --directory=DIR    Search for source files in DIR.\n\
788   --epoch            Output information used by epoch emacs-GDB interface.\n\
789   --exec=EXECFILE    Use EXECFILE as the executable.\n\
790   --fullname         Output information used by emacs-GDB interface.\n\
791   --help             Print this message.\n\
792 "), stream);
793   fputs_unfiltered (_("\
794   --interpreter=INTERP\n\
795                      Select a specific interpreter / user interface\n\
796 "), stream);
797   fputs_unfiltered (_("\
798   --mapped           Use mapped symbol files if supported on this system.\n\
799   --nw               Do not use a window interface.\n\
800   --nx               Do not read "), stream);
801   fputs_unfiltered (gdbinit, stream);
802   fputs_unfiltered (_(" file.\n\
803   --quiet            Do not print version number on startup.\n\
804   --readnow          Fully read symbol files on first access.\n\
805 "), stream);
806   fputs_unfiltered (_("\
807   --se=FILE          Use FILE as symbol file and executable file.\n\
808   --symbols=SYMFILE  Read symbols from SYMFILE.\n\
809   --tty=TTY          Use TTY for input/output by the program being debugged.\n\
810 "), stream);
811 #if defined(TUI)
812   fputs_unfiltered (_("\
813   --tui              Use a terminal user interface.\n\
814 "), stream);
815 #endif
816   fputs_unfiltered (_("\
817   --version          Print version information and then exit.\n\
818   -w                 Use a window interface.\n\
819   --write            Set writing into executable and core files.\n\
820   --xdb              XDB compatibility mode.\n\
821 "), stream);
822   fputs_unfiltered (_("\n\
823 For more information, type \"help\" from within GDB, or consult the\n\
824 GDB manual (available as on-line info or a printed manual).\n\
825 Report bugs to \"bug-gdb@gnu.org\".\
826 "), stream);
827 }