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