public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Andrew Burgess <andrew.burgess@embecosm.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [PATCH 7/7] Add "set startup-quietly"
Date: Wed,  7 Oct 2020 21:05:11 +0100	[thread overview]
Message-ID: <c3f02cdd39a697015dc462b49ff6a254b2691110.1601927356.git.andrew.burgess@embecosm.com> (raw)
In-Reply-To: <cover.1601927355.git.andrew.burgess@embecosm.com>

From: Tom Tromey <tom@tromey.com>

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.

2020-07-05  Tom Tromey  <tom@tromey.com>

	* 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-07-05  Tom Tromey  <tom@tromey.com>

	* gdb.texinfo (Mode Options): Mention "set startup-quietly".

gdb/testsuite/ChangeLog
2020-07-05  Tom Tromey  <tom@tromey.com>

	* gdb.base/persist.exp: Add startup-quietly test.
---
 gdb/ChangeLog                      | 10 ++++++++
 gdb/NEWS                           |  7 ++++++
 gdb/doc/ChangeLog                  |  4 +++
 gdb/doc/gdb.texinfo                | 15 ++++++++++++
 gdb/main.c                         |  5 ++++
 gdb/testsuite/ChangeLog            |  4 +++
 gdb/testsuite/gdb.base/persist.exp |  1 +
 gdb/top.c                          | 39 ++++++++++++++++++++++++++++++
 gdb/top.h                          |  5 ++++
 9 files changed, 90 insertions(+)

diff --git a/gdb/NEWS b/gdb/NEWS
index d72d51b18b6..9b69ea70c11 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -139,6 +139,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 f11948e8c4f..1162f0d46ac 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -1114,6 +1114,21 @@
 ``Quiet''.  Do not print the introductory and copyright messages.  These
 messages are also suppressed in batch mode.
 
+@kindex set startup-quietly
+@kindex show startup-quietly
+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.  Changing this setting will cause it to automatically
+be saved in a special configuration file, which is read by
+@value{GDBN} early in its startup.
+
+The directory in which this file appears depends on the host platform.
+On most systems, the file is 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 850b6b6708d..e067158d4e3 100644
--- a/gdb/main.c
+++ b/gdb/main.c
@@ -1080,6 +1080,11 @@ captured_main_1 (struct captured_main_args *context)
 		   CMDARG_STARTUP_COMMAND, &ret);
   startup_file_read = true;
 
+  /* 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.  */
   if (set_args)
diff --git a/gdb/testsuite/gdb.base/persist.exp b/gdb/testsuite/gdb.base/persist.exp
index e0525786feb..3e7791f2ad0 100644
--- a/gdb/testsuite/gdb.base/persist.exp
+++ b/gdb/testsuite/gdb.base/persist.exp
@@ -64,4 +64,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/top.c b/gdb/top.c
index e4c80c6dadb..c05b5506ef2 100644
--- a/gdb/top.c
+++ b/gdb/top.c
@@ -2153,6 +2153,34 @@ 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;
+}
+
+/* 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)
 {
@@ -2307,6 +2335,17 @@ input settings."),
                         show_interactive_mode,
                         &setlist, &showlist);
 
+  c = 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_default_startup_writer (c);
+
   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
-- 
2.25.4


  parent reply	other threads:[~2020-10-07 19:05 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-07 20:05 [PATCH 0/7] Adding startup files to GDB Andrew Burgess
2020-10-07 20:05 ` [PATCH 1/7] Add get_standard_config_dir function Andrew Burgess
2020-10-07 20:05 ` [PATCH 2/7] gdb: use get_standard_config_dir when looking for .gdbinit Andrew Burgess
2020-10-08  6:52   ` Eli Zaretskii
2020-11-02 10:20     ` Andrew Burgess
2020-10-22 19:07   ` Tom Tromey
2020-11-09 13:52   ` Tom Tromey
2020-11-09 13:55     ` Tom Tromey
2020-10-07 20:05 ` [PATCH 3/7] gdb: new function to wrap up executing command line scripts/commands Andrew Burgess
2020-10-08 15:25   ` Aktemur, Tankut Baris
2020-11-02  9:48     ` Andrew Burgess
2020-10-22 19:08   ` Tom Tromey
2020-10-07 20:05 ` [PATCH 4/7] gdb: process startup files and startup command line options Andrew Burgess
2020-10-08  6:28   ` Eli Zaretskii
2020-10-07 20:05 ` [PATCH 5/7] gdb: add mechanism to auto-save startup options Andrew Burgess
2020-10-08  6:36   ` Eli Zaretskii
2020-10-07 20:05 ` [PATCH 6/7] Let the user control the startup style Andrew Burgess
2020-10-08  6:40   ` Eli Zaretskii
2020-10-07 20:05 ` Andrew Burgess [this message]
2020-10-08  6:44   ` [PATCH 7/7] Add "set startup-quietly" Eli Zaretskii
2020-10-08  6:56 ` [PATCH 0/7] Adding startup files to GDB Eli Zaretskii
2020-10-22 19:02 ` Tom Tromey
2020-10-28 15:29   ` Andrew Burgess
2021-01-11 16:45   ` Andrew Burgess

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=c3f02cdd39a697015dc462b49ff6a254b2691110.1601927356.git.andrew.burgess@embecosm.com \
    --to=andrew.burgess@embecosm.com \
    --cc=gdb-patches@sourceware.org \
    --cc=tom@tromey.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).