*local_gdbinit = init_files->local_file ();
}
+/* Compute the location of the early init file GDB should source and return
+ it in HOME_GDBEARLYINIT. HOME_GDBEARLYINIT could be returned as an
+ empty string if there is no early init file found. */
+
+static void
+get_earlyinit_files (std::string *home_gdbearlyinit)
+{
+ /* Cache the file lookup object so we only actually search for the files
+ once. */
+ static gdb::optional<gdb_initfile_finder> init_files;
+ if (!init_files.has_value ())
+ init_files.emplace (GDBEARLYINIT, nullptr, false, nullptr, false, false);
+
+ *home_gdbearlyinit = init_files->home_file ();
+}
+
/* Start up the event loop. This is the entry point to the event loop
from the command loop. */
/* Option type -ix. */
CMDARG_INIT_FILE,
-
+
/* Option type -iex. */
- CMDARG_INIT_COMMAND
+ CMDARG_INIT_COMMAND,
+
+ /* Option type -eix. */
+ CMDARG_EARLYINIT_FILE,
+
+ /* Option type -eiex. */
+ CMDARG_EARLYINIT_COMMAND
};
/* Arguments of --command option and its counterpart. */
OPT_WINDOWS,
OPT_IX,
OPT_IEX,
+ OPT_EIX,
+ OPT_EIEX,
OPT_READNOW,
OPT_READNEVER
};
{"init-eval-command", required_argument, 0, OPT_IEX},
{"ix", required_argument, 0, OPT_IX},
{"iex", required_argument, 0, OPT_IEX},
+ {"early-init-command", required_argument, 0, OPT_EIX},
+ {"early-init-eval-command", required_argument, 0, OPT_EIEX},
+ {"eix", required_argument, 0, OPT_EIX},
+ {"eiex", required_argument, 0, OPT_EIEX},
#ifdef GDBTK
{"tclcommand", required_argument, 0, 'z'},
{"enable-external-editor", no_argument, 0, 'y'},
case OPT_IEX:
cmdarg_vec.emplace_back (CMDARG_INIT_COMMAND, optarg);
break;
+ case OPT_EIX:
+ cmdarg_vec.emplace_back (CMDARG_EARLYINIT_FILE, optarg);
+ break;
+ case OPT_EIEX:
+ cmdarg_vec.emplace_back (CMDARG_EARLYINIT_COMMAND, optarg);
+ break;
case 'B':
batch_flag = batch_silent = 1;
gdb_stdout = new null_file ();
gdb::alternate_signal_stack signal_stack;
/* Initialize all files. */
- gdb_init (gdb_program_name);
+ gdb_init ();
+
+ /* Process early init files and early init options from the command line. */
+ if (!inhibit_gdbinit)
+ {
+ std::string home_gdbearlyinit;
+ get_earlyinit_files (&home_gdbearlyinit);
+ if (!home_gdbearlyinit.empty () && !inhibit_home_gdbinit)
+ ret = catch_command_errors (source_script,
+ home_gdbearlyinit.c_str (), 0);
+ }
+ execute_cmdargs (&cmdarg_vec, CMDARG_EARLYINIT_FILE,
+ CMDARG_EARLYINIT_COMMAND, &ret);
+
+ /* Initialize the extension languages. */
+ ext_lang_initialization ();
+
+ /* Recheck if we're starting up quietly after processing the startup
+ scripts and commands. */
+ if (!quiet)
+ quiet = check_quiet_mode ();
/* Now that gdb_init has created the initial inferior, we're in
position to set args for that inferior. */
std::vector<std::string> system_gdbinit;
std::string home_gdbinit;
std::string local_gdbinit;
+ std::string home_gdbearlyinit;
get_init_files (&system_gdbinit, &home_gdbinit, &local_gdbinit);
+ get_earlyinit_files (&home_gdbearlyinit);
/* Note: The options in the list below are only approximately sorted
in the alphabetical order, so as to group closely related options
Set GDB's data-directory to DIR.\n\
"), stream);
fputs_unfiltered (_("\n\
+At startup, GDB reads the following early init files and executes their\n\
+commands:\n\
+"), stream);
+ if (!home_gdbearlyinit.empty ())
+ fprintf_unfiltered (stream, _("\
+ * user-specific early init file: %s\n\
+"), home_gdbearlyinit.c_str ());
+ if (home_gdbearlyinit.empty ())
+ fprintf_unfiltered (stream, _("\
+ None found.\n"));
+ fputs_unfiltered (_("\n\
At startup, GDB reads the following init files and executes their commands:\n\
"), stream);
if (!system_gdbinit.empty ())