1 /* Top level stuff for GDB, the GNU debugger.
3 Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
4 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008,
5 2009 Free Software Foundation, Inc.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
29 #include "exceptions.h"
32 #include <sys/types.h>
36 #include "gdb_string.h"
37 #include "event-loop.h"
45 /* If nonzero, display time usage both at startup and for each command. */
49 /* If nonzero, display space usage both at startup and for each command. */
53 /* The selected interpreter. This will be used as a set command
54 variable, so it should always be malloc'ed - since
55 do_setshow_command will free it. */
58 /* Whether xdb commands will be handled */
61 /* Whether dbx commands will be handled */
64 /* System root path, used to find libraries etc. */
65 char *gdb_sysroot
= 0;
67 struct ui_file
*gdb_stdout
;
68 struct ui_file
*gdb_stderr
;
69 struct ui_file
*gdb_stdlog
;
70 struct ui_file
*gdb_stdin
;
71 /* target IO streams */
72 struct ui_file
*gdb_stdtargin
;
73 struct ui_file
*gdb_stdtarg
;
74 struct ui_file
*gdb_stdtargerr
;
76 /* Support for the --batch-silent option. */
79 /* Support for --return-child-result option.
80 Set the default to -1 to return error in the case
81 that the program does not run or does not complete. */
82 int return_child_result
= 0;
83 int return_child_result_value
= -1;
85 /* Whether to enable writing into executable and core files */
86 extern int write_files
;
88 /* GDB as it has been invoked from the command line (i.e. argv[0]). */
89 static char *gdb_program_name
;
91 static void print_gdb_help (struct ui_file
*);
93 /* These two are used to set the external editor commands when gdb is farming
94 out files to be edited by another program. */
96 extern char *external_editor_command
;
98 /* Compute the locations of init files that GDB should source and return
99 them in SYSTEM_GDBINIT, HOME_GDBINIT, LOCAL_GDBINIT. If there is
100 no system gdbinit (resp. home gdbinit and local gdbinit) to be loaded,
101 then SYSTEM_GDBINIT (resp. HOME_GDBINIT and LOCAL_GDBINIT) is set to
104 get_init_files (char **system_gdbinit
,
106 char **local_gdbinit
)
108 static char *sysgdbinit
= NULL
;
109 static char *homeinit
= NULL
;
110 static char *localinit
= NULL
;
111 static int initialized
= 0;
115 struct stat homebuf
, cwdbuf
, s
;
116 char *homedir
, *relocated_sysgdbinit
;
118 sysgdbinit
= SYSTEM_GDBINIT
;
119 if (!sysgdbinit
[0] || stat (sysgdbinit
, &s
) != 0)
122 #ifdef SYSTEM_GDBINIT_RELOCATABLE
123 relocated_sysgdbinit
= make_relative_prefix (gdb_program_name
, BINDIR
,
125 if (relocated_sysgdbinit
)
130 if (stat (relocated_sysgdbinit
, &s
) == 0)
131 sysgdbinit
= relocated_sysgdbinit
;
133 xfree (relocated_sysgdbinit
);
137 homedir
= getenv ("HOME");
139 /* If the .gdbinit file in the current directory is the same as
140 the $HOME/.gdbinit file, it should not be sourced. homebuf
141 and cwdbuf are used in that purpose. Make sure that the stats
142 are zero in case one of them fails (this guarantees that they
143 won't match if either exists). */
145 memset (&homebuf
, 0, sizeof (struct stat
));
146 memset (&cwdbuf
, 0, sizeof (struct stat
));
150 homeinit
= xstrprintf ("%s/%s", homedir
, gdbinit
);
151 if (stat (homeinit
, &homebuf
) != 0)
158 if (stat (gdbinit
, &cwdbuf
) == 0)
161 || memcmp ((char *) &homebuf
, (char *) &cwdbuf
,
162 sizeof (struct stat
)))
169 *system_gdbinit
= sysgdbinit
;
170 *home_gdbinit
= homeinit
;
171 *local_gdbinit
= localinit
;
174 /* Call command_loop. If it happens to return, pass that through as a
175 non-zero return status. */
178 captured_command_loop (void *data
)
180 current_interp_command_loop ();
181 /* FIXME: cagney/1999-11-05: A correct command_loop() implementaton
182 would clean things up (restoring the cleanup chain) to the state
183 they were just prior to the call. Technically, this means that
184 the do_cleanups() below is redundant. Unfortunately, many FUNCs
185 are not that well behaved. do_cleanups should either be replaced
186 with a do_cleanups call (to cover the problem) or an assertion
187 check to detect bad FUNCs code. */
188 do_cleanups (ALL_CLEANUPS
);
189 /* If the command_loop returned, normally (rather than threw an
190 error) we try to quit. If the quit is aborted, catch_errors()
191 which called this catch the signal and restart the command
193 quit_command (NULL
, instream
== stdin
);
198 captured_main (void *data
)
200 struct captured_main_args
*context
= data
;
201 int argc
= context
->argc
;
202 char **argv
= context
->argv
;
203 static int quiet
= 0;
204 static int batch
= 0;
205 static int set_args
= 0;
207 /* Pointers to various arguments from command line. */
209 char *execarg
= NULL
;
211 char *corearg
= NULL
;
212 char *pid_or_core_arg
= NULL
;
216 /* These are static so that we can take their address in an initializer. */
217 static int print_help
;
218 static int print_version
;
220 /* Pointers to all arguments of --command option. */
228 /* Allocated size of cmdarg. */
230 /* Number of elements of cmdarg used. */
233 /* Indices of all arguments of --directory option. */
235 /* Allocated size. */
237 /* Number of elements used. */
240 /* gdb init files. */
241 char *system_gdbinit
;
247 long time_at_startup
= get_run_time ();
249 #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
250 setlocale (LC_MESSAGES
, "");
252 #if defined (HAVE_SETLOCALE)
253 setlocale (LC_CTYPE
, "");
255 bindtextdomain (PACKAGE
, LOCALEDIR
);
256 textdomain (PACKAGE
);
259 lim_at_start
= (char *) sbrk (0);
263 cmdarg
= (struct cmdarg
*) xmalloc (cmdsize
* sizeof (*cmdarg
));
266 dirarg
= (char **) xmalloc (dirsize
* sizeof (*dirarg
));
270 line
= (char *) xmalloc (linesize
);
271 line
[0] = '\0'; /* Terminate saved (now empty) cmd line */
274 gdb_stdout
= stdio_fileopen (stdout
);
275 gdb_stderr
= stdio_fileopen (stderr
);
276 gdb_stdlog
= gdb_stderr
; /* for moment */
277 gdb_stdtarg
= gdb_stderr
; /* for moment */
278 gdb_stdin
= stdio_fileopen (stdin
);
279 gdb_stdtargerr
= gdb_stderr
; /* for moment */
280 gdb_stdtargin
= gdb_stdin
; /* for moment */
282 gdb_program_name
= xstrdup (argv
[0]);
284 if (! getcwd (gdb_dirbuf
, sizeof (gdb_dirbuf
)))
285 /* Don't use *_filtered or warning() (which relies on
286 current_target) until after initialize_all_files(). */
287 fprintf_unfiltered (gdb_stderr
,
288 _("%s: warning: error finding working directory: %s\n"),
289 argv
[0], safe_strerror (errno
));
291 current_directory
= gdb_dirbuf
;
293 /* Set the sysroot path. */
294 #ifdef TARGET_SYSTEM_ROOT_RELOCATABLE
295 gdb_sysroot
= make_relative_prefix (argv
[0], BINDIR
, TARGET_SYSTEM_ROOT
);
301 if (stat (gdb_sysroot
, &s
) == 0)
302 if (S_ISDIR (s
.st_mode
))
308 gdb_sysroot
= xstrdup (TARGET_SYSTEM_ROOT
);
312 gdb_sysroot
= xstrdup (TARGET_SYSTEM_ROOT
);
314 gdb_sysroot
= xstrdup (TARGET_SYSTEM_ROOT
);
317 /* Canonicalize the sysroot path. */
320 char *canon_sysroot
= lrealpath (gdb_sysroot
);
324 gdb_sysroot
= canon_sysroot
;
328 #ifdef DEBUGDIR_RELOCATABLE
329 debug_file_directory
= make_relative_prefix (argv
[0], BINDIR
, DEBUGDIR
);
330 if (debug_file_directory
)
335 if (stat (debug_file_directory
, &s
) == 0)
336 if (S_ISDIR (s
.st_mode
))
341 xfree (debug_file_directory
);
342 debug_file_directory
= xstrdup (DEBUGDIR
);
346 debug_file_directory
= xstrdup (DEBUGDIR
);
348 debug_file_directory
= xstrdup (DEBUGDIR
);
351 /* Canonicalize the debugfile path. */
352 if (*debug_file_directory
)
354 char *canon_debug
= lrealpath (debug_file_directory
);
357 xfree (debug_file_directory
);
358 debug_file_directory
= canon_debug
;
362 get_init_files (&system_gdbinit
, &home_gdbinit
, &local_gdbinit
);
365 add_substitute_path_rule (RELOC_SRCDIR
,
366 make_relative_prefix (argv
[0], BINDIR
,
370 /* There will always be an interpreter. Either the one passed into
371 this captured main, or one specified by the user at start up, or
372 the console. Initialize the interpreter to the one requested by
374 interpreter_p
= xstrdup (context
->interpreter_p
);
376 /* Parse arguments and options. */
379 /* When var field is 0, use flag field to record the equivalent
380 short option (or arbitrary numbers starting at 10 for those
381 with no equivalent). */
391 static struct option long_options
[] =
393 {"tui", no_argument
, 0, OPT_TUI
},
394 {"xdb", no_argument
, &xdb_commands
, 1},
395 {"dbx", no_argument
, &dbx_commands
, 1},
396 {"readnow", no_argument
, &readnow_symbol_files
, 1},
397 {"r", no_argument
, &readnow_symbol_files
, 1},
398 {"quiet", no_argument
, &quiet
, 1},
399 {"q", no_argument
, &quiet
, 1},
400 {"silent", no_argument
, &quiet
, 1},
401 {"nx", no_argument
, &inhibit_gdbinit
, 1},
402 {"n", no_argument
, &inhibit_gdbinit
, 1},
403 {"batch-silent", no_argument
, 0, 'B'},
404 {"batch", no_argument
, &batch
, 1},
405 {"epoch", no_argument
, &epoch_interface
, 1},
407 /* This is a synonym for "--annotate=1". --annotate is now preferred,
408 but keep this here for a long time because people will be running
409 emacses which use --fullname. */
410 {"fullname", no_argument
, 0, 'f'},
411 {"f", no_argument
, 0, 'f'},
413 {"annotate", required_argument
, 0, OPT_ANNOTATE
},
414 {"help", no_argument
, &print_help
, 1},
415 {"se", required_argument
, 0, OPT_SE
},
416 {"symbols", required_argument
, 0, 's'},
417 {"s", required_argument
, 0, 's'},
418 {"exec", required_argument
, 0, 'e'},
419 {"e", required_argument
, 0, 'e'},
420 {"core", required_argument
, 0, 'c'},
421 {"c", required_argument
, 0, 'c'},
422 {"pid", required_argument
, 0, 'p'},
423 {"p", required_argument
, 0, 'p'},
424 {"command", required_argument
, 0, 'x'},
425 {"eval-command", required_argument
, 0, 'X'},
426 {"version", no_argument
, &print_version
, 1},
427 {"x", required_argument
, 0, 'x'},
428 {"ex", required_argument
, 0, 'X'},
430 {"tclcommand", required_argument
, 0, 'z'},
431 {"enable-external-editor", no_argument
, 0, 'y'},
432 {"editor-command", required_argument
, 0, 'w'},
434 {"ui", required_argument
, 0, 'i'},
435 {"interpreter", required_argument
, 0, 'i'},
436 {"i", required_argument
, 0, 'i'},
437 {"directory", required_argument
, 0, 'd'},
438 {"d", required_argument
, 0, 'd'},
439 {"cd", required_argument
, 0, OPT_CD
},
440 {"tty", required_argument
, 0, 't'},
441 {"baud", required_argument
, 0, 'b'},
442 {"b", required_argument
, 0, 'b'},
443 {"nw", no_argument
, NULL
, OPT_NOWINDOWS
},
444 {"nowindows", no_argument
, NULL
, OPT_NOWINDOWS
},
445 {"w", no_argument
, NULL
, OPT_WINDOWS
},
446 {"windows", no_argument
, NULL
, OPT_WINDOWS
},
447 {"statistics", no_argument
, 0, OPT_STATISTICS
},
448 {"write", no_argument
, &write_files
, 1},
449 {"args", no_argument
, &set_args
, 1},
450 {"l", required_argument
, 0, 'l'},
451 {"return-child-result", no_argument
, &return_child_result
, 1},
452 {0, no_argument
, 0, 0}
459 c
= getopt_long_only (argc
, argv
, "",
460 long_options
, &option_index
);
461 if (c
== EOF
|| set_args
)
464 /* Long option that takes an argument. */
465 if (c
== 0 && long_options
[option_index
].flag
== 0)
466 c
= long_options
[option_index
].val
;
471 /* Long option that just sets a flag. */
481 /* FIXME: what if the syntax is wrong (e.g. not digits)? */
482 annotation_level
= atoi (optarg
);
485 /* Enable the display of both time and space usage. */
490 /* --tui is equivalent to -i=tui. */
492 xfree (interpreter_p
);
493 interpreter_p
= xstrdup (INTERP_TUI
);
495 fprintf_unfiltered (gdb_stderr
,
496 _("%s: TUI mode is not supported\n"),
502 /* FIXME: cagney/2003-03-01: Not sure if this option is
503 actually useful, and if it is, what it should do. */
505 /* --windows is equivalent to -i=insight. */
506 xfree (interpreter_p
);
507 interpreter_p
= xstrdup (INTERP_INSIGHT
);
512 /* -nw is equivalent to -i=console. */
513 xfree (interpreter_p
);
514 interpreter_p
= xstrdup (INTERP_CONSOLE
);
518 annotation_level
= 1;
519 /* We have probably been invoked from emacs. Disable window interface. */
535 cmdarg
[ncmd
].type
= CMDARG_FILE
;
536 cmdarg
[ncmd
++].string
= optarg
;
540 cmdarg
= xrealloc ((char *) cmdarg
,
541 cmdsize
* sizeof (*cmdarg
));
545 cmdarg
[ncmd
].type
= CMDARG_COMMAND
;
546 cmdarg
[ncmd
++].string
= optarg
;
550 cmdarg
= xrealloc ((char *) cmdarg
,
551 cmdsize
* sizeof (*cmdarg
));
555 batch
= batch_silent
= 1;
556 gdb_stdout
= ui_file_new();
561 extern int gdbtk_test (char *);
562 if (!gdbtk_test (optarg
))
564 fprintf_unfiltered (gdb_stderr
, _("%s: unable to load tclcommand file \"%s\""),
571 /* Backwards compatibility only. */
575 external_editor_command
= xstrdup (optarg
);
580 xfree (interpreter_p
);
581 interpreter_p
= xstrdup (optarg
);
584 dirarg
[ndir
++] = optarg
;
588 dirarg
= (char **) xrealloc ((char *) dirarg
,
589 dirsize
* sizeof (*dirarg
));
603 i
= strtol (optarg
, &p
, 0);
604 if (i
== 0 && p
== optarg
)
606 /* Don't use *_filtered or warning() (which relies on
607 current_target) until after initialize_all_files(). */
611 _("warning: could not set baud rate to `%s'.\n"), optarg
);
621 i
= strtol (optarg
, &p
, 0);
622 if (i
== 0 && p
== optarg
)
624 /* Don't use *_filtered or warning() (which relies on
625 current_target) until after initialize_all_files(). */
629 _("warning: could not set timeout limit to `%s'.\n"), optarg
);
636 fprintf_unfiltered (gdb_stderr
,
637 _("Use `%s --help' for a complete list of options.\n"),
643 /* If --help or --version, disable window interface. */
644 if (print_help
|| print_version
)
651 /* The remaining options are the command-line options for the
652 inferior. The first one is the sym/exec file, and the rest
656 fprintf_unfiltered (gdb_stderr
,
657 _("%s: `--args' specified but no program specified\n"),
661 symarg
= argv
[optind
];
662 execarg
= argv
[optind
];
664 set_inferior_args_vector (argc
- optind
, &argv
[optind
]);
668 /* OK, that's all the options. */
670 /* The first argument, if specified, is the name of the
674 symarg
= argv
[optind
];
675 execarg
= argv
[optind
];
679 /* If the user hasn't already specified a PID or the name of a
680 core file, then a second optional argument is allowed. If
681 present, this argument should be interpreted as either a
682 PID or a core file, whichever works. */
683 if (pidarg
== NULL
&& corearg
== NULL
&& optind
< argc
)
685 pid_or_core_arg
= argv
[optind
];
689 /* Any argument left on the command line is unexpected and
690 will be ignored. Inform the user. */
692 fprintf_unfiltered (gdb_stderr
, _("\
693 Excess command line arguments ignored. (%s%s)\n"),
695 (optind
== argc
- 1) ? "" : " ...");
701 /* Initialize all files. Give the interpreter a chance to take
702 control of the console via the deprecated_init_ui_hook (). */
705 /* Do these (and anything which might call wrap_here or *_filtered)
706 after initialize_all_files() but before the interpreter has been
707 installed. Otherwize the help/version messages will be eaten by
708 the interpreter's output handler. */
712 print_gdb_version (gdb_stdout
);
714 printf_filtered ("\n");
720 print_gdb_help (gdb_stdout
);
721 fputs_unfiltered ("\n", gdb_stdout
);
725 /* FIXME: cagney/2003-02-03: The big hack (part 1 of 2) that lets
726 GDB retain the old MI1 interpreter startup behavior. Output the
727 copyright message before the interpreter is installed. That way
728 it isn't encapsulated in MI output. */
729 if (!quiet
&& strcmp (interpreter_p
, INTERP_MI1
) == 0)
731 /* Print all the junk at the top, with trailing "..." if we are about
732 to read a symbol file (possibly slowly). */
733 print_gdb_version (gdb_stdout
);
735 printf_filtered ("..");
737 printf_filtered ("\n");
738 gdb_flush (gdb_stdout
); /* Force to screen during slow operations */
742 /* Install the default UI. All the interpreters should have had a
743 look at things by now. Initialize the default interpreter. */
747 struct interp
*interp
= interp_lookup (interpreter_p
);
749 error (_("Interpreter `%s' unrecognized"), interpreter_p
);
751 if (!interp_set (interp
, 1))
753 fprintf_unfiltered (gdb_stderr
,
754 "Interpreter `%s' failed to initialize.\n",
760 /* FIXME: cagney/2003-02-03: The big hack (part 2 of 2) that lets
761 GDB retain the old MI1 interpreter startup behavior. Output the
762 copyright message after the interpreter is installed when it is
763 any sane interpreter. */
764 if (!quiet
&& !current_interp_named_p (INTERP_MI1
))
766 /* Print all the junk at the top, with trailing "..." if we are about
767 to read a symbol file (possibly slowly). */
768 print_gdb_version (gdb_stdout
);
770 printf_filtered ("..");
772 printf_filtered ("\n");
773 gdb_flush (gdb_stdout
); /* Force to screen during slow operations */
776 /* Set off error and warning messages with a blank line. */
777 error_pre_print
= "\n";
778 quit_pre_print
= error_pre_print
;
779 warning_pre_print
= _("\nwarning: ");
781 /* Read and execute the system-wide gdbinit file, if it exists.
782 This is done *before* all the command line arguments are
783 processed; it sets global parameters, which are independent of
784 what file you are debugging or what directory you are in. */
785 if (system_gdbinit
&& !inhibit_gdbinit
)
786 catch_command_errors (source_script
, system_gdbinit
, 0, RETURN_MASK_ALL
);
788 /* Read and execute $HOME/.gdbinit file, if it exists. This is done
789 *before* all the command line arguments are processed; it sets
790 global parameters, which are independent of what file you are
791 debugging or what directory you are in. */
793 if (home_gdbinit
&& !inhibit_gdbinit
)
794 catch_command_errors (source_script
, home_gdbinit
, 0, RETURN_MASK_ALL
);
796 /* Now perform all the actions indicated by the arguments. */
799 catch_command_errors (cd_command
, cdarg
, 0, RETURN_MASK_ALL
);
802 for (i
= 0; i
< ndir
; i
++)
803 catch_command_errors (directory_switch
, dirarg
[i
], 0, RETURN_MASK_ALL
);
808 && strcmp (execarg
, symarg
) == 0)
810 /* The exec file and the symbol-file are the same. If we can't
811 open it, better only print one error message.
812 catch_command_errors returns non-zero on success! */
813 if (catch_command_errors (exec_file_attach
, execarg
, !batch
, RETURN_MASK_ALL
))
814 catch_command_errors (symbol_file_add_main
, symarg
, 0, RETURN_MASK_ALL
);
819 catch_command_errors (exec_file_attach
, execarg
, !batch
, RETURN_MASK_ALL
);
821 catch_command_errors (symbol_file_add_main
, symarg
, 0, RETURN_MASK_ALL
);
824 if (corearg
&& pidarg
)
826 Can't attach to process and specify a core file at the same time."));
829 catch_command_errors (core_file_command
, corearg
,
830 !batch
, RETURN_MASK_ALL
);
831 else if (pidarg
!= NULL
)
832 catch_command_errors (attach_command
, pidarg
,
833 !batch
, RETURN_MASK_ALL
);
834 else if (pid_or_core_arg
)
836 /* The user specified 'gdb program pid' or gdb program core'.
837 If pid_or_core_arg's first character is a digit, try attach
838 first and then corefile. Otherwise try just corefile. */
840 if (isdigit (pid_or_core_arg
[0]))
842 if (catch_command_errors (attach_command
, pid_or_core_arg
,
843 !batch
, RETURN_MASK_ALL
) == 0)
844 catch_command_errors (core_file_command
, pid_or_core_arg
,
845 !batch
, RETURN_MASK_ALL
);
847 else /* Can't be a pid, better be a corefile. */
848 catch_command_errors (core_file_command
, pid_or_core_arg
,
849 !batch
, RETURN_MASK_ALL
);
853 catch_command_errors (tty_command
, ttyarg
, !batch
, RETURN_MASK_ALL
);
855 /* Error messages should no longer be distinguished with extra output. */
856 error_pre_print
= NULL
;
857 quit_pre_print
= NULL
;
858 warning_pre_print
= _("warning: ");
860 /* Read the .gdbinit file in the current directory, *if* it isn't
861 the same as the $HOME/.gdbinit file (it should exist, also). */
862 if (local_gdbinit
&& !inhibit_gdbinit
)
863 catch_command_errors (source_script
, local_gdbinit
, 0, RETURN_MASK_ALL
);
865 for (i
= 0; i
< ncmd
; i
++)
867 if (cmdarg
[i
].type
== CMDARG_FILE
)
868 catch_command_errors (source_script
, cmdarg
[i
].string
,
869 !batch
, RETURN_MASK_ALL
);
870 else /* cmdarg[i].type == CMDARG_COMMAND */
871 catch_command_errors (execute_command
, cmdarg
[i
].string
,
872 !batch
, RETURN_MASK_ALL
);
876 /* Read in the old history after all the command files have been read. */
881 /* We have hit the end of the batch file. */
882 quit_force (NULL
, 0);
885 /* Show time and/or space usage. */
889 long init_time
= get_run_time () - time_at_startup
;
891 printf_unfiltered (_("Startup time: %ld.%06ld\n"),
892 init_time
/ 1000000, init_time
% 1000000);
898 extern char **environ
;
899 char *lim
= (char *) sbrk (0);
901 printf_unfiltered (_("Startup size: data size %ld\n"),
902 (long) (lim
- (char *) &environ
));
906 /* NOTE: cagney/1999-11-07: There is probably no reason for not
907 moving this loop and the code found in captured_command_loop()
908 into the command_loop() proper. The main thing holding back that
909 change - SET_TOP_LEVEL() - has been eliminated. */
912 catch_errors (captured_command_loop
, 0, "", RETURN_MASK_ALL
);
914 /* No exit -- exit is through quit_command. */
918 gdb_main (struct captured_main_args
*args
)
920 use_windows
= args
->use_windows
;
921 catch_errors (captured_main
, args
, "", RETURN_MASK_ALL
);
922 /* The only way to end up here is by an error (normal exit is
923 handled by quit_force()), hence always return an error status. */
928 /* Don't use *_filtered for printing help. We don't want to prompt
929 for continue no matter how small the screen or how much we're going
933 print_gdb_help (struct ui_file
*stream
)
935 char *system_gdbinit
;
939 get_init_files (&system_gdbinit
, &home_gdbinit
, &local_gdbinit
);
941 fputs_unfiltered (_("\
942 This is the GNU debugger. Usage:\n\n\
943 gdb [options] [executable-file [core-file or process-id]]\n\
944 gdb [options] --args executable-file [inferior-arguments ...]\n\n\
947 fputs_unfiltered (_("\
948 --args Arguments after executable-file are passed to inferior\n\
950 fputs_unfiltered (_("\
951 -b BAUDRATE Set serial port baud rate used for remote debugging.\n\
952 --batch Exit after processing options.\n\
953 --batch-silent As for --batch, but suppress all gdb stdout output.\n\
954 --return-child-result\n\
955 GDB exit code will be the child's exit code.\n\
956 --cd=DIR Change current directory to DIR.\n\
957 --command=FILE, -x Execute GDB commands from FILE.\n\
958 --eval-command=COMMAND, -ex\n\
959 Execute a single GDB command.\n\
960 May be used multiple times and in conjunction\n\
962 --core=COREFILE Analyze the core dump COREFILE.\n\
963 --pid=PID Attach to running process PID.\n\
965 fputs_unfiltered (_("\
966 --dbx DBX compatibility mode.\n\
967 --directory=DIR Search for source files in DIR.\n\
968 --epoch Output information used by epoch emacs-GDB interface.\n\
969 --exec=EXECFILE Use EXECFILE as the executable.\n\
970 --fullname Output information used by emacs-GDB interface.\n\
971 --help Print this message.\n\
973 fputs_unfiltered (_("\
974 --interpreter=INTERP\n\
975 Select a specific interpreter / user interface\n\
977 fputs_unfiltered (_("\
978 -l TIMEOUT Set timeout in seconds for remote debugging.\n\
979 --nw Do not use a window interface.\n\
980 --nx Do not read "), stream
);
981 fputs_unfiltered (gdbinit
, stream
);
982 fputs_unfiltered (_(" file.\n\
983 --quiet Do not print version number on startup.\n\
984 --readnow Fully read symbol files on first access.\n\
986 fputs_unfiltered (_("\
987 --se=FILE Use FILE as symbol file and executable file.\n\
988 --symbols=SYMFILE Read symbols from SYMFILE.\n\
989 --tty=TTY Use TTY for input/output by the program being debugged.\n\
992 fputs_unfiltered (_("\
993 --tui Use a terminal user interface.\n\
996 fputs_unfiltered (_("\
997 --version Print version information and then exit.\n\
998 -w Use a window interface.\n\
999 --write Set writing into executable and core files.\n\
1000 --xdb XDB compatibility mode.\n\
1002 fputs_unfiltered (_("\n\
1003 At startup, GDB reads the following init files and executes their commands:\n\
1006 fprintf_unfiltered (stream
, _("\
1007 * system-wide init file: %s\n\
1008 "), system_gdbinit
);
1010 fprintf_unfiltered (stream
, _("\
1011 * user-specific init file: %s\n\
1014 fprintf_unfiltered (stream
, _("\
1015 * local init file: ./%s\n\
1017 fputs_unfiltered (_("\n\
1018 For more information, type \"help\" from within GDB, or consult the\n\
1019 GDB manual (available as on-line info or a printed manual).\n\
1021 if (REPORT_BUGS_TO
[0] && stream
== gdb_stdout
)
1022 fprintf_unfiltered (stream
, _("\
1023 Report bugs to \"%s\".\n\
1024 "), REPORT_BUGS_TO
);