Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Andrew Burgess <andrew.burgess@embecosm.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [PATCHv3 3/3] gdb: add "set startup-quietly" command
Date: Thu, 18 Feb 2021 16:41:04 +0000	[thread overview]
Message-ID: <c935bb1214f0e27f8ad0e6a8b4b8dbe7046a8739.1613666281.git.andrew.burgess@embecosm.com> (raw)
In-Reply-To: <cover.1613666280.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 new command can be added to the gdbstartup
file to affect future GDB sessions.

gdb/ChangeLog:

	* NEWS: Add entry.
	* main.c (captured_main_1): Call check_quiet_mode.
	* top.c (startup_quiet): New global.
	(check_quiet_mode): New function.
	(show_startup_quiet): New function.
	(init_main): Register new command.
	* top.h (check_quiet_mode): Declare.

gdb/doc/ChangeLog:

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

gdb/testsuite/ChangeLog:

	* gdb.base/startup-file.exp: Add more tests.
---
 gdb/ChangeLog                              | 11 ++++++
 gdb/NEWS                                   |  7 ++++
 gdb/doc/ChangeLog                          |  5 +++
 gdb/doc/gdb.texinfo                        |  8 +++++
 gdb/main.c                                 |  5 +++
 gdb/testsuite/ChangeLog                    |  4 +++
 gdb/testsuite/gdb.base/early-init-file.exp | 39 ++++++++++++++++++++++
 gdb/top.c                                  | 33 ++++++++++++++++++
 gdb/top.h                                  |  5 +++
 9 files changed, 117 insertions(+)

diff --git a/gdb/NEWS b/gdb/NEWS
index fdd526e86cf..a1d9194de29 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -59,6 +59,13 @@ maintenance flush register-cache
 maintenance flush dcache
   A new command to flush the dcache.
 
+set startup-quietly on|off
+show startup-quietly
+  When 'on', this causes GDB to act as if "-silent" were passed on the
+  command line.  This command needs to be added to an early
+  initialization file (e.g. ~/.config/gdb/gdbearlyinit) in order to
+  affect GDB.
+
 * Changed commands
 
 break [PROBE_MODIFIER] [LOCATION] [thread THREADNUM]
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index b900d777c13..2489b69fb23 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -1112,6 +1112,14 @@
 ``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.  Place @code{set startup-quietly on} into your early
+initialization file (@pxref{Initialization Files,,Initialization
+Files}) to have future @value{GDBN} sessions startup quietly.
+
 @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 5633381fdd5..60c08fb83dd 100644
--- a/gdb/main.c
+++ b/gdb/main.c
@@ -1053,6 +1053,11 @@ captured_main_1 (struct captured_main_args *context)
   execute_cmdargs (&cmdarg_vec, CMDARG_EARLYINIT_FILE,
 		   CMDARG_EARLYINIT_COMMAND, &ret);
 
+  /* 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/early-init-file.exp b/gdb/testsuite/gdb.base/early-init-file.exp
index 116a3e83761..701e172656e 100644
--- a/gdb/testsuite/gdb.base/early-init-file.exp
+++ b/gdb/testsuite/gdb.base/early-init-file.exp
@@ -66,6 +66,21 @@ proc setup_home_directories { prefix content } {
     return [list $home_dir $xdg_home_dir]
 }
 
+# Restart GDB and ensure that there's no license text, we should just
+# drop straight to the prompt.
+proc check_gdb_startups_up_quietly { message } {
+    global gdb_prompt
+
+    gdb_exit
+    gdb_spawn
+
+    gdb_test_multiple "" $message {
+	-re "^$gdb_prompt $" {
+	    pass $gdb_test_name
+	}
+    }
+}
+
 save_vars { env(TERM) } {
     # We need an ANSI-capable terminal to get the output.
     setenv TERM ansi
@@ -106,5 +121,29 @@ save_vars { env(TERM) } {
 	check_gdb_startup_version_string none \
 	    "check version string is unstyled using XDG_CONFIG_HOME"
     }
+
+    # Create two directories to use for the quiet startup test.
+    set dirs [setup_home_directories "quiet" "set startup-quietly on"]
+    set home_dir [lindex $dirs 0]
+    set xdg_home_dir [lindex $dirs 1]
+
+    # Now arrange to use the fake home directory startup file.
+    save_vars { INTERNAL_GDBFLAGS env(HOME) env(XDG_CONFIG_HOME) } {
+	set INTERNAL_GDBFLAGS [string map {"-nx" ""} $INTERNAL_GDBFLAGS]
+
+	# Now test GDB when using the HOME directory.
+	set env(HOME) $home_dir
+	unset -nocomplain env(XDG_CONFIG_HOME)
+	check_gdb_startups_up_quietly \
+	    "check GDB starts quietly using HOME"
+
+	# Now test using the XDG_CONFIG_HOME folder.  We still need to
+	# have a HOME directory set otherwise GDB will issue an error
+	# about not knowing where to place the index cache.
+	set env(XDG_CONFIG_HOME) $xdg_home_dir
+	set env(HOME) $empty_home_dir
+	check_gdb_startups_up_quietly \
+	    "check GDB starts quietly using XDG_CONFIG_HOME"
+    }
 }
 
diff --git a/gdb/top.c b/gdb/top.c
index 3be95079654..07b253ce4be 100644
--- a/gdb/top.c
+++ b/gdb/top.c
@@ -2144,6 +2144,28 @@ 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;
+}
+
+/* Show whether GDB should start up in quiet mode.  */
+
+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)
 {
@@ -2298,6 +2320,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."), _("\
+This setting will not affect the current session.  Instead this command\n\
+should be added to the .gdbstartup file in the users home directory to\n\
+affect future GDB sessions."),
+			       NULL,
+			       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 f58bebbb385..9438e52331b 100644
--- a/gdb/top.h
+++ b/gdb/top.h
@@ -291,4 +291,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:[~2021-02-18 16:41 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-26  9:48 [PATCHv2 0/3] Adding startup files to GDB Andrew Burgess
2021-01-26  9:48 ` [PATCHv2 1/3] gdb: refactor the initialization file lookup code Andrew Burgess
2021-01-26 15:09   ` Simon Marchi via Gdb-patches
2021-01-26  9:48 ` [PATCHv2 2/3] gdb: process startup files and startup command line options Andrew Burgess
2021-01-26 15:22   ` Eli Zaretskii via Gdb-patches
2021-01-26 15:32     ` Simon Marchi via Gdb-patches
2021-01-26 15:30   ` Simon Marchi via Gdb-patches
2021-01-26  9:48 ` [PATCHv2 3/3] gdb: add "set startup-quietly" command Andrew Burgess
2021-01-26 15:12   ` Eli Zaretskii via Gdb-patches
2021-02-18 16:41 ` [PATCHv3 0/3] Adding startup files to GDB Andrew Burgess
2021-02-18 16:41   ` [PATCHv3 1/3] gdb: refactor the initialization file lookup code Andrew Burgess
2021-02-18 16:41   ` [PATCHv3 2/3] gdb: process early initialization files and command line options Andrew Burgess
2021-02-18 17:46     ` Eli Zaretskii via Gdb-patches
2021-03-24 12:10       ` Andrew Burgess
2021-03-24 17:17         ` Eli Zaretskii via Gdb-patches
2021-02-18 16:41   ` Andrew Burgess [this message]
2021-02-18 17:32     ` [PATCHv3 3/3] gdb: add "set startup-quietly" command Eli Zaretskii via Gdb-patches
2021-03-24 12:08       ` Andrew Burgess
2021-03-31 20:11   ` [PATCHv3 0/3] Adding startup files to GDB Andrew Burgess
2021-04-02 19:20     ` Tom Tromey

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=c935bb1214f0e27f8ad0e6a8b4b8dbe7046a8739.1613666281.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