diff options
author | Andrew Burgess <andrew.burgess@embecosm.com> | 2020-09-25 16:28:05 +0100 |
---|---|---|
committer | Andrew Burgess <andrew.burgess@embecosm.com> | 2021-04-15 10:34:09 +0100 |
commit | 92e4e97a9f569bf23b0f74479f32280c1f24cc6b (patch) | |
tree | c3c32649c4dd701fef2406701e243be12a27b726 /gdb/main.c | |
parent | 54b4dcc530f0a907d9121aba1a2631d7e3333a8f (diff) | |
download | binutils-92e4e97a9f569bf23b0f74479f32280c1f24cc6b.zip binutils-92e4e97a9f569bf23b0f74479f32280c1f24cc6b.tar.gz binutils-92e4e97a9f569bf23b0f74479f32280c1f24cc6b.tar.bz2 |
gdb: process early initialization files and command line options
Adds the ability to process commands at a new phase during GDB's
startup. This phase is earlier than the current initialisation file
processing, before GDB has produced any output.
The number of commands that can be processed at this early stage will
be limited, and it is expected that the only commands that would be
processed at this stage will relate to some of the fundamentals of how
GDB starts up.
Currently the only commands that it makes sense to add to this early
initialization file are those like 'set style version ....' as the
version string is displayed during startup before the standard
initialization files are parsed. As such this commit fully resolved
bug cli/25956.
This commit adds a mechanism to execute these early initialization
files from a users HOME directory, as well as some corresponding
command line flags for GDB.
The early initialization files that GDB will currently check for are
~/.config/gdb/gdbearlyinit (on Linux like systems) or ~/.gdbearlyinit
if the former is not found.
The output of 'gdb --help' has been extended to include a list of the
early initialization files being processed.
gdb/ChangeLog:
PR cli/25956
* NEWS: Mention new early init files and command line options.
* config.in: Regenerate.
* configure: Regenerate.
* configure.ac: Define GDBEARLYINIT.
* main.c (get_earlyinit_files): New function.
(enum cmdarg_kind): Add CMDARG_EARLYINIT_FILE and
CMDARG_EARLYINIT_COMMAND.
(captured_main_1): Add support for new command line flags, and for
processing startup files.
(print_gdb_help): Include startup files in the output.
gdb/doc/ChangeLog:
PR cli/25956
* gdb.texinfo (File Options): Mention new command line options.
(Startup): Discuss when early init files are processed.
(Initialization Files): Add description of early init files.
(Output Styling): Update description of 'version' style.
(gdb man): Mention early init files.
gdb/testsuite/ChangeLog:
PR cli/25956
* gdb.base/early-init-file.c: New file.
* gdb.base/early-init-file.exp: New file.
* lib/gdb-utils.exp (style): Handle style 'none'.
Diffstat (limited to 'gdb/main.c')
-rw-r--r-- | gdb/main.c | 61 |
1 files changed, 60 insertions, 1 deletions
@@ -386,6 +386,22 @@ get_init_files (std::vector<std::string> *system_gdbinit, *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. */ @@ -560,7 +576,13 @@ enum cmdarg_kind CMDARG_INIT_FILE, /* Option type -iex. */ - CMDARG_INIT_COMMAND + CMDARG_INIT_COMMAND, + + /* Option type -sx. */ + CMDARG_EARLYINIT_FILE, + + /* Option type -sex. */ + CMDARG_EARLYINIT_COMMAND }; /* Arguments of --command option and its counterpart. */ @@ -738,6 +760,8 @@ captured_main_1 (struct captured_main_args *context) OPT_WINDOWS, OPT_IX, OPT_IEX, + OPT_EIX, + OPT_EIEX, OPT_READNOW, OPT_READNEVER }; @@ -787,6 +811,10 @@ captured_main_1 (struct captured_main_args *context) {"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'}, @@ -899,6 +927,12 @@ captured_main_1 (struct captured_main_args *context) 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 (); @@ -1007,6 +1041,18 @@ captured_main_1 (struct captured_main_args *context) /* Initialize all files. */ gdb_init (gdb_program_name); + /* 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); + /* Now that gdb_init has created the initial inferior, we're in position to set args for that inferior. */ if (set_args) @@ -1334,8 +1380,10 @@ print_gdb_help (struct ui_file *stream) 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 @@ -1409,6 +1457,17 @@ Other options:\n\n\ 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 ()) |