[RFC 6/6] Add "set startup-quietly"
Tom Tromey
tom@tromey.com
Sat Apr 4 14:54:22 GMT 2020
This adds a new command to change gdb to behave as though "-quiet"
were always given. This is done by creating a special sentinel file
in the config directory.
2020-03-28 Tom Tromey <tom@tromey.com>
* tips: Add a tip.
* NEWS: Add entry.
* top.h (check_quiet_mode): Declare.
* top.c (startup_quiet, store_startup_quiet): New globals.
(QUIET_FILE): New define.
(check_quiet_mode, set_startup_quiet, show_startup_quiet): New
functions.
(init_main): Register new command.
* main.c (captured_main_1): Call check_quiet_mode.
gdb/doc/ChangeLog
2020-03-28 Tom Tromey <tom@tromey.com>
* gdb.texinfo (Mode Options): Mention "set startup-quietly".
---
gdb/ChangeLog | 12 +++++++
gdb/NEWS | 7 ++++
gdb/doc/ChangeLog | 4 +++
gdb/doc/gdb.texinfo | 13 +++++++
gdb/main.c | 7 +++-
gdb/tips | 3 ++
gdb/top.c | 82 +++++++++++++++++++++++++++++++++++++++++++++
gdb/top.h | 5 +++
8 files changed, 132 insertions(+), 1 deletion(-)
diff --git a/gdb/NEWS b/gdb/NEWS
index bb54c738281..a07052be0b1 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -67,6 +67,13 @@ set style startup intensity VALUE
a special configuration file, so that it can be read during startup
and applied.
+set startup-quietly on|off
+show startup-quietly
+ When enabled, this causes GDB to act as if "-silent" were always
+ passed on the command line. This saves the setting into a special
+ configuration file, so that it can be read during startup and
+ applied.
+
tui new-layout NAME WINDOW WEIGHT [WINDOW WEIGHT]...
Define a new TUI layout, specifying its name and the windows that
will be displayed.
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index f860b238ff8..6025f39468b 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -1124,6 +1124,19 @@ in your home directory.
``Quiet''. Do not print the introductory and copyright messages. These
messages are also suppressed in batch mode.
+This can also be enabled using @code{set startup-quietly on}. The
+default is @code{off}. Use @code{show startup-quietly} to see the
+current setting. Unlike most settings in @value{GDBN}, this one is
+automatically saved by creating a special in a configuration
+directory.
+
+The default value for this directory depends on the host platform. On
+most systems, the index is cached in the @file{gdb} subdirectory of
+the directory pointed to by the @env{XDG_CONFIG_HOME} environment
+variable, if it is defined, else in the @file{.config/gdb} subdirectory
+of your home directory. However, on some systems, the default may
+differ according to local convention.
+
@item -batch
@cindex @code{--batch}
Run in batch mode. Exit with status @code{0} after processing all the
diff --git a/gdb/main.c b/gdb/main.c
index 51e422ae496..85d2802cff0 100644
--- a/gdb/main.c
+++ b/gdb/main.c
@@ -918,7 +918,12 @@ captured_main_1 (struct captured_main_args *context)
/* Set the startup style. */
if (!inhibit_gdbinit && !inhibit_home_gdbinit)
- read_startup_style ();
+ {
+ read_startup_style ();
+
+ 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. */
diff --git a/gdb/tips b/gdb/tips
index 75957fb853d..f0b194d88a4 100644
--- a/gdb/tips
+++ b/gdb/tips
@@ -7,3 +7,6 @@ You can use "help news" to see what has changed in GDB.
Type "apropos word" to search for commands related to "word".
%
Type "show configuration" for configuration details.
+%
+You can use "set startup-quietly on" to have GDB always start up
+silently.
diff --git a/gdb/top.c b/gdb/top.c
index 46781a5c0ef..13d139d238b 100644
--- a/gdb/top.c
+++ b/gdb/top.c
@@ -2198,6 +2198,80 @@ set_history_filename (const char *args,
}
}
+/* Whether we're in quiet startup mode. */
+
+static bool startup_quiet;
+
+/* Whether we should try writing changes to startup-quietly to the
+ filesystem. */
+
+static bool store_startup_quiet;
+
+/* File name for quiet startup. */
+#define QUIET_FILE "startup-quietly"
+
+/* See top.h. */
+
+bool
+check_quiet_mode ()
+{
+ std::string config_dir = get_standard_config_dir ();
+
+ if (!config_dir.empty ())
+ {
+ std::string filename = config_dir + "/" + QUIET_FILE;
+ int ignore;
+
+ store_startup_quiet = true;
+ startup_quiet = is_regular_file (filename.c_str (), &ignore);
+ return startup_quiet;
+ }
+
+ return false;
+}
+
+/* Set the startup-quiet flag. */
+
+static void
+set_startup_quiet (const char *args, int from_tty, struct cmd_list_element *c)
+{
+ if (!store_startup_quiet)
+ return;
+
+ std::string config_dir = get_standard_config_dir ();
+
+ if (!config_dir.empty ())
+ {
+ std::string filename = config_dir + "/" + QUIET_FILE;
+
+ if (startup_quiet)
+ {
+ if (!mkdir_recursive (config_dir.c_str ()))
+ {
+ warning (_("Could not make config directory: %s"),
+ safe_strerror (errno));
+ return;
+ }
+
+ /* Just touching the file is enough. */
+ gdb_file_up f = gdb_fopen_cloexec (filename.c_str (), FOPEN_WT);
+ if (f == nullptr)
+ warning (_("Could not make 'quiet' config file: %s"),
+ safe_strerror (errno));
+ }
+ else
+ unlink (filename.c_str ());
+ }
+}
+
+static void
+show_startup_quiet (struct ui_file *file, int from_tty,
+ struct cmd_list_element *c, const char *value)
+{
+ fprintf_filtered (file, _("Whether to start up quietly is %s.\n"),
+ value);
+}
+
static void
init_gdb_version_vars (void)
{
@@ -2352,6 +2426,14 @@ input settings."),
show_interactive_mode,
&setlist, &showlist);
+ add_setshow_boolean_cmd ("startup-quietly", class_support,
+ &startup_quiet, _("\
+Set whether GDB should start up quietly."), _("\
+Show whether GDB should start up quietly."), NULL,
+ set_startup_quiet,
+ show_startup_quiet,
+ &setlist, &showlist);
+
c = add_cmd ("new-ui", class_support, new_ui_command, _("\
Create a new UI.\n\
Usage: new-ui INTERPRETER TTY\n\
diff --git a/gdb/top.h b/gdb/top.h
index 638e02cad4c..ba09d723908 100644
--- a/gdb/top.h
+++ b/gdb/top.h
@@ -298,4 +298,9 @@ extern char *handle_line_of_input (struct buffer *cmd_line_buffer,
const char *rl, int repeat,
const char *annotation_suffix);
+/* Call at startup to see if the user has requested that gdb start up
+ quietly. */
+
+extern bool check_quiet_mode ();
+
#endif
--
2.17.2
More information about the Gdb-patches
mailing list