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"
43 /* If nonzero, display time usage both at startup and for each command. */
47 /* If nonzero, display space usage both at startup and for each command. */
51 /* The selected interpreter. This will be used as a set command
52 variable, so it should always be malloc'ed - since
53 do_setshow_command will free it. */
56 /* Whether xdb commands will be handled */
59 /* Whether dbx commands will be handled */
62 /* System root path, used to find libraries etc. */
63 char *gdb_sysroot
= 0;
65 struct ui_file
*gdb_stdout
;
66 struct ui_file
*gdb_stderr
;
67 struct ui_file
*gdb_stdlog
;
68 struct ui_file
*gdb_stdin
;
69 /* target IO streams */
70 struct ui_file
*gdb_stdtargin
;
71 struct ui_file
*gdb_stdtarg
;
72 struct ui_file
*gdb_stdtargerr
;
74 /* Support for the --batch-silent option. */
77 /* Support for --return-child-result option.
78 Set the default to -1 to return error in the case
79 that the program does not run or does not complete. */
80 int return_child_result
= 0;
81 int return_child_result_value
= -1;
83 /* Whether to enable writing into executable and core files */
84 extern int write_files
;
86 /* GDB as it has been invoked from the command line (i.e. argv[0]). */
87 static char *gdb_program_name
;
89 static void print_gdb_help (struct ui_file
*);
91 /* These two are used to set the external editor commands when gdb is farming
92 out files to be edited by another program. */
94 extern char *external_editor_command
;
96 /* Compute the locations of init files that GDB should source and return
97 them in SYSTEM_GDBINIT, HOME_GDBINIT, LOCAL_GDBINIT. If there is
98 no system gdbinit (resp. home gdbinit and local gdbinit) to be loaded,
99 then SYSTEM_GDBINIT (resp. HOME_GDBINIT and LOCAL_GDBINIT) is set to
102 get_init_files (char **system_gdbinit
,
104 char **local_gdbinit
)
106 static char *sysgdbinit
= NULL
;
107 static char *homeinit
= NULL
;
108 static char *localinit
= NULL
;
109 static int initialized
= 0;
113 struct stat homebuf
, cwdbuf
, s
;
114 char *homedir
, *relocated_sysgdbinit
;
116 sysgdbinit
= SYSTEM_GDBINIT
;
117 if (!sysgdbinit
[0] || stat (sysgdbinit
, &s
) != 0)
120 #ifdef SYSTEM_GDBINIT_RELOCATABLE
121 relocated_sysgdbinit
= make_relative_prefix (gdb_program_name
, BINDIR
,
123 if (relocated_sysgdbinit
)
128 if (stat (relocated_sysgdbinit
, &s
) == 0)
129 sysgdbinit
= relocated_sysgdbinit
;
131 xfree (relocated_sysgdbinit
);
135 homedir
= getenv ("HOME");
137 /* If the .gdbinit file in the current directory is the same as
138 the $HOME/.gdbinit file, it should not be sourced. homebuf
139 and cwdbuf are used in that purpose. Make sure that the stats
140 are zero in case one of them fails (this guarantees that they
141 won't match if either exists). */
143 memset (&homebuf
, 0, sizeof (struct stat
));
144 memset (&cwdbuf
, 0, sizeof (struct stat
));
148 homeinit
= xstrprintf ("%s/%s", homedir
, gdbinit
);
149 if (stat (homeinit
, &homebuf
) != 0)
156 if (stat (gdbinit
, &cwdbuf
) == 0)
159 || memcmp ((char *) &homebuf
, (char *) &cwdbuf
,
160 sizeof (struct stat
)))
167 *system_gdbinit
= sysgdbinit
;
168 *home_gdbinit
= homeinit
;
169 *local_gdbinit
= localinit
;
172 /* Call command_loop. If it happens to return, pass that through as a
173 non-zero return status. */
176 captured_command_loop (void *data
)
178 current_interp_command_loop ();
179 /* FIXME: cagney/1999-11-05: A correct command_loop() implementaton
180 would clean things up (restoring the cleanup chain) to the state
181 they were just prior to the call. Technically, this means that
182 the do_cleanups() below is redundant. Unfortunately, many FUNCs
183 are not that well behaved. do_cleanups should either be replaced
184 with a do_cleanups call (to cover the problem) or an assertion
185 check to detect bad FUNCs code. */
186 do_cleanups (ALL_CLEANUPS
);
187 /* If the command_loop returned, normally (rather than threw an
188 error) we try to quit. If the quit is aborted, catch_errors()
189 which called this catch the signal and restart the command
191 quit_command (NULL
, instream
== stdin
);
196 captured_main (void *data
)
198 struct captured_main_args
*context
= data
;
199 int argc
= context
->argc
;
200 char **argv
= context
->argv
;
201 static int quiet
= 0;
202 static int batch
= 0;
203 static int set_args
= 0;
205 /* Pointers to various arguments from command line. */
207 char *execarg
= NULL
;
209 char *corearg
= NULL
;
210 char *pid_or_core_arg
= NULL
;
214 /* These are static so that we can take their address in an initializer. */
215 static int print_help
;
216 static int print_version
;
218 /* Pointers to all arguments of --command option. */
226 /* Allocated size of cmdarg. */
228 /* Number of elements of cmdarg used. */
231 /* Indices of all arguments of --directory option. */
233 /* Allocated size. */
235 /* Number of elements used. */
238 /* gdb init files. */
239 char *system_gdbinit
;
245 long time_at_startup
= get_run_time ();
247 #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
248 setlocale (LC_MESSAGES
, "");
250 #if defined (HAVE_SETLOCALE)
251 setlocale (LC_CTYPE
, "");
253 bindtextdomain (PACKAGE
, LOCALEDIR
);
254 textdomain (PACKAGE
);
257 lim_at_start
= (char *) sbrk (0);
261 cmdarg
= (struct cmdarg
*) xmalloc (cmdsize
* sizeof (*cmdarg
));
264 dirarg
= (char **) xmalloc (dirsize
* sizeof (*dirarg
));
268 line
= (char *) xmalloc (linesize
);
269 line
[0] = '\0'; /* Terminate saved (now empty) cmd line */
272 gdb_stdout
= stdio_fileopen (stdout
);
273 gdb_stderr
= stdio_fileopen (stderr
);
274 gdb_stdlog
= gdb_stderr
; /* for moment */
275 gdb_stdtarg
= gdb_stderr
; /* for moment */
276 gdb_stdin
= stdio_fileopen (stdin
);
277 gdb_stdtargerr
= gdb_stderr
; /* for moment */
278 gdb_stdtargin
= gdb_stdin
; /* for moment */
280 gdb_program_name
= xstrdup (argv
[0]);
282 if (! getcwd (gdb_dirbuf
, sizeof (gdb_dirbuf
)))
283 /* Don't use *_filtered or warning() (which relies on
284 current_target) until after initialize_all_files(). */
285 fprintf_unfiltered (gdb_stderr
,
286 _("%s: warning: error finding working directory: %s\n"),
287 argv
[0], safe_strerror (errno
));
289 current_directory
= gdb_dirbuf
;
291 /* Set the sysroot path. */
292 #ifdef TARGET_SYSTEM_ROOT_RELOCATABLE
293 gdb_sysroot
= make_relative_prefix (argv
[0], BINDIR
, TARGET_SYSTEM_ROOT
);
299 if (stat (gdb_sysroot
, &s
) == 0)
300 if (S_ISDIR (s
.st_mode
))
306 gdb_sysroot
= xstrdup (TARGET_SYSTEM_ROOT
);
310 gdb_sysroot
= xstrdup (TARGET_SYSTEM_ROOT
);
312 gdb_sysroot
= xstrdup (TARGET_SYSTEM_ROOT
);
315 /* Canonicalize the sysroot path. */
318 char *canon_sysroot
= lrealpath (gdb_sysroot
);
322 gdb_sysroot
= canon_sysroot
;
326 #ifdef DEBUGDIR_RELOCATABLE
327 debug_file_directory
= make_relative_prefix (argv
[0], BINDIR
, DEBUGDIR
);
328 if (debug_file_directory
)
333 if (stat (debug_file_directory
, &s
) == 0)
334 if (S_ISDIR (s
.st_mode
))
339 xfree (debug_file_directory
);
340 debug_file_directory
= xstrdup (DEBUGDIR
);
344 debug_file_directory
= xstrdup (DEBUGDIR
);
346 debug_file_directory
= xstrdup (DEBUGDIR
);
349 /* Canonicalize the debugfile path. */
350 if (*debug_file_directory
)
352 char *canon_debug
= lrealpath (debug_file_directory
);
355 xfree (debug_file_directory
);
356 debug_file_directory
= canon_debug
;
360 get_init_files (&system_gdbinit
, &home_gdbinit
, &local_gdbinit
);
362 /* There will always be an interpreter. Either the one passed into
363 this captured main, or one specified by the user at start up, or
364 the console. Initialize the interpreter to the one requested by
366 interpreter_p
= xstrdup (context
->interpreter_p
);
368 /* Parse arguments and options. */
371 /* When var field is 0, use flag field to record the equivalent
372 short option (or arbitrary numbers starting at 10 for those
373 with no equivalent). */
383 static struct option long_options
[] =
385 {"tui", no_argument
, 0, OPT_TUI
},
386 {"xdb", no_argument
, &xdb_commands
, 1},
387 {"dbx", no_argument
, &dbx_commands
, 1},
388 {"readnow", no_argument
, &readnow_symbol_files
, 1},
389 {"r", no_argument
, &readnow_symbol_files
, 1},
390 {"quiet", no_argument
, &quiet
, 1},
391 {"q", no_argument
, &quiet
, 1},
392 {"silent", no_argument
, &quiet
, 1},
393 {"nx", no_argument
, &inhibit_gdbinit
, 1},
394 {"n", no_argument
, &inhibit_gdbinit
, 1},
395 {"batch-silent", no_argument
, 0, 'B'},
396 {"batch", no_argument
, &batch
, 1},
397 {"epoch", no_argument
, &epoch_interface
, 1},
399 /* This is a synonym for "--annotate=1". --annotate is now preferred,
400 but keep this here for a long time because people will be running
401 emacses which use --fullname. */
402 {"fullname", no_argument
, 0, 'f'},
403 {"f", no_argument
, 0, 'f'},
405 {"annotate", required_argument
, 0, OPT_ANNOTATE
},
406 {"help", no_argument
, &print_help
, 1},
407 {"se", required_argument
, 0, OPT_SE
},
408 {"symbols", required_argument
, 0, 's'},
409 {"s", required_argument
, 0, 's'},
410 {"exec", required_argument
, 0, 'e'},
411 {"e", required_argument
, 0, 'e'},
412 {"core", required_argument
, 0, 'c'},
413 {"c", required_argument
, 0, 'c'},
414 {"pid", required_argument
, 0, 'p'},
415 {"p", required_argument
, 0, 'p'},
416 {"command", required_argument
, 0, 'x'},
417 {"eval-command", required_argument
, 0, 'X'},
418 {"version", no_argument
, &print_version
, 1},
419 {"x", required_argument
, 0, 'x'},
420 {"ex", required_argument
, 0, 'X'},
422 {"tclcommand", required_argument
, 0, 'z'},
423 {"enable-external-editor", no_argument
, 0, 'y'},
424 {"editor-command", required_argument
, 0, 'w'},
426 {"ui", required_argument
, 0, 'i'},
427 {"interpreter", required_argument
, 0, 'i'},
428 {"i", required_argument
, 0, 'i'},
429 {"directory", required_argument
, 0, 'd'},
430 {"d", required_argument
, 0, 'd'},
431 {"cd", required_argument
, 0, OPT_CD
},
432 {"tty", required_argument
, 0, 't'},
433 {"baud", required_argument
, 0, 'b'},
434 {"b", required_argument
, 0, 'b'},
435 {"nw", no_argument
, NULL
, OPT_NOWINDOWS
},
436 {"nowindows", no_argument
, NULL
, OPT_NOWINDOWS
},
437 {"w", no_argument
, NULL
, OPT_WINDOWS
},
438 {"windows", no_argument
, NULL
, OPT_WINDOWS
},
439 {"statistics", no_argument
, 0, OPT_STATISTICS
},
440 {"write", no_argument
, &write_files
, 1},
441 {"args", no_argument
, &set_args
, 1},
442 {"l", required_argument
, 0, 'l'},
443 {"return-child-result", no_argument
, &return_child_result
, 1},
444 {0, no_argument
, 0, 0}
451 c
= getopt_long_only (argc
, argv
, "",
452 long_options
, &option_index
);
453 if (c
== EOF
|| set_args
)
456 /* Long option that takes an argument. */
457 if (c
== 0 && long_options
[option_index
].flag
== 0)
458 c
= long_options
[option_index
].val
;
463 /* Long option that just sets a flag. */
473 /* FIXME: what if the syntax is wrong (e.g. not digits)? */
474 annotation_level
= atoi (optarg
);
477 /* Enable the display of both time and space usage. */
482 /* --tui is equivalent to -i=tui. */
484 xfree (interpreter_p
);
485 interpreter_p
= xstrdup (INTERP_TUI
);
487 fprintf_unfiltered (gdb_stderr
,
488 _("%s: TUI mode is not supported\n"),
494 /* FIXME: cagney/2003-03-01: Not sure if this option is
495 actually useful, and if it is, what it should do. */
497 /* --windows is equivalent to -i=insight. */
498 xfree (interpreter_p
);
499 interpreter_p
= xstrdup (INTERP_INSIGHT
);
504 /* -nw is equivalent to -i=console. */
505 xfree (interpreter_p
);
506 interpreter_p
= xstrdup (INTERP_CONSOLE
);
510 annotation_level
= 1;
511 /* We have probably been invoked from emacs. Disable window interface. */
527 cmdarg
[ncmd
].type
= CMDARG_FILE
;
528 cmdarg
[ncmd
++].string
= optarg
;
532 cmdarg
= xrealloc ((char *) cmdarg
,
533 cmdsize
* sizeof (*cmdarg
));
537 cmdarg
[ncmd
].type
= CMDARG_COMMAND
;
538 cmdarg
[ncmd
++].string
= optarg
;
542 cmdarg
= xrealloc ((char *) cmdarg
,
543 cmdsize
* sizeof (*cmdarg
));
547 batch
= batch_silent
= 1;
548 gdb_stdout
= ui_file_new();
553 extern int gdbtk_test (char *);
554 if (!gdbtk_test (optarg
))
556 fprintf_unfiltered (gdb_stderr
, _("%s: unable to load tclcommand file \"%s\""),
563 /* Backwards compatibility only. */
567 external_editor_command
= xstrdup (optarg
);
572 xfree (interpreter_p
);
573 interpreter_p
= xstrdup (optarg
);
576 dirarg
[ndir
++] = optarg
;
580 dirarg
= (char **) xrealloc ((char *) dirarg
,
581 dirsize
* sizeof (*dirarg
));
595 i
= strtol (optarg
, &p
, 0);
596 if (i
== 0 && p
== optarg
)
598 /* Don't use *_filtered or warning() (which relies on
599 current_target) until after initialize_all_files(). */
603 _("warning: could not set baud rate to `%s'.\n"), optarg
);
613 i
= strtol (optarg
, &p
, 0);
614 if (i
== 0 && p
== optarg
)
616 /* Don't use *_filtered or warning() (which relies on
617 current_target) until after initialize_all_files(). */
621 _("warning: could not set timeout limit to `%s'.\n"), optarg
);
628 fprintf_unfiltered (gdb_stderr
,
629 _("Use `%s --help' for a complete list of options.\n"),
635 /* If --help or --version, disable window interface. */
636 if (print_help
|| print_version
)
643 /* The remaining options are the command-line options for the
644 inferior. The first one is the sym/exec file, and the rest
648 fprintf_unfiltered (gdb_stderr
,
649 _("%s: `--args' specified but no program specified\n"),
653 symarg
= argv
[optind
];
654 execarg
= argv
[optind
];
656 set_inferior_args_vector (argc
- optind
, &argv
[optind
]);
660 /* OK, that's all the options. */
662 /* The first argument, if specified, is the name of the
666 symarg
= argv
[optind
];
667 execarg
= argv
[optind
];
671 /* If the user hasn't already specified a PID or the name of a
672 core file, then a second optional argument is allowed. If
673 present, this argument should be interpreted as either a
674 PID or a core file, whichever works. */
675 if (pidarg
== NULL
&& corearg
== NULL
&& optind
< argc
)
677 pid_or_core_arg
= argv
[optind
];
681 /* Any argument left on the command line is unexpected and
682 will be ignored. Inform the user. */
684 fprintf_unfiltered (gdb_stderr
, _("\
685 Excess command line arguments ignored. (%s%s)\n"),
687 (optind
== argc
- 1) ? "" : " ...");
693 /* Initialize all files. Give the interpreter a chance to take
694 control of the console via the deprecated_init_ui_hook (). */
697 /* Do these (and anything which might call wrap_here or *_filtered)
698 after initialize_all_files() but before the interpreter has been
699 installed. Otherwize the help/version messages will be eaten by
700 the interpreter's output handler. */
704 print_gdb_version (gdb_stdout
);
706 printf_filtered ("\n");
712 print_gdb_help (gdb_stdout
);
713 fputs_unfiltered ("\n", gdb_stdout
);
717 /* FIXME: cagney/2003-02-03: The big hack (part 1 of 2) that lets
718 GDB retain the old MI1 interpreter startup behavior. Output the
719 copyright message before the interpreter is installed. That way
720 it isn't encapsulated in MI output. */
721 if (!quiet
&& strcmp (interpreter_p
, INTERP_MI1
) == 0)
723 /* Print all the junk at the top, with trailing "..." if we are about
724 to read a symbol file (possibly slowly). */
725 print_gdb_version (gdb_stdout
);
727 printf_filtered ("..");
729 printf_filtered ("\n");
730 gdb_flush (gdb_stdout
); /* Force to screen during slow operations */
734 /* Install the default UI. All the interpreters should have had a
735 look at things by now. Initialize the default interpreter. */
739 struct interp
*interp
= interp_lookup (interpreter_p
);
741 error (_("Interpreter `%s' unrecognized"), interpreter_p
);
743 if (!interp_set (interp
, 1))
745 fprintf_unfiltered (gdb_stderr
,
746 "Interpreter `%s' failed to initialize.\n",
752 /* FIXME: cagney/2003-02-03: The big hack (part 2 of 2) that lets
753 GDB retain the old MI1 interpreter startup behavior. Output the
754 copyright message after the interpreter is installed when it is
755 any sane interpreter. */
756 if (!quiet
&& !current_interp_named_p (INTERP_MI1
))
758 /* Print all the junk at the top, with trailing "..." if we are about
759 to read a symbol file (possibly slowly). */
760 print_gdb_version (gdb_stdout
);
762 printf_filtered ("..");
764 printf_filtered ("\n");
765 gdb_flush (gdb_stdout
); /* Force to screen during slow operations */
768 /* Set off error and warning messages with a blank line. */
769 error_pre_print
= "\n";
770 quit_pre_print
= error_pre_print
;
771 warning_pre_print
= _("\nwarning: ");
773 /* Read and execute the system-wide gdbinit file, if it exists.
774 This is done *before* all the command line arguments are
775 processed; it sets global parameters, which are independent of
776 what file you are debugging or what directory you are in. */
777 if (system_gdbinit
&& !inhibit_gdbinit
)
778 catch_command_errors (source_script
, system_gdbinit
, 0, RETURN_MASK_ALL
);
780 /* Read and execute $HOME/.gdbinit file, if it exists. This is done
781 *before* all the command line arguments are processed; it sets
782 global parameters, which are independent of what file you are
783 debugging or what directory you are in. */
785 if (home_gdbinit
&& !inhibit_gdbinit
)
786 catch_command_errors (source_script
, home_gdbinit
, 0, RETURN_MASK_ALL
);
788 /* Now perform all the actions indicated by the arguments. */
791 catch_command_errors (cd_command
, cdarg
, 0, RETURN_MASK_ALL
);
794 for (i
= 0; i
< ndir
; i
++)
795 catch_command_errors (directory_switch
, dirarg
[i
], 0, RETURN_MASK_ALL
);
800 && strcmp (execarg
, symarg
) == 0)
802 /* The exec file and the symbol-file are the same. If we can't
803 open it, better only print one error message.
804 catch_command_errors returns non-zero on success! */
805 if (catch_command_errors (exec_file_attach
, execarg
, !batch
, RETURN_MASK_ALL
))
806 catch_command_errors (symbol_file_add_main
, symarg
, 0, RETURN_MASK_ALL
);
811 catch_command_errors (exec_file_attach
, execarg
, !batch
, RETURN_MASK_ALL
);
813 catch_command_errors (symbol_file_add_main
, symarg
, 0, RETURN_MASK_ALL
);
816 if (corearg
&& pidarg
)
818 Can't attach to process and specify a core file at the same time."));
821 catch_command_errors (core_file_command
, corearg
,
822 !batch
, RETURN_MASK_ALL
);
823 else if (pidarg
!= NULL
)
824 catch_command_errors (attach_command
, pidarg
,
825 !batch
, RETURN_MASK_ALL
);
826 else if (pid_or_core_arg
)
828 /* The user specified 'gdb program pid' or gdb program core'.
829 If pid_or_core_arg's first character is a digit, try attach
830 first and then corefile. Otherwise try just corefile. */
832 if (isdigit (pid_or_core_arg
[0]))
834 if (catch_command_errors (attach_command
, pid_or_core_arg
,
835 !batch
, RETURN_MASK_ALL
) == 0)
836 catch_command_errors (core_file_command
, pid_or_core_arg
,
837 !batch
, RETURN_MASK_ALL
);
839 else /* Can't be a pid, better be a corefile. */
840 catch_command_errors (core_file_command
, pid_or_core_arg
,
841 !batch
, RETURN_MASK_ALL
);
845 catch_command_errors (tty_command
, ttyarg
, !batch
, RETURN_MASK_ALL
);
847 /* Error messages should no longer be distinguished with extra output. */
848 error_pre_print
= NULL
;
849 quit_pre_print
= NULL
;
850 warning_pre_print
= _("warning: ");
852 /* Read the .gdbinit file in the current directory, *if* it isn't
853 the same as the $HOME/.gdbinit file (it should exist, also). */
854 if (local_gdbinit
&& !inhibit_gdbinit
)
855 catch_command_errors (source_script
, local_gdbinit
, 0, RETURN_MASK_ALL
);
857 for (i
= 0; i
< ncmd
; i
++)
859 if (cmdarg
[i
].type
== CMDARG_FILE
)
860 catch_command_errors (source_script
, cmdarg
[i
].string
,
861 !batch
, RETURN_MASK_ALL
);
862 else /* cmdarg[i].type == CMDARG_COMMAND */
863 catch_command_errors (execute_command
, cmdarg
[i
].string
,
864 !batch
, RETURN_MASK_ALL
);
868 /* Read in the old history after all the command files have been read. */
873 /* We have hit the end of the batch file. */
874 quit_force (NULL
, 0);
877 /* Show time and/or space usage. */
881 long init_time
= get_run_time () - time_at_startup
;
883 printf_unfiltered (_("Startup time: %ld.%06ld\n"),
884 init_time
/ 1000000, init_time
% 1000000);
890 extern char **environ
;
891 char *lim
= (char *) sbrk (0);
893 printf_unfiltered (_("Startup size: data size %ld\n"),
894 (long) (lim
- (char *) &environ
));
898 /* NOTE: cagney/1999-11-07: There is probably no reason for not
899 moving this loop and the code found in captured_command_loop()
900 into the command_loop() proper. The main thing holding back that
901 change - SET_TOP_LEVEL() - has been eliminated. */
904 catch_errors (captured_command_loop
, 0, "", RETURN_MASK_ALL
);
906 /* No exit -- exit is through quit_command. */
910 gdb_main (struct captured_main_args
*args
)
912 use_windows
= args
->use_windows
;
913 catch_errors (captured_main
, args
, "", RETURN_MASK_ALL
);
914 /* The only way to end up here is by an error (normal exit is
915 handled by quit_force()), hence always return an error status. */
920 /* Don't use *_filtered for printing help. We don't want to prompt
921 for continue no matter how small the screen or how much we're going
925 print_gdb_help (struct ui_file
*stream
)
927 char *system_gdbinit
;
931 get_init_files (&system_gdbinit
, &home_gdbinit
, &local_gdbinit
);
933 fputs_unfiltered (_("\
934 This is the GNU debugger. Usage:\n\n\
935 gdb [options] [executable-file [core-file or process-id]]\n\
936 gdb [options] --args executable-file [inferior-arguments ...]\n\n\
939 fputs_unfiltered (_("\
940 --args Arguments after executable-file are passed to inferior\n\
942 fputs_unfiltered (_("\
943 -b BAUDRATE Set serial port baud rate used for remote debugging.\n\
944 --batch Exit after processing options.\n\
945 --batch-silent As for --batch, but suppress all gdb stdout output.\n\
946 --return-child-result\n\
947 GDB exit code will be the child's exit code.\n\
948 --cd=DIR Change current directory to DIR.\n\
949 --command=FILE, -x Execute GDB commands from FILE.\n\
950 --eval-command=COMMAND, -ex\n\
951 Execute a single GDB command.\n\
952 May be used multiple times and in conjunction\n\
954 --core=COREFILE Analyze the core dump COREFILE.\n\
955 --pid=PID Attach to running process PID.\n\
957 fputs_unfiltered (_("\
958 --dbx DBX compatibility mode.\n\
959 --directory=DIR Search for source files in DIR.\n\
960 --epoch Output information used by epoch emacs-GDB interface.\n\
961 --exec=EXECFILE Use EXECFILE as the executable.\n\
962 --fullname Output information used by emacs-GDB interface.\n\
963 --help Print this message.\n\
965 fputs_unfiltered (_("\
966 --interpreter=INTERP\n\
967 Select a specific interpreter / user interface\n\
969 fputs_unfiltered (_("\
970 -l TIMEOUT Set timeout in seconds for remote debugging.\n\
971 --nw Do not use a window interface.\n\
972 --nx Do not read "), stream
);
973 fputs_unfiltered (gdbinit
, stream
);
974 fputs_unfiltered (_(" file.\n\
975 --quiet Do not print version number on startup.\n\
976 --readnow Fully read symbol files on first access.\n\
978 fputs_unfiltered (_("\
979 --se=FILE Use FILE as symbol file and executable file.\n\
980 --symbols=SYMFILE Read symbols from SYMFILE.\n\
981 --tty=TTY Use TTY for input/output by the program being debugged.\n\
984 fputs_unfiltered (_("\
985 --tui Use a terminal user interface.\n\
988 fputs_unfiltered (_("\
989 --version Print version information and then exit.\n\
990 -w Use a window interface.\n\
991 --write Set writing into executable and core files.\n\
992 --xdb XDB compatibility mode.\n\
994 fputs_unfiltered (_("\n\
995 At startup, GDB reads the following init files and executes their commands:\n\
998 fprintf_unfiltered (stream
, _("\
999 * system-wide init file: %s\n\
1000 "), system_gdbinit
);
1002 fprintf_unfiltered (stream
, _("\
1003 * user-specific init file: %s\n\
1006 fprintf_unfiltered (stream
, _("\
1007 * local init file: ./%s\n\
1009 fputs_unfiltered (_("\n\
1010 For more information, type \"help\" from within GDB, or consult the\n\
1011 GDB manual (available as on-line info or a printed manual).\n\
1013 if (REPORT_BUGS_TO
[0] && stream
== gdb_stdout
)
1014 fprintf_unfiltered (stream
, _("\
1015 Report bugs to \"%s\".\n\
1016 "), REPORT_BUGS_TO
);