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