28 #include <sys/types.h>
42 #include "filenames.h"
114 if (stat (new_datadir, &st) < 0)
116 int save_errno = errno;
121 else if (!S_ISDIR (st.st_mode))
122 warning (
_(
"%s is not a directory."), new_datadir);
150 return make_relative_prefix (progname,
BINDIR, initial);
151 return xstrdup (initial);
170 if (*dir ==
'\0' || stat (dir, &s) != 0 || !S_ISDIR (s.st_mode))
177 dir = xstrdup (initial);
182 char *canon_sysroot = lrealpath (dir);
201 const char **home_gdbinit,
202 const char **local_gdbinit)
204 static const char *sysgdbinit = NULL;
205 static char *homeinit = NULL;
206 static const char *localinit = NULL;
207 static int initialized = 0;
211 struct stat homebuf, cwdbuf, s;
218 char *relocated_sysgdbinit;
223 && datadir_len < sys_gdbinit_len
232 for (p = tmp_sys_gdbinit; IS_DIR_SEPARATOR (*p); ++p)
236 xfree (tmp_sys_gdbinit);
244 if (relocated_sysgdbinit && stat (relocated_sysgdbinit, &s) == 0)
245 sysgdbinit = relocated_sysgdbinit;
247 xfree (relocated_sysgdbinit);
250 homedir = getenv (
"HOME");
258 memset (&homebuf, 0,
sizeof (
struct stat));
259 memset (&cwdbuf, 0,
sizeof (
struct stat));
264 if (stat (homeinit, &homebuf) != 0)
271 if (stat (
gdbinit, &cwdbuf) == 0)
274 || memcmp ((
char *) &homebuf, (
char *) &cwdbuf,
275 sizeof (
struct stat)))
282 *system_gdbinit = sysgdbinit;
283 *home_gdbinit = homeinit;
284 *local_gdbinit = localinit;
297 #ifdef HAVE_SIGALTSTACK
301 ss.ss_size = SIGSTKSZ;
304 sigaltstack(&ss, NULL);
362 char *arg,
int from_tty)
368 command (arg, from_tty);
389 const char *arg,
int from_tty)
395 command (arg, from_tty);
443 static int quiet = 0;
444 static int set_args = 0;
445 static int inhibit_home_gdbinit = 0;
449 char *execarg = NULL;
451 char *corearg = NULL;
452 char *pid_or_core_arg = NULL;
458 static int print_help;
459 static int print_version;
460 static int print_configuration;
474 const char *system_gdbinit;
475 const char *home_gdbinit;
476 const char *local_gdbinit;
482 struct cleanup *pre_stat_chain;
491 #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
492 setlocale (LC_MESSAGES,
"");
494 #if defined (HAVE_SETLOCALE)
495 setlocale (LC_CTYPE,
"");
505 dirarg = (
char **)
xmalloc (dirsize *
sizeof (*dirarg));
516 setvbuf (stderr, NULL, _IONBF, BUFSIZ);
560 #ifdef WITH_PYTHON_PATH
599 static struct option long_options[] =
601 {
"tui", no_argument, 0, OPT_TUI},
605 {
"quiet", no_argument, &quiet, 1},
606 {
"q", no_argument, &quiet, 1},
607 {
"silent", no_argument, &quiet, 1},
608 {
"nh", no_argument, &inhibit_home_gdbinit, 1},
611 {
"batch-silent", no_argument, 0,
'B'},
617 {
"fullname", no_argument, 0,
'f'},
618 {
"f", no_argument, 0,
'f'},
620 {
"annotate", required_argument, 0, OPT_ANNOTATE},
621 {
"help", no_argument, &print_help, 1},
622 {
"se", required_argument, 0, OPT_SE},
623 {
"symbols", required_argument, 0,
's'},
624 {
"s", required_argument, 0,
's'},
625 {
"exec", required_argument, 0,
'e'},
626 {
"e", required_argument, 0,
'e'},
627 {
"core", required_argument, 0,
'c'},
628 {
"c", required_argument, 0,
'c'},
629 {
"pid", required_argument, 0,
'p'},
630 {
"p", required_argument, 0,
'p'},
631 {
"command", required_argument, 0,
'x'},
632 {
"eval-command", required_argument, 0,
'X'},
633 {
"version", no_argument, &print_version, 1},
634 {
"configuration", no_argument, &print_configuration, 1},
635 {
"x", required_argument, 0,
'x'},
636 {
"ex", required_argument, 0,
'X'},
637 {
"init-command", required_argument, 0, OPT_IX},
638 {
"init-eval-command", required_argument, 0, OPT_IEX},
639 {
"ix", required_argument, 0, OPT_IX},
640 {
"iex", required_argument, 0, OPT_IEX},
642 {
"tclcommand", required_argument, 0,
'z'},
643 {
"enable-external-editor", no_argument, 0,
'y'},
644 {
"editor-command", required_argument, 0,
'w'},
646 {
"ui", required_argument, 0,
'i'},
647 {
"interpreter", required_argument, 0,
'i'},
648 {
"i", required_argument, 0,
'i'},
649 {
"directory", required_argument, 0,
'd'},
650 {
"d", required_argument, 0,
'd'},
651 {
"data-directory", required_argument, 0,
'D'},
652 {
"D", required_argument, 0,
'D'},
653 {
"cd", required_argument, 0, OPT_CD},
654 {
"tty", required_argument, 0,
't'},
655 {
"baud", required_argument, 0,
'b'},
656 {
"b", required_argument, 0,
'b'},
657 {
"nw", no_argument, NULL, OPT_NOWINDOWS},
658 {
"nowindows", no_argument, NULL, OPT_NOWINDOWS},
659 {
"w", no_argument, NULL, OPT_WINDOWS},
660 {
"windows", no_argument, NULL, OPT_WINDOWS},
661 {
"statistics", no_argument, 0, OPT_STATISTICS},
663 {
"args", no_argument, &set_args, 1},
664 {
"l", required_argument, 0,
'l'},
666 {0, no_argument, 0, 0}
673 c = getopt_long_only (argc, argv,
"",
674 long_options, &option_index);
675 if (c == EOF || set_args)
679 if (c == 0 && long_options[option_index].flag == 0)
680 c = long_options[option_index].val;
774 if (optarg[0] ==
'\0')
775 error (
_(
"%s: empty path for `--data-directory'"),
783 extern int gdbtk_test (
char *);
785 if (!gdbtk_test (optarg))
786 error (
_(
"%s: unable to load tclcommand file \"%s\""),
797 extern char *external_editor_command;
799 external_editor_command = xstrdup (optarg);
808 dirarg[ndir++] = optarg;
812 dirarg = (
char **)
xrealloc ((
char *) dirarg,
813 dirsize *
sizeof (*dirarg));
827 i = strtol (optarg, &p, 0);
828 if (i == 0 && p == optarg)
829 warning (
_(
"could not set baud rate to `%s'."),
840 i = strtol (optarg, &p, 0);
841 if (i == 0 && p == optarg)
842 warning (
_(
"could not set timeout limit to `%s'."),
850 error (
_(
"Use `%s --help' for a complete list of options."),
873 error (
_(
"%s: `--args' specified but no program specified"),
876 symarg = argv[optind];
877 execarg = argv[optind];
889 symarg = argv[optind];
890 execarg = argv[optind];
898 if (pidarg == NULL && corearg == NULL && optind < argc)
900 pid_or_core_arg = argv[optind];
908 _(
"Excess command line "
909 "arguments ignored. (%s%s)\n"),
911 (optind == argc - 1) ?
"" :
" ...");
939 if (print_configuration)
1016 switch (cmdarg_p->
type)
1034 for (i = 0; i < ndir; i++)
1046 && strcmp (execarg, symarg) == 0)
1058 if (execarg != NULL)
1066 if (corearg && pidarg)
1067 error (
_(
"Can't attach to process and specify "
1068 "a core file at the same time."));
1070 if (corearg != NULL)
1072 else if (pidarg != NULL)
1074 else if (pid_or_core_arg)
1080 if (isdigit (pid_or_core_arg[0]))
1106 _(
"auto-load: Loading .gdbinit "
1126 switch (cmdarg_p->
type)
1179 const char *system_gdbinit;
1180 const char *home_gdbinit;
1181 const char *local_gdbinit;
1189 This is the GNU debugger. Usage:\n\n\
1190 gdb [options] [executable-file [core-file or process-id]]\n\
1191 gdb [options] --args executable-file [inferior-arguments ...]\n\n\
1194 Selection of debuggee and its files:\n\n\
1195 --args Arguments after executable-file are passed to inferior\n\
1196 --core=COREFILE Analyze the core dump COREFILE.\n\
1197 --exec=EXECFILE Use EXECFILE as the executable.\n\
1198 --pid=PID Attach to running process PID.\n\
1199 --directory=DIR Search for source files in DIR.\n\
1200 --se=FILE Use FILE as symbol file and executable file.\n\
1201 --symbols=SYMFILE Read symbols from SYMFILE.\n\
1202 --readnow Fully read symbol files on first access.\n\
1203 --write Set writing into executable and core files.\n\n\
1206 Initial commands and command files:\n\n\
1207 --command=FILE, -x Execute GDB commands from FILE.\n\
1208 --init-command=FILE, -ix\n\
1209 Like -x but execute commands before loading inferior.\n\
1210 --eval-command=COMMAND, -ex\n\
1211 Execute a single GDB command.\n\
1212 May be used multiple times and in conjunction\n\
1214 --init-eval-command=COMMAND, -iex\n\
1215 Like -ex but before loading inferior.\n\
1216 --nh Do not read ~/.gdbinit.\n\
1217 --nx Do not read any .gdbinit files in any directory.\n\n\
1220 Output and user interface control:\n\n\
1221 --fullname Output information used by emacs-GDB interface.\n\
1222 --interpreter=INTERP\n\
1223 Select a specific interpreter / user interface\n\
1224 --tty=TTY Use TTY for input/output by the program being debugged.\n\
1225 -w Use the GUI interface.\n\
1226 --nw Do not use the GUI interface.\n\
1230 --tui Use a terminal user interface.\n\
1234 --dbx DBX compatibility mode.\n\
1235 -q, --quiet, --silent\n\
1236 Do not print version number on startup.\n\n\
1239 Operating modes:\n\n\
1240 --batch Exit after processing options.\n\
1241 --batch-silent Like --batch, but suppress all gdb stdout output.\n\
1242 --return-child-result\n\
1243 GDB exit code will be the child's exit code.\n\
1244 --configuration Print details about GDB configuration and then exit.\n\
1245 --help Print this message and then exit.\n\
1246 --version Print version information and then exit.\n\n\
1247 Remote debugging options:\n\n\
1248 -b BAUDRATE Set serial port baud rate used for remote debugging.\n\
1249 -l TIMEOUT Set timeout in seconds for remote debugging.\n\n\
1251 --cd=DIR Change current directory to DIR.\n\
1252 --data-directory=DIR, -D\n\
1253 Set GDB's data-directory to DIR.\n\
1256 At startup, GDB reads the following init files and executes their commands:\n\
1260 * system-wide init file: %s\n\
1261 "), system_gdbinit);
1264 * user-specific init file: %s\n\
1268 * local init file (see also 'set auto-load local-gdbinit'): ./%s\n\
1271 For more information, type \"help\" from within GDB, or consult the\n\
1272 GDB manual (available as on-line info or a printed manual).\n\
1276 Report bugs to \"%s\".\n\
int gdb_main(struct captured_main_args *args)
char * gdb_realpath(const char *filename)
void notice_open_fds(void)
int saved_command_line_size
static void get_init_files(const char **system_gdbinit, const char **home_gdbinit, const char **local_gdbinit)
char * gdb_abspath(const char *path)
struct ui_file * gdb_stdin
static char * gdb_program_name
static int gdb_datadir_provided
void fputs_unfiltered(const char *buf, struct ui_file *file)
#define textdomain(Domainname)
void clear_quit_flag(void)
void warning(const char *fmt,...)
void( catch_command_errors_const_ftype)(const char *, int)
void async_enable_stdin(void)
int auto_load_local_gdbinit_loaded
char * relocate_gdb_directory(const char *initial, int flag)
struct ui_file * gdb_stdout
struct ui_file * gdb_stdtargin
void print_sys_errmsg(const char *string, int errcode)
void quit_force(char *args, int from_tty)
void set_inferior_io_terminal(const char *terminal_name)
int catch_errors(catch_errors_ftype *func, void *func_args, char *errstring, return_mask mask)
void set_per_command_time(int new_value)
#define VEC_safe_push(T, V, O)
void print_gdb_configuration(struct ui_file *stream)
static int catch_command_errors(catch_command_errors_ftype *command, char *arg, int from_tty)
char * auto_load_local_gdbinit_pathname
void core_file_command(char *filename, int from_tty)
void execute_command(char *, int)
char * debug_file_directory
void printf_filtered(const char *format,...)
static char * relocate_path(const char *progname, const char *initial, int flag)
#define TARGET_SYSROOT_PREFIX
struct cleanup * all_cleanups(void)
#define TARGET_SYSTEM_ROOT_RELOCATABLE
static int captured_main(void *data)
struct ui_file * stderr_fileopen(void)
#define ALL_OBJFILES(obj)
int interp_set(struct interp *interp, int top_level)
#define VEC_iterate(T, V, I, P)
static void print_gdb_help(struct ui_file *)
void set_gdb_data_directory(const char *new_datadir)
int auto_load_local_gdbinit
#define CATCH(EXCEPTION, MASK)
void load_auto_scripts_for_objfile(struct objfile *objfile)
struct ui_file * ui_file_new(void)
void fprintf_unfiltered(struct ui_file *stream, const char *format,...)
void cd_command(char *dir, int from_tty)
void exception_print(struct ui_file *file, struct gdb_exception e)
struct cleanup * make_cleanup(make_cleanup_ftype *function, void *arg)
void print_gdb_version(struct ui_file *stream)
#define GDB_DATADIR_RELOCATABLE
void( catch_command_errors_ftype)(char *, int)
void add_substitute_path_rule(char *from, char *to)
void source_script(const char *file, int from_tty)
void perror_warning_with_name(const char *string)
const char * get_gdb_program_name(void)
char * xstrprintf(const char *format,...)
void wrap_here(char *indent)
int file_is_auto_load_safe(const char *filename, const char *debug_fmt,...)
static void setup_alternate_signal_stack(void)
void maybe_wait_sync_command_done(int was_sync)
struct ui_file * gdb_stdlog
#define DEBUGDIR_RELOCATABLE
void symbol_file_add_main(const char *args, int from_tty)
struct interp * interp_lookup(const char *name)
#define SYSTEM_GDBINIT_RELOCATABLE
void set_inferior_args_vector(int argc, char **argv)
PTR xrealloc(PTR ptr, size_t size)
#define PYTHON_PATH_RELOCATABLE
const char const char int
void exec_file_attach(const char *filename, int from_tty)
void attach_command(char *args, int from_tty)
char * windows_get_absolute_argv0(const char *argv0)
#define bindtextdomain(Domainname, Dirname)
const char * interpreter_p
struct cleanup * make_command_stats_cleanup(int msg_type)
static int catch_command_errors_const(catch_command_errors_const_ftype *command, const char *arg, int from_tty)
struct ui_file * gdb_stderr
static int handle_command_errors(struct gdb_exception e)
#define TARGET_SYSTEM_ROOT
void quit_command(char *args, int from_tty)
struct ui_file * gdb_stdtarg
void directory_switch(char *, int)
void set_per_command_space(int new_value)
static int captured_command_loop(void *data)
void gdb_init(char *argv0)
struct ui_file * gdb_stdtargerr
void gdb_flush(struct ui_file *file)
struct ui_file * stdio_fileopen(FILE *file)
char * saved_command_line
void current_interp_command_loop(void)
int current_interp_named_p(const char *interp_name)
void error(const char *fmt,...)
int return_child_result_value
void do_cleanups(struct cleanup *old_chain)
enum return_reason reason