620 int argc = context->
argc;
621 char **argv = context->
argv;
623 static int quiet = 0;
624 static int set_args = 0;
625 static int inhibit_home_gdbinit = 0;
629 char *execarg = NULL;
631 char *corearg = NULL;
632 char *pid_or_core_arg = NULL;
638 static int print_help;
639 static int print_version;
640 static int print_configuration;
643 std::vector<struct cmdarg> cmdarg_vec;
646 std::vector<char *> dirarg;
652 const char *no_color = getenv (
"NO_COLOR");
653 if (no_color !=
nullptr && *no_color !=
'\0')
656#ifdef HAVE_USEFUL_SBRK
663#if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
664 setlocale (LC_MESSAGES,
"");
666#if defined (HAVE_SETLOCALE)
667 setlocale (LC_CTYPE,
"");
670 bindtextdomain (
PACKAGE, LOCALEDIR);
679 setvbuf (stderr, NULL, _IONBF, BUFSIZ);
684 main_ui =
new ui (stdin, stdout, stderr);
691 if (bfd_init () != BFD_INIT_MAGIC)
692 error (_(
"fatal error: libbfd ABI mismatch"));
703 gdb::unique_xmalloc_ptr<char> tmp_warn_preprint
707 current_directory = getcwd (NULL, 0);
708 if (current_directory == NULL)
721#ifdef ADDITIONAL_DEBUG_DIRS
723 + ADDITIONAL_DEBUG_DIRS);
729#ifdef WITH_PYTHON_LIBDIR
769 int write_files_1 = 0;
770 static struct option long_options[] =
772 {
"tui", no_argument, 0, OPT_TUI},
773 {
"readnow", no_argument, NULL, OPT_READNOW},
774 {
"readnever", no_argument, NULL, OPT_READNEVER},
775 {
"r", no_argument, NULL, OPT_READNOW},
776 {
"quiet", no_argument, &quiet, 1},
777 {
"q", no_argument, &quiet, 1},
778 {
"silent", no_argument, &quiet, 1},
779 {
"nh", no_argument, &inhibit_home_gdbinit, 1},
782 {
"batch-silent", no_argument, 0,
'B'},
788 {
"fullname", no_argument, 0,
'f'},
789 {
"f", no_argument, 0,
'f'},
791 {
"annotate", required_argument, 0, OPT_ANNOTATE},
792 {
"help", no_argument, &print_help, 1},
793 {
"se", required_argument, 0, OPT_SE},
794 {
"symbols", required_argument, 0,
's'},
795 {
"s", required_argument, 0,
's'},
796 {
"exec", required_argument, 0,
'e'},
797 {
"e", required_argument, 0,
'e'},
798 {
"core", required_argument, 0,
'c'},
799 {
"c", required_argument, 0,
'c'},
800 {
"pid", required_argument, 0,
'p'},
801 {
"p", required_argument, 0,
'p'},
802 {
"command", required_argument, 0,
'x'},
803 {
"eval-command", required_argument, 0,
'X'},
804 {
"version", no_argument, &print_version, 1},
805 {
"configuration", no_argument, &print_configuration, 1},
806 {
"x", required_argument, 0,
'x'},
807 {
"ex", required_argument, 0,
'X'},
808 {
"init-command", required_argument, 0, OPT_IX},
809 {
"init-eval-command", required_argument, 0, OPT_IEX},
810 {
"ix", required_argument, 0, OPT_IX},
811 {
"iex", required_argument, 0, OPT_IEX},
812 {
"early-init-command", required_argument, 0, OPT_EIX},
813 {
"early-init-eval-command", required_argument, 0, OPT_EIEX},
814 {
"eix", required_argument, 0, OPT_EIX},
815 {
"eiex", required_argument, 0, OPT_EIEX},
817 {
"tclcommand", required_argument, 0,
'z'},
818 {
"enable-external-editor", no_argument, 0,
'y'},
819 {
"editor-command", required_argument, 0,
'w'},
821 {
"ui", required_argument, 0,
'i'},
822 {
"interpreter", required_argument, 0,
'i'},
823 {
"i", required_argument, 0,
'i'},
824 {
"directory", required_argument, 0,
'd'},
825 {
"d", required_argument, 0,
'd'},
826 {
"data-directory", required_argument, 0,
'D'},
827 {
"D", required_argument, 0,
'D'},
828 {
"cd", required_argument, 0, OPT_CD},
829 {
"tty", required_argument, 0,
't'},
830 {
"baud", required_argument, 0,
'b'},
831 {
"b", required_argument, 0,
'b'},
832 {
"nw", no_argument, NULL, OPT_NOWINDOWS},
833 {
"nowindows", no_argument, NULL, OPT_NOWINDOWS},
834 {
"w", no_argument, NULL, OPT_WINDOWS},
835 {
"windows", no_argument, NULL, OPT_WINDOWS},
836 {
"statistics", no_argument, 0, OPT_STATISTICS},
837 {
"write", no_argument, &write_files_1, 1},
838 {
"args", no_argument, &set_args, 1},
839 {
"l", required_argument, 0,
'l'},
841 {0, no_argument, 0, 0}
848 c = getopt_long_only (argc, argv,
"",
849 long_options, &option_index);
850 if (c == EOF || set_args)
854 if (c == 0 && long_options[option_index].flag == 0)
855 c = long_options[option_index].val;
936 if (optarg[0] ==
'\0')
937 error (_(
"%s: empty path for `--data-directory'"),
945 if (!gdbtk_test (optarg))
946 error (_(
"%s: unable to load tclcommand file \"%s\""),
957 external_editor_command = xstrdup (optarg);
965 dirarg.push_back (optarg);
978 rate = strtol (optarg, &p, 0);
979 if (
rate == 0 && p == optarg)
980 warning (_(
"could not set baud rate to `%s'."),
991 timeout = strtol (optarg, &p, 0);
992 if (timeout == 0 && p == optarg)
993 warning (_(
"could not set timeout limit to `%s'."),
1015 error (_(
"Use `%s --help' for a complete list of options."),
1030 save_original_signals_state (quiet);
1033 gdb::alternate_signal_stack signal_stack;
1041 std::string home_gdbearlyinit;
1043 if (!home_gdbearlyinit.empty () && !inhibit_home_gdbinit)
1045 home_gdbearlyinit.c_str (), 0);
1066 error (_(
"%s: `--args' specified but no program specified"),
1069 symarg = argv[optind];
1070 execarg = argv[optind];
1073 (gdb::array_view<char * const> (&argv[optind], argc - optind));
1083 symarg = argv[optind];
1084 execarg = argv[optind];
1092 if (pidarg == NULL && corearg == NULL && optind < argc)
1094 pid_or_core_arg = argv[optind];
1102 _(
"Excess command line "
1103 "arguments ignored. (%s%s)\n"),
1105 (optind == argc - 1) ?
"" :
" ...");
1111 std::vector<std::string> system_gdbinit;
1112 std::string home_gdbinit;
1113 std::string local_gdbinit;
1134 if (print_configuration)
1158 tmp_warn_preprint.reset ();
1167 for (
const std::string &file : system_gdbinit)
1176 if (!home_gdbinit.empty () && !
inhibit_gdbinit && !inhibit_home_gdbinit)
1188 for (i = 0; i < dirarg.size (); i++)
1199 && strcmp (execarg, symarg) == 0)
1212 if (execarg != NULL)
1220 if (corearg && pidarg)
1221 error (_(
"Can't attach to process and specify "
1222 "a core file at the same time."));
1224 if (corearg != NULL)
1229 else if (pidarg != NULL)
1233 else if (pid_or_core_arg)
1239 if (isdigit (pid_or_core_arg[0]))
1265 if (!local_gdbinit.empty ())
1268 = gdb_realpath (local_gdbinit.c_str ()).release ();
1273 local_gdbinit.c_str ());
1301 int error_status = EXIT_FAILURE;
1302 int *exit_arg = ret == 0 ? &error_status : NULL;
static void execute_cmdargs(const std::vector< struct cmdarg > *cmdarg_vec, cmdarg_kind file_type, cmdarg_kind cmd_type, int *ret)
static std::string relocate_path(const char *progname, const char *initial, bool relocatable)
static void get_init_files(std::vector< std::string > *system_gdbinit, std::string *home_gdbinit, std::string *local_gdbinit)
static int catch_command_errors(catch_command_errors_const_ftype command, const char *arg, int from_tty, bool do_bp_actions=false)