28 #include <sys/types.h> 42 #include "filenames.h" 112 if (stat (new_datadir, &st) < 0)
114 int save_errno = errno;
119 else if (!S_ISDIR (st.st_mode))
120 warning (
_(
"%s is not a directory."), new_datadir);
148 return make_relative_prefix (progname,
BINDIR, initial);
149 return xstrdup (initial);
168 if (*dir ==
'\0' || stat (dir, &s) != 0 || !S_ISDIR (s.st_mode))
175 dir = xstrdup (initial);
180 char *canon_sysroot = lrealpath (dir);
199 const char **home_gdbinit,
200 const char **local_gdbinit)
202 static const char *sysgdbinit = NULL;
203 static char *homeinit = NULL;
204 static const char *localinit = NULL;
205 static int initialized = 0;
209 struct stat homebuf, cwdbuf, s;
216 char *relocated_sysgdbinit;
221 && datadir_len < sys_gdbinit_len
230 for (p = tmp_sys_gdbinit; IS_DIR_SEPARATOR (*p); ++p)
234 xfree (tmp_sys_gdbinit);
242 if (relocated_sysgdbinit && stat (relocated_sysgdbinit, &s) == 0)
243 sysgdbinit = relocated_sysgdbinit;
245 xfree (relocated_sysgdbinit);
248 homedir = getenv (
"HOME");
256 memset (&homebuf, 0,
sizeof (
struct stat));
257 memset (&cwdbuf, 0,
sizeof (
struct stat));
262 if (stat (homeinit, &homebuf) != 0)
269 if (stat (
gdbinit, &cwdbuf) == 0)
272 || memcmp ((
char *) &homebuf, (
char *) &cwdbuf,
273 sizeof (
struct stat)))
280 *system_gdbinit = sysgdbinit;
281 *home_gdbinit = homeinit;
282 *local_gdbinit = localinit;
295 #ifdef HAVE_SIGALTSTACK 300 ss.ss_sp = (
char *)
xmalloc (SIGSTKSZ);
301 ss.ss_size = SIGSTKSZ;
304 sigaltstack(&ss, NULL);
372 const char *arg,
int from_tty)
378 command (arg, from_tty);
397 symfile_add_flags add_flags = 0;
412 error (
_(
"%s: '--readnow' and '--readnever' cannot be " 413 "specified simultaneously"),
452 int argc = context->
argc;
455 static int quiet = 0;
456 static int set_args = 0;
457 static int inhibit_home_gdbinit = 0;
461 char *execarg = NULL;
463 char *corearg = NULL;
464 char *pid_or_core_arg = NULL;
470 static int print_help;
471 static int print_version;
472 static int print_configuration;
475 std::vector<struct cmdarg> cmdarg_vec;
478 std::vector<char *> dirarg;
481 const char *system_gdbinit;
482 const char *home_gdbinit;
483 const char *local_gdbinit;
496 #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES) 497 setlocale (LC_MESSAGES,
"");
499 #if defined (HAVE_SETLOCALE) 500 setlocale (LC_CTYPE,
"");
503 bindtextdomain (
PACKAGE, LOCALEDIR);
515 setvbuf (stderr, NULL, _IONBF, BUFSIZ);
518 main_ui =
new ui (stdin, stdout, stderr);
557 #ifdef WITH_PYTHON_PATH 598 static struct option long_options[] =
600 {
"tui", no_argument, 0, OPT_TUI},
602 {
"readnow", no_argument, NULL, OPT_READNOW},
603 {
"readnever", no_argument, NULL, OPT_READNEVER},
604 {
"r", no_argument, NULL, OPT_READNOW},
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;
758 if (optarg[0] ==
'\0')
759 error (
_(
"%s: empty path for `--data-directory'"),
767 extern int gdbtk_test (
char *);
769 if (!gdbtk_test (optarg))
770 error (
_(
"%s: unable to load tclcommand file \"%s\""),
781 extern char *external_editor_command;
783 external_editor_command = xstrdup (optarg);
792 dirarg.push_back (optarg);
805 i = strtol (optarg, &p, 0);
806 if (i == 0 && p == optarg)
807 warning (
_(
"could not set baud rate to `%s'."),
818 i = strtol (optarg, &p, 0);
819 if (i == 0 && p == optarg)
820 warning (
_(
"could not set timeout limit to `%s'."),
842 error (
_(
"Use `%s --help' for a complete list of options."),
867 error (
_(
"%s: `--args' specified but no program specified"),
870 symarg =
argv[optind];
871 execarg =
argv[optind];
883 symarg =
argv[optind];
884 execarg =
argv[optind];
892 if (pidarg == NULL && corearg == NULL && optind < argc)
894 pid_or_core_arg =
argv[optind];
902 _(
"Excess command line " 903 "arguments ignored. (%s%s)\n"),
905 (optind == argc - 1) ?
"" :
" ...");
933 if (print_configuration)
980 tmp_warn_preprint.reset ();
999 for (i = 0; i < cmdarg_vec.size (); i++)
1001 const struct cmdarg &cmdarg_p = cmdarg_vec[i];
1003 switch (cmdarg_p.
type)
1022 for (i = 0; i < dirarg.size (); i++)
1033 && strcmp (execarg, symarg) == 0)
1045 if (execarg != NULL)
1053 if (corearg && pidarg)
1054 error (
_(
"Can't attach to process and specify " 1055 "a core file at the same time."));
1057 if (corearg != NULL)
1059 else if (pidarg != NULL)
1061 else if (pid_or_core_arg)
1067 if (isdigit (pid_or_core_arg[0]))
1094 _(
"auto-load: Loading .gdbinit " 1113 for (i = 0; i < cmdarg_vec.size (); i++)
1115 const struct cmdarg &cmdarg_p = cmdarg_vec[i];
1117 switch (cmdarg_p.
type)
1193 const char *system_gdbinit;
1194 const char *home_gdbinit;
1195 const char *local_gdbinit;
1203 This is the GNU debugger. Usage:\n\n\ 1204 gdb [options] [executable-file [core-file or process-id]]\n\ 1205 gdb [options] --args executable-file [inferior-arguments ...]\n\n\ 1208 Selection of debuggee and its files:\n\n\ 1209 --args Arguments after executable-file are passed to inferior\n\ 1210 --core=COREFILE Analyze the core dump COREFILE.\n\ 1211 --exec=EXECFILE Use EXECFILE as the executable.\n\ 1212 --pid=PID Attach to running process PID.\n\ 1213 --directory=DIR Search for source files in DIR.\n\ 1214 --se=FILE Use FILE as symbol file and executable file.\n\ 1215 --symbols=SYMFILE Read symbols from SYMFILE.\n\ 1216 --readnow Fully read symbol files on first access.\n\ 1217 --readnever Do not read symbol files.\n\ 1218 --write Set writing into executable and core files.\n\n\ 1221 Initial commands and command files:\n\n\ 1222 --command=FILE, -x Execute GDB commands from FILE.\n\ 1223 --init-command=FILE, -ix\n\ 1224 Like -x but execute commands before loading inferior.\n\ 1225 --eval-command=COMMAND, -ex\n\ 1226 Execute a single GDB command.\n\ 1227 May be used multiple times and in conjunction\n\ 1229 --init-eval-command=COMMAND, -iex\n\ 1230 Like -ex but before loading inferior.\n\ 1231 --nh Do not read ~/.gdbinit.\n\ 1232 --nx Do not read any .gdbinit files in any directory.\n\n\ 1235 Output and user interface control:\n\n\ 1236 --fullname Output information used by emacs-GDB interface.\n\ 1237 --interpreter=INTERP\n\ 1238 Select a specific interpreter / user interface\n\ 1239 --tty=TTY Use TTY for input/output by the program being debugged.\n\ 1240 -w Use the GUI interface.\n\ 1241 --nw Do not use the GUI interface.\n\ 1245 --tui Use a terminal user interface.\n\ 1249 --dbx DBX compatibility mode.\n\ 1250 -q, --quiet, --silent\n\ 1251 Do not print version number on startup.\n\n\ 1254 Operating modes:\n\n\ 1255 --batch Exit after processing options.\n\ 1256 --batch-silent Like --batch, but suppress all gdb stdout output.\n\ 1257 --return-child-result\n\ 1258 GDB exit code will be the child's exit code.\n\ 1259 --configuration Print details about GDB configuration and then exit.\n\ 1260 --help Print this message and then exit.\n\ 1261 --version Print version information and then exit.\n\n\ 1262 Remote debugging options:\n\n\ 1263 -b BAUDRATE Set serial port baud rate used for remote debugging.\n\ 1264 -l TIMEOUT Set timeout in seconds for remote debugging.\n\n\ 1266 --cd=DIR Change current directory to DIR.\n\ 1267 --data-directory=DIR, -D\n\ 1268 Set GDB's data-directory to DIR.\n\ 1271 At startup, GDB reads the following init files and executes their commands:\n\ 1275 * system-wide init file: %s\n\ 1276 "), system_gdbinit);
1279 * user-specific init file: %s\n\ 1283 * local init file (see also 'set auto-load local-gdbinit'): ./%s\n\ 1286 For more information, type \"help\" from within GDB, or consult the\n\ 1287 GDB manual (available as on-line info or a printed manual).\n\ 1291 Report bugs to \"%s\".\n\
int gdb_main(struct captured_main_args *args)
void start_event_loop(void)
void notice_open_fds(void)
static void get_init_files(const char **system_gdbinit, const char **home_gdbinit, const char **local_gdbinit)
void directory_switch(const char *, int)
static char * gdb_program_name
static int gdb_datadir_provided
void fputs_unfiltered(const char *buf, struct ui_file *file)
void warning(const char *fmt,...)
void async_enable_stdin(void)
int auto_load_local_gdbinit_loaded
char * relocate_gdb_directory(const char *initial, int flag)
struct ui_file * gdb_stdtargin
void * memset(T *s, int c, size_t n)=delete
void print_sys_errmsg(const char *string, int errcode)
const char * warning_pre_print
void set_inferior_io_terminal(const char *terminal_name)
void set_per_command_time(int new_value)
void symbol_file_add_main(const char *args, symfile_add_flags add_flags)
cmdarg(cmdarg_kind type_, char *string_)
void print_gdb_configuration(struct ui_file *stream)
static void captured_main(void *data)
gdb::unique_xmalloc_ptr< char > gdb_realpath(const char *filename)
char * auto_load_local_gdbinit_pathname
char * debug_file_directory
void printf_filtered(const char *format,...)
void execute_command(const char *, int)
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
void interp_pre_command_loop(struct interp *interp)
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)
std::unique_ptr< T, xfree_deleter< T > > unique_xmalloc_ptr
void load_auto_scripts_for_objfile(struct objfile *objfile)
objfile(bfd *, const char *, objfile_flags)
enum prompt_state prompt_state
long __attribute__((__aligned__(4)))
void fprintf_unfiltered(struct ui_file *stream, const char *format,...)
void exception_print(struct ui_file *file, struct gdb_exception e)
void quit_force(int *exit_arg, int from_tty)
void print_gdb_version(struct ui_file *stream)
#define GDB_DATADIR_RELOCATABLE
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,...)
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)
void quit_command(const char *args, int from_tty)
#define DEBUGDIR_RELOCATABLE
static int catch_command_errors(catch_command_errors_const_ftype command, const char *arg, int from_tty)
void wrap_here(const char *indent)
#define SYSTEM_GDBINIT_RELOCATABLE
void set_inferior_args_vector(int argc, char **argv)
#define PYTHON_PATH_RELOCATABLE
void core_file_command(const char *filename, int from_tty)
void exec_file_attach(const char *filename, int from_tty)
char * windows_get_absolute_argv0(const char *argv0)
gdb::unique_xmalloc_ptr< char > gdb_abspath(const char *path)
const char * interpreter_p
int readnever_symbol_files
void save_original_signals_state(bool quiet)
void attach_command(const char *args, int from_tty)
static int handle_command_errors(struct gdb_exception e)
void set_top_level_interpreter(const char *name)
void cd_command(const char *dir, int from_tty)
#define TARGET_SYSTEM_ROOT
struct ui_file * gdb_stdtarg
static void captured_command_loop()
static void symbol_file_add_main_adapter(const char *arg, int from_tty)
struct interp * top_level_interpreter(void)
void set_per_command_space(int new_value)
void gdb_init(char *argv0)
struct ui_file * gdb_stdtargerr
static void validate_readnow_readnever()
void gdb_flush(struct ui_file *file)
#define ALL_OBJFILES(obj)
char * saved_command_line
static void captured_main_1(struct captured_main_args *context)
void() catch_command_errors_const_ftype(const char *, int)
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