[v2,7/7] Add "set startup-quietly"

Message ID 20200623132006.15863-8-tom@tromey.com
State New
Headers show
Series
  • Some user-friendliness changes
Related show

Commit Message

Tom Tromey June 23, 2020, 1:20 p.m.
This adds a new command to change gdb to behave as though "-quiet"
were always given.  This is done by using the early startup file
infrastructure.

gdb/ChangeLog
2020-06-22  Tom Tromey  <tom@tromey.com>

	* tips: Add a tip.
	* NEWS: Add entry.
	* top.h (check_quiet_mode): Declare.
	* top.c (startup_quiet): New global.
	(check_quiet_mode, set_startup_quiet, show_startup_quiet)
	(write_startup_quietly): New functions.
	(init_main): Register new command and callback.
	* 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/testsuite/ChangeLog
2020-06-22  Tom Tromey  <tom@tromey.com>

	* gdb.base/persist.exp: Add startup-quietly test.
---
 gdb/ChangeLog                      | 11 +++++++
 gdb/NEWS                           |  7 +++++
 gdb/doc/ChangeLog                  |  4 +++
 gdb/doc/gdb.texinfo                | 13 ++++++++
 gdb/main.c                         |  7 ++++-
 gdb/testsuite/ChangeLog            |  4 +++
 gdb/testsuite/gdb.base/persist.exp |  1 +
 gdb/tips                           |  3 ++
 gdb/top.c                          | 48 ++++++++++++++++++++++++++++++
 gdb/top.h                          |  5 ++++
 10 files changed, 102 insertions(+), 1 deletion(-)

-- 
2.17.2

Comments

Eli Zaretskii June 23, 2020, 2:45 p.m. | #1
> From: Tom Tromey <tom@tromey.com>

> Date: Tue, 23 Jun 2020 07:20:06 -0600

> Cc: Tom Tromey <tom@tromey.com>

> 

> --- a/gdb/NEWS

> +++ b/gdb/NEWS

> @@ -87,6 +87,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.


OK for this part.

> --- 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 file in a configuration

> +directory.


Please index the new commands using @kindex, as we do for every
command.

The documentation parts are OK with this nit fixed, thanks.

Patch

diff --git a/gdb/NEWS b/gdb/NEWS
index 8f474c51bf4..31cfdc95ae1 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -87,6 +87,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 7c3fe7d38a2..ba44369c10e 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 file 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 bd1f6d6b2c5..34752d27737 100644
--- a/gdb/main.c
+++ b/gdb/main.c
@@ -936,7 +936,12 @@  captured_main_1 (struct captured_main_args *context)
 
   /* Set the startup style.  */
   if (!inhibit_gdbinit && !inhibit_home_gdbinit)
-    read_startup_file ();
+    {
+      read_startup_file ();
+
+      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/testsuite/gdb.base/persist.exp b/gdb/testsuite/gdb.base/persist.exp
index 76a55d558c3..adffa488aa5 100644
--- a/gdb/testsuite/gdb.base/persist.exp
+++ b/gdb/testsuite/gdb.base/persist.exp
@@ -61,4 +61,5 @@  save_vars { env(XDG_CONFIG_HOME) } {
     set contents [require_changed "set style startup foreground green" $filename $contents]
     set contents [require_changed "set style startup background green" $filename $contents]
     set contents [require_changed "set style startup intensity dim" $filename $contents]
+    set contents [require_changed "set startup-quietly on" $filename $contents]
 }
diff --git a/gdb/tips b/gdb/tips
index a9c89747aa4..a83dc2c9ddc 100644
--- a/gdb/tips
+++ b/gdb/tips
@@ -10,3 +10,6 @@  Type "show configuration" for configuration details.
 %
 You can use the "set style startup" family of commands to change the
 style used for tips.
+%
+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 e86ce4020f3..910b9d0dfcb 100644
--- a/gdb/top.c
+++ b/gdb/top.c
@@ -2196,6 +2196,43 @@  set_history_filename (const char *args,
     }
 }
 
+/* Whether we're in quiet startup mode.  */
+
+static bool startup_quiet;
+
+/* See top.h.  */
+
+bool
+check_quiet_mode ()
+{
+  return startup_quiet;
+}
+
+/* Write "set startup-quietly" to the file.  */
+
+static void
+write_startup_quietly (ui_file *outfile)
+{
+  fprintf_unfiltered (outfile, "set startup-quietly %s\n",
+		      startup_quiet ? "on" : "off");
+}
+
+/* Set the startup-quiet flag.  */
+
+static void
+set_startup_quiet (const char *args, int from_tty, struct cmd_list_element *c)
+{
+  write_startup_file ();
+}
+
+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)
 {
@@ -2350,6 +2387,17 @@  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);
+  /* Arrange to write "set startup-quietly" to the early startup
+     file.  */
+  add_startup_writer (write_startup_quietly);
+
   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 fd992977155..85e178c527a 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