1 /* Top level stuff for GDB, the GNU debugger.
3 Copyright (C) 1986-2005, 2007-2012 Free Software Foundation, Inc.
5 This file is part of GDB.
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 3 of the License, or
10 (at your option) any later version.
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.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
27 #include "exceptions.h"
30 #include <sys/types.h>
34 #include "gdb_string.h"
35 #include "event-loop.h"
41 #include "cli/cli-cmds.h"
42 #include "python/python.h"
44 #include "auto-load.h"
46 /* The selected interpreter. This will be used as a set command
47 variable, so it should always be malloc'ed - since
48 do_setshow_command will free it. */
51 /* Whether xdb commands will be handled. */
54 /* Whether dbx commands will be handled. */
57 /* System root path, used to find libraries etc. */
58 char *gdb_sysroot
= 0;
60 /* GDB datadir, used to store data files. */
61 char *gdb_datadir
= 0;
63 /* If gdb was configured with --with-python=/path,
64 the possibly relocated path to python's lib directory. */
65 char *python_libdir
= 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 /* True if --batch or --batch-silent was seen. */
79 /* Support for the --batch-silent option. */
82 /* Support for --return-child-result option.
83 Set the default to -1 to return error in the case
84 that the program does not run or does not complete. */
85 int return_child_result
= 0;
86 int return_child_result_value
= -1;
89 /* GDB as it has been invoked from the command line (i.e. argv[0]). */
90 static char *gdb_program_name
;
92 static void print_gdb_help (struct ui_file
*);
94 /* Relocate a file or directory. PROGNAME is the name by which gdb
95 was invoked (i.e., argv[0]). INITIAL is the default value for the
96 file or directory. FLAG is true if the value is relocatable, false
97 otherwise. Returns a newly allocated string; this may return NULL
98 under the same conditions as make_relative_prefix. */
101 relocate_path (const char *progname
, const char *initial
, int flag
)
104 return make_relative_prefix (progname
, BINDIR
, initial
);
105 return xstrdup (initial
);
108 /* Like relocate_path, but specifically checks for a directory.
109 INITIAL is relocated according to the rules of relocate_path. If
110 the result is a directory, it is used; otherwise, INITIAL is used.
111 The chosen directory is then canonicalized using lrealpath. This
112 function always returns a newly-allocated string. */
115 relocate_gdb_directory (const char *initial
, int flag
)
119 dir
= relocate_path (gdb_program_name
, initial
, flag
);
124 if (stat (dir
, &s
) != 0 || !S_ISDIR (s
.st_mode
))
131 dir
= xstrdup (initial
);
133 /* Canonicalize the directory. */
136 char *canon_sysroot
= lrealpath (dir
);
148 /* Compute the locations of init files that GDB should source and
149 return them in SYSTEM_GDBINIT, HOME_GDBINIT, LOCAL_GDBINIT. If
150 there is no system gdbinit (resp. home gdbinit and local gdbinit)
151 to be loaded, then SYSTEM_GDBINIT (resp. HOME_GDBINIT and
152 LOCAL_GDBINIT) is set to NULL. */
154 get_init_files (char **system_gdbinit
,
156 char **local_gdbinit
)
158 static char *sysgdbinit
= NULL
;
159 static char *homeinit
= NULL
;
160 static char *localinit
= NULL
;
161 static int initialized
= 0;
165 struct stat homebuf
, cwdbuf
, s
;
166 char *homedir
, *relocated_sysgdbinit
;
168 if (SYSTEM_GDBINIT
[0])
170 relocated_sysgdbinit
= relocate_path (gdb_program_name
,
172 SYSTEM_GDBINIT_RELOCATABLE
);
173 if (relocated_sysgdbinit
&& stat (relocated_sysgdbinit
, &s
) == 0)
174 sysgdbinit
= relocated_sysgdbinit
;
176 xfree (relocated_sysgdbinit
);
179 homedir
= getenv ("HOME");
181 /* If the .gdbinit file in the current directory is the same as
182 the $HOME/.gdbinit file, it should not be sourced. homebuf
183 and cwdbuf are used in that purpose. Make sure that the stats
184 are zero in case one of them fails (this guarantees that they
185 won't match if either exists). */
187 memset (&homebuf
, 0, sizeof (struct stat
));
188 memset (&cwdbuf
, 0, sizeof (struct stat
));
192 homeinit
= xstrprintf ("%s/%s", homedir
, gdbinit
);
193 if (stat (homeinit
, &homebuf
) != 0)
200 if (stat (gdbinit
, &cwdbuf
) == 0)
203 || memcmp ((char *) &homebuf
, (char *) &cwdbuf
,
204 sizeof (struct stat
)))
211 *system_gdbinit
= sysgdbinit
;
212 *home_gdbinit
= homeinit
;
213 *local_gdbinit
= localinit
;
216 /* Call command_loop. If it happens to return, pass that through as a
217 non-zero return status. */
220 captured_command_loop (void *data
)
222 /* Top-level execution commands can be run on the background from
224 interpreter_async
= 1;
226 current_interp_command_loop ();
227 /* FIXME: cagney/1999-11-05: A correct command_loop() implementaton
228 would clean things up (restoring the cleanup chain) to the state
229 they were just prior to the call. Technically, this means that
230 the do_cleanups() below is redundant. Unfortunately, many FUNCs
231 are not that well behaved. do_cleanups should either be replaced
232 with a do_cleanups call (to cover the problem) or an assertion
233 check to detect bad FUNCs code. */
234 do_cleanups (all_cleanups ());
235 /* If the command_loop returned, normally (rather than threw an
236 error) we try to quit. If the quit is aborted, catch_errors()
237 which called this catch the signal and restart the command
239 quit_command (NULL
, instream
== stdin
);
243 /* Arguments of --command option and its counterpart. */
244 typedef struct cmdarg
{
245 /* Type of this option. */
247 /* Option type -x. */
250 /* Option type -ex. */
253 /* Option type -ix. */
256 /* Option type -iex. */
260 /* Value of this option - filename or the GDB command itself. String memory
261 is not owned by this structure despite it is 'const'. */
265 /* Define type VEC (cmdarg_s). */
266 DEF_VEC_O (cmdarg_s
);
269 captured_main (void *data
)
271 struct captured_main_args
*context
= data
;
272 int argc
= context
->argc
;
273 char **argv
= context
->argv
;
274 static int quiet
= 0;
275 static int set_args
= 0;
276 static int inhibit_home_gdbinit
= 0;
278 /* Pointers to various arguments from command line. */
280 char *execarg
= NULL
;
282 char *corearg
= NULL
;
283 char *pid_or_core_arg
= NULL
;
287 /* These are static so that we can take their address in an
289 static int print_help
;
290 static int print_version
;
292 /* Pointers to all arguments of --command option. */
293 VEC (cmdarg_s
) *cmdarg_vec
= NULL
;
294 struct cmdarg
*cmdarg_p
;
296 /* Indices of all arguments of --directory option. */
298 /* Allocated size. */
300 /* Number of elements used. */
303 /* gdb init files. */
304 char *system_gdbinit
;
310 struct objfile
*objfile
;
312 struct cleanup
*pre_stat_chain
;
315 /* Set this before calling make_command_stats_cleanup. */
316 lim_at_start
= (char *) sbrk (0);
319 pre_stat_chain
= make_command_stats_cleanup (0);
321 #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
322 setlocale (LC_MESSAGES
, "");
324 #if defined (HAVE_SETLOCALE)
325 setlocale (LC_CTYPE
, "");
327 bindtextdomain (PACKAGE
, LOCALEDIR
);
328 textdomain (PACKAGE
);
330 make_cleanup (VEC_cleanup (cmdarg_s
), &cmdarg_vec
);
332 dirarg
= (char **) xmalloc (dirsize
* sizeof (*dirarg
));
336 saved_command_line
= (char *) xmalloc (saved_command_line_size
);
337 saved_command_line
[0] = '\0';
340 gdb_stdout
= stdio_fileopen (stdout
);
341 gdb_stderr
= stdio_fileopen (stderr
);
342 gdb_stdlog
= gdb_stderr
; /* for moment */
343 gdb_stdtarg
= gdb_stderr
; /* for moment */
344 gdb_stdin
= stdio_fileopen (stdin
);
345 gdb_stdtargerr
= gdb_stderr
; /* for moment */
346 gdb_stdtargin
= gdb_stdin
; /* for moment */
348 gdb_program_name
= xstrdup (argv
[0]);
350 if (! getcwd (gdb_dirbuf
, sizeof (gdb_dirbuf
)))
351 /* Don't use *_filtered or warning() (which relies on
352 current_target) until after initialize_all_files(). */
353 fprintf_unfiltered (gdb_stderr
,
354 _("%s: warning: error finding "
355 "working directory: %s\n"),
356 argv
[0], safe_strerror (errno
));
358 current_directory
= gdb_dirbuf
;
360 /* Set the sysroot path. */
361 gdb_sysroot
= relocate_gdb_directory (TARGET_SYSTEM_ROOT
,
362 TARGET_SYSTEM_ROOT_RELOCATABLE
);
364 debug_file_directory
= relocate_gdb_directory (DEBUGDIR
,
365 DEBUGDIR_RELOCATABLE
);
367 gdb_datadir
= relocate_gdb_directory (GDB_DATADIR
,
368 GDB_DATADIR_RELOCATABLE
);
370 #ifdef WITH_PYTHON_PATH
372 /* For later use in helping Python find itself. */
373 char *tmp
= concat (WITH_PYTHON_PATH
, SLASH_STRING
, "lib", NULL
);
375 python_libdir
= relocate_gdb_directory (tmp
, PYTHON_PATH_RELOCATABLE
);
381 add_substitute_path_rule (RELOC_SRCDIR
,
382 make_relative_prefix (argv
[0], BINDIR
,
386 /* There will always be an interpreter. Either the one passed into
387 this captured main, or one specified by the user at start up, or
388 the console. Initialize the interpreter to the one requested by
390 interpreter_p
= xstrdup (context
->interpreter_p
);
392 /* Parse arguments and options. */
395 /* When var field is 0, use flag field to record the equivalent
396 short option (or arbitrary numbers starting at 10 for those
397 with no equivalent). */
409 static struct option long_options
[] =
411 {"tui", no_argument
, 0, OPT_TUI
},
412 {"xdb", no_argument
, &xdb_commands
, 1},
413 {"dbx", no_argument
, &dbx_commands
, 1},
414 {"readnow", no_argument
, &readnow_symbol_files
, 1},
415 {"r", no_argument
, &readnow_symbol_files
, 1},
416 {"quiet", no_argument
, &quiet
, 1},
417 {"q", no_argument
, &quiet
, 1},
418 {"silent", no_argument
, &quiet
, 1},
419 {"nh", no_argument
, &inhibit_home_gdbinit
, 1},
420 {"nx", no_argument
, &inhibit_gdbinit
, 1},
421 {"n", no_argument
, &inhibit_gdbinit
, 1},
422 {"batch-silent", no_argument
, 0, 'B'},
423 {"batch", no_argument
, &batch_flag
, 1},
424 {"epoch", no_argument
, &epoch_interface
, 1},
426 /* This is a synonym for "--annotate=1". --annotate is now
427 preferred, but keep this here for a long time because people
428 will be running emacses which use --fullname. */
429 {"fullname", no_argument
, 0, 'f'},
430 {"f", no_argument
, 0, 'f'},
432 {"annotate", required_argument
, 0, OPT_ANNOTATE
},
433 {"help", no_argument
, &print_help
, 1},
434 {"se", required_argument
, 0, OPT_SE
},
435 {"symbols", required_argument
, 0, 's'},
436 {"s", required_argument
, 0, 's'},
437 {"exec", required_argument
, 0, 'e'},
438 {"e", required_argument
, 0, 'e'},
439 {"core", required_argument
, 0, 'c'},
440 {"c", required_argument
, 0, 'c'},
441 {"pid", required_argument
, 0, 'p'},
442 {"p", required_argument
, 0, 'p'},
443 {"command", required_argument
, 0, 'x'},
444 {"eval-command", required_argument
, 0, 'X'},
445 {"version", no_argument
, &print_version
, 1},
446 {"x", required_argument
, 0, 'x'},
447 {"ex", required_argument
, 0, 'X'},
448 {"init-command", required_argument
, 0, OPT_IX
},
449 {"init-eval-command", required_argument
, 0, OPT_IEX
},
450 {"ix", required_argument
, 0, OPT_IX
},
451 {"iex", required_argument
, 0, OPT_IEX
},
453 {"tclcommand", required_argument
, 0, 'z'},
454 {"enable-external-editor", no_argument
, 0, 'y'},
455 {"editor-command", required_argument
, 0, 'w'},
457 {"ui", required_argument
, 0, 'i'},
458 {"interpreter", required_argument
, 0, 'i'},
459 {"i", required_argument
, 0, 'i'},
460 {"directory", required_argument
, 0, 'd'},
461 {"d", required_argument
, 0, 'd'},
462 {"data-directory", required_argument
, 0, 'D'},
463 {"cd", required_argument
, 0, OPT_CD
},
464 {"tty", required_argument
, 0, 't'},
465 {"baud", required_argument
, 0, 'b'},
466 {"b", required_argument
, 0, 'b'},
467 {"nw", no_argument
, NULL
, OPT_NOWINDOWS
},
468 {"nowindows", no_argument
, NULL
, OPT_NOWINDOWS
},
469 {"w", no_argument
, NULL
, OPT_WINDOWS
},
470 {"windows", no_argument
, NULL
, OPT_WINDOWS
},
471 {"statistics", no_argument
, 0, OPT_STATISTICS
},
472 {"write", no_argument
, &write_files
, 1},
473 {"args", no_argument
, &set_args
, 1},
474 {"l", required_argument
, 0, 'l'},
475 {"return-child-result", no_argument
, &return_child_result
, 1},
476 {0, no_argument
, 0, 0}
483 c
= getopt_long_only (argc
, argv
, "",
484 long_options
, &option_index
);
485 if (c
== EOF
|| set_args
)
488 /* Long option that takes an argument. */
489 if (c
== 0 && long_options
[option_index
].flag
== 0)
490 c
= long_options
[option_index
].val
;
495 /* Long option that just sets a flag. */
505 /* FIXME: what if the syntax is wrong (e.g. not digits)? */
506 annotation_level
= atoi (optarg
);
509 /* Enable the display of both time and space usage. */
510 set_display_time (1);
511 set_display_space (1);
514 /* --tui is equivalent to -i=tui. */
516 xfree (interpreter_p
);
517 interpreter_p
= xstrdup (INTERP_TUI
);
519 fprintf_unfiltered (gdb_stderr
,
520 _("%s: TUI mode is not supported\n"),
526 /* FIXME: cagney/2003-03-01: Not sure if this option is
527 actually useful, and if it is, what it should do. */
529 /* --windows is equivalent to -i=insight. */
530 xfree (interpreter_p
);
531 interpreter_p
= xstrdup (INTERP_INSIGHT
);
536 /* -nw is equivalent to -i=console. */
537 xfree (interpreter_p
);
538 interpreter_p
= xstrdup (INTERP_CONSOLE
);
542 annotation_level
= 1;
543 /* We have probably been invoked from emacs. Disable
561 struct cmdarg cmdarg
= { CMDARG_FILE
, optarg
};
563 VEC_safe_push (cmdarg_s
, cmdarg_vec
, &cmdarg
);
568 struct cmdarg cmdarg
= { CMDARG_COMMAND
, optarg
};
570 VEC_safe_push (cmdarg_s
, cmdarg_vec
, &cmdarg
);
575 struct cmdarg cmdarg
= { CMDARG_INIT_FILE
, optarg
};
577 VEC_safe_push (cmdarg_s
, cmdarg_vec
, &cmdarg
);
582 struct cmdarg cmdarg
= { CMDARG_INIT_COMMAND
, optarg
};
584 VEC_safe_push (cmdarg_s
, cmdarg_vec
, &cmdarg
);
588 batch_flag
= batch_silent
= 1;
589 gdb_stdout
= ui_file_new();
593 gdb_datadir
= xstrdup (optarg
);
598 extern int gdbtk_test (char *);
600 if (!gdbtk_test (optarg
))
602 fprintf_unfiltered (gdb_stderr
,
603 _("%s: unable to load "
604 "tclcommand file \"%s\""),
611 /* Backwards compatibility only. */
615 /* Set the external editor commands when gdb is farming out files
616 to be edited by another program. */
617 extern char *external_editor_command
;
619 external_editor_command
= xstrdup (optarg
);
624 xfree (interpreter_p
);
625 interpreter_p
= xstrdup (optarg
);
628 dirarg
[ndir
++] = optarg
;
632 dirarg
= (char **) xrealloc ((char *) dirarg
,
633 dirsize
* sizeof (*dirarg
));
647 i
= strtol (optarg
, &p
, 0);
648 if (i
== 0 && p
== optarg
)
650 /* Don't use *_filtered or warning() (which relies on
651 current_target) until after initialize_all_files(). */
655 _("warning: could not set baud rate to `%s'.\n"), optarg
);
665 i
= strtol (optarg
, &p
, 0);
666 if (i
== 0 && p
== optarg
)
668 /* Don't use *_filtered or warning() (which relies on
669 current_target) until after initialize_all_files(). */
671 fprintf_unfiltered (gdb_stderr
,
672 _("warning: could not set "
673 "timeout limit to `%s'.\n"), optarg
);
680 fprintf_unfiltered (gdb_stderr
,
681 _("Use `%s --help' for a "
682 "complete list of options.\n"),
688 /* If --help or --version, disable window interface. */
689 if (print_help
|| print_version
)
698 /* Initialize all files. Give the interpreter a chance to take
699 control of the console via the deprecated_init_ui_hook (). */
702 /* Now that gdb_init has created the initial inferior, we're in
703 position to set args for that inferior. */
706 /* The remaining options are the command-line options for the
707 inferior. The first one is the sym/exec file, and the rest
711 fprintf_unfiltered (gdb_stderr
,
712 _("%s: `--args' specified but "
713 "no program specified\n"),
717 symarg
= argv
[optind
];
718 execarg
= argv
[optind
];
720 set_inferior_args_vector (argc
- optind
, &argv
[optind
]);
724 /* OK, that's all the options. */
726 /* The first argument, if specified, is the name of the
730 symarg
= argv
[optind
];
731 execarg
= argv
[optind
];
735 /* If the user hasn't already specified a PID or the name of a
736 core file, then a second optional argument is allowed. If
737 present, this argument should be interpreted as either a
738 PID or a core file, whichever works. */
739 if (pidarg
== NULL
&& corearg
== NULL
&& optind
< argc
)
741 pid_or_core_arg
= argv
[optind
];
745 /* Any argument left on the command line is unexpected and
746 will be ignored. Inform the user. */
748 fprintf_unfiltered (gdb_stderr
,
749 _("Excess command line "
750 "arguments ignored. (%s%s)\n"),
752 (optind
== argc
- 1) ? "" : " ...");
755 /* Lookup gdbinit files. Note that the gdbinit file name may be
756 overriden during file initialization, so get_init_files should be
757 called after gdb_init. */
758 get_init_files (&system_gdbinit
, &home_gdbinit
, &local_gdbinit
);
760 /* Do these (and anything which might call wrap_here or *_filtered)
761 after initialize_all_files() but before the interpreter has been
762 installed. Otherwize the help/version messages will be eaten by
763 the interpreter's output handler. */
767 print_gdb_version (gdb_stdout
);
769 printf_filtered ("\n");
775 print_gdb_help (gdb_stdout
);
776 fputs_unfiltered ("\n", gdb_stdout
);
780 /* FIXME: cagney/2003-02-03: The big hack (part 1 of 2) that lets
781 GDB retain the old MI1 interpreter startup behavior. Output the
782 copyright message before the interpreter is installed. That way
783 it isn't encapsulated in MI output. */
784 if (!quiet
&& strcmp (interpreter_p
, INTERP_MI1
) == 0)
786 /* Print all the junk at the top, with trailing "..." if we are
787 about to read a symbol file (possibly slowly). */
788 print_gdb_version (gdb_stdout
);
790 printf_filtered ("..");
792 printf_filtered ("\n");
793 gdb_flush (gdb_stdout
); /* Force to screen during slow
797 /* Install the default UI. All the interpreters should have had a
798 look at things by now. Initialize the default interpreter. */
802 struct interp
*interp
= interp_lookup (interpreter_p
);
805 error (_("Interpreter `%s' unrecognized"), interpreter_p
);
807 if (!interp_set (interp
, 1))
809 fprintf_unfiltered (gdb_stderr
,
810 "Interpreter `%s' failed to initialize.\n",
816 /* FIXME: cagney/2003-02-03: The big hack (part 2 of 2) that lets
817 GDB retain the old MI1 interpreter startup behavior. Output the
818 copyright message after the interpreter is installed when it is
819 any sane interpreter. */
820 if (!quiet
&& !current_interp_named_p (INTERP_MI1
))
822 /* Print all the junk at the top, with trailing "..." if we are
823 about to read a symbol file (possibly slowly). */
824 print_gdb_version (gdb_stdout
);
826 printf_filtered ("..");
828 printf_filtered ("\n");
829 gdb_flush (gdb_stdout
); /* Force to screen during slow
833 /* Set off error and warning messages with a blank line. */
834 error_pre_print
= "\n";
835 quit_pre_print
= error_pre_print
;
836 warning_pre_print
= _("\nwarning: ");
838 /* Read and execute the system-wide gdbinit file, if it exists.
839 This is done *before* all the command line arguments are
840 processed; it sets global parameters, which are independent of
841 what file you are debugging or what directory you are in. */
842 if (system_gdbinit
&& !inhibit_gdbinit
)
843 catch_command_errors (source_script
, system_gdbinit
, 0, RETURN_MASK_ALL
);
845 /* Read and execute $HOME/.gdbinit file, if it exists. This is done
846 *before* all the command line arguments are processed; it sets
847 global parameters, which are independent of what file you are
848 debugging or what directory you are in. */
850 if (home_gdbinit
&& !inhibit_gdbinit
&& !inhibit_home_gdbinit
)
851 catch_command_errors (source_script
, home_gdbinit
, 0, RETURN_MASK_ALL
);
853 /* Process '-ix' and '-iex' options early. */
854 for (i
= 0; VEC_iterate (cmdarg_s
, cmdarg_vec
, i
, cmdarg_p
); i
++)
855 switch (cmdarg_p
->type
)
857 case CMDARG_INIT_FILE
:
858 catch_command_errors (source_script
, cmdarg_p
->string
,
859 !batch_flag
, RETURN_MASK_ALL
);
861 case CMDARG_INIT_COMMAND
:
862 catch_command_errors (execute_command
, cmdarg_p
->string
,
863 !batch_flag
, RETURN_MASK_ALL
);
867 /* Now perform all the actions indicated by the arguments. */
870 catch_command_errors (cd_command
, cdarg
, 0, RETURN_MASK_ALL
);
873 for (i
= 0; i
< ndir
; i
++)
874 catch_command_errors (directory_switch
, dirarg
[i
], 0, RETURN_MASK_ALL
);
877 /* Skip auto-loading section-specified scripts until we've sourced
878 local_gdbinit (which is often used to augment the source search
880 save_auto_load
= global_auto_load
;
881 global_auto_load
= 0;
885 && strcmp (execarg
, symarg
) == 0)
887 /* The exec file and the symbol-file are the same. If we can't
888 open it, better only print one error message.
889 catch_command_errors returns non-zero on success! */
890 if (catch_command_errors (exec_file_attach
, execarg
,
891 !batch_flag
, RETURN_MASK_ALL
))
892 catch_command_errors (symbol_file_add_main
, symarg
,
893 !batch_flag
, RETURN_MASK_ALL
);
898 catch_command_errors (exec_file_attach
, execarg
,
899 !batch_flag
, RETURN_MASK_ALL
);
901 catch_command_errors (symbol_file_add_main
, symarg
,
902 !batch_flag
, RETURN_MASK_ALL
);
905 if (corearg
&& pidarg
)
906 error (_("Can't attach to process and specify "
907 "a core file at the same time."));
910 catch_command_errors (core_file_command
, corearg
,
911 !batch_flag
, RETURN_MASK_ALL
);
912 else if (pidarg
!= NULL
)
913 catch_command_errors (attach_command
, pidarg
,
914 !batch_flag
, RETURN_MASK_ALL
);
915 else if (pid_or_core_arg
)
917 /* The user specified 'gdb program pid' or gdb program core'.
918 If pid_or_core_arg's first character is a digit, try attach
919 first and then corefile. Otherwise try just corefile. */
921 if (isdigit (pid_or_core_arg
[0]))
923 if (catch_command_errors (attach_command
, pid_or_core_arg
,
924 !batch_flag
, RETURN_MASK_ALL
) == 0)
925 catch_command_errors (core_file_command
, pid_or_core_arg
,
926 !batch_flag
, RETURN_MASK_ALL
);
928 else /* Can't be a pid, better be a corefile. */
929 catch_command_errors (core_file_command
, pid_or_core_arg
,
930 !batch_flag
, RETURN_MASK_ALL
);
934 set_inferior_io_terminal (ttyarg
);
936 /* Error messages should no longer be distinguished with extra output. */
937 error_pre_print
= NULL
;
938 quit_pre_print
= NULL
;
939 warning_pre_print
= _("warning: ");
941 /* Read the .gdbinit file in the current directory, *if* it isn't
942 the same as the $HOME/.gdbinit file (it should exist, also). */
945 auto_load_local_gdbinit_pathname
= gdb_realpath (local_gdbinit
);
947 if (!inhibit_gdbinit
&& auto_load_local_gdbinit
948 && file_is_auto_load_safe (local_gdbinit
,
949 _("auto-load: Loading .gdbinit "
953 auto_load_local_gdbinit_loaded
= 1;
955 catch_command_errors (source_script
, local_gdbinit
, 0,
960 /* Now that all .gdbinit's have been read and all -d options have been
961 processed, we can read any scripts mentioned in SYMARG.
962 We wait until now because it is common to add to the source search
963 path in local_gdbinit. */
964 global_auto_load
= save_auto_load
;
965 ALL_OBJFILES (objfile
)
966 load_auto_scripts_for_objfile (objfile
);
968 /* Process '-x' and '-ex' options. */
969 for (i
= 0; VEC_iterate (cmdarg_s
, cmdarg_vec
, i
, cmdarg_p
); i
++)
970 switch (cmdarg_p
->type
)
973 catch_command_errors (source_script
, cmdarg_p
->string
,
974 !batch_flag
, RETURN_MASK_ALL
);
977 catch_command_errors (execute_command
, cmdarg_p
->string
,
978 !batch_flag
, RETURN_MASK_ALL
);
982 /* Read in the old history after all the command files have been
988 /* We have hit the end of the batch file. */
989 quit_force (NULL
, 0);
992 /* Show time and/or space usage. */
993 do_cleanups (pre_stat_chain
);
995 /* NOTE: cagney/1999-11-07: There is probably no reason for not
996 moving this loop and the code found in captured_command_loop()
997 into the command_loop() proper. The main thing holding back that
998 change - SET_TOP_LEVEL() - has been eliminated. */
1001 catch_errors (captured_command_loop
, 0, "", RETURN_MASK_ALL
);
1003 /* No exit -- exit is through quit_command. */
1007 gdb_main (struct captured_main_args
*args
)
1009 use_windows
= args
->use_windows
;
1010 catch_errors (captured_main
, args
, "", RETURN_MASK_ALL
);
1011 /* The only way to end up here is by an error (normal exit is
1012 handled by quit_force()), hence always return an error status. */
1017 /* Don't use *_filtered for printing help. We don't want to prompt
1018 for continue no matter how small the screen or how much we're going
1022 print_gdb_help (struct ui_file
*stream
)
1024 char *system_gdbinit
;
1026 char *local_gdbinit
;
1028 get_init_files (&system_gdbinit
, &home_gdbinit
, &local_gdbinit
);
1030 fputs_unfiltered (_("\
1031 This is the GNU debugger. Usage:\n\n\
1032 gdb [options] [executable-file [core-file or process-id]]\n\
1033 gdb [options] --args executable-file [inferior-arguments ...]\n\n\
1036 fputs_unfiltered (_("\
1037 --args Arguments after executable-file are passed to inferior\n\
1039 fputs_unfiltered (_("\
1040 -b BAUDRATE Set serial port baud rate used for remote debugging.\n\
1041 --batch Exit after processing options.\n\
1042 --batch-silent As for --batch, but suppress all gdb stdout output.\n\
1043 --return-child-result\n\
1044 GDB exit code will be the child's exit code.\n\
1045 --cd=DIR Change current directory to DIR.\n\
1046 --command=FILE, -x Execute GDB commands from FILE.\n\
1047 --eval-command=COMMAND, -ex\n\
1048 Execute a single GDB command.\n\
1049 May be used multiple times and in conjunction\n\
1051 --init-command=FILE, -ix Like -x but execute it before loading inferior.\n\
1052 --init-eval-command=COMMAND, -iex Like -ex but before loading inferior.\n\
1053 --core=COREFILE Analyze the core dump COREFILE.\n\
1054 --pid=PID Attach to running process PID.\n\
1056 fputs_unfiltered (_("\
1057 --dbx DBX compatibility mode.\n\
1058 --directory=DIR Search for source files in DIR.\n\
1059 --epoch Output information used by epoch emacs-GDB interface.\n\
1060 --exec=EXECFILE Use EXECFILE as the executable.\n\
1061 --fullname Output information used by emacs-GDB interface.\n\
1062 --help Print this message.\n\
1064 fputs_unfiltered (_("\
1065 --interpreter=INTERP\n\
1066 Select a specific interpreter / user interface\n\
1068 fputs_unfiltered (_("\
1069 -l TIMEOUT Set timeout in seconds for remote debugging.\n\
1070 --nw Do not use a window interface.\n\
1071 --nx Do not read any "), stream
);
1072 fputs_unfiltered (gdbinit
, stream
);
1073 fputs_unfiltered (_(" files.\n\
1074 --nh Do not read "), stream
);
1075 fputs_unfiltered (gdbinit
, stream
);
1076 fputs_unfiltered (_(" file from home directory.\n\
1077 --quiet Do not print version number on startup.\n\
1078 --readnow Fully read symbol files on first access.\n\
1080 fputs_unfiltered (_("\
1081 --se=FILE Use FILE as symbol file and executable file.\n\
1082 --symbols=SYMFILE Read symbols from SYMFILE.\n\
1083 --tty=TTY Use TTY for input/output by the program being debugged.\n\
1086 fputs_unfiltered (_("\
1087 --tui Use a terminal user interface.\n\
1090 fputs_unfiltered (_("\
1091 --version Print version information and then exit.\n\
1092 -w Use a window interface.\n\
1093 --write Set writing into executable and core files.\n\
1094 --xdb XDB compatibility mode.\n\
1096 fputs_unfiltered (_("\n\
1097 At startup, GDB reads the following init files and executes their commands:\n\
1100 fprintf_unfiltered (stream
, _("\
1101 * system-wide init file: %s\n\
1102 "), system_gdbinit
);
1104 fprintf_unfiltered (stream
, _("\
1105 * user-specific init file: %s\n\
1108 fprintf_unfiltered (stream
, _("\
1109 * local init file (see also 'set auto-load local-gdbinit'): ./%s\n\
1111 fputs_unfiltered (_("\n\
1112 For more information, type \"help\" from within GDB, or consult the\n\
1113 GDB manual (available as on-line info or a printed manual).\n\
1115 if (REPORT_BUGS_TO
[0] && stream
== gdb_stdout
)
1116 fprintf_unfiltered (stream
, _("\
1117 Report bugs to \"%s\".\n\
1118 "), REPORT_BUGS_TO
);