public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 0/3] Suppressing CLI notifications
@ 2021-12-01 15:08 Tankut Baris Aktemur
  2021-12-01 15:08 ` [PATCH 1/3] gdb/cli: convert cli_suppress_notification from int to bool Tankut Baris Aktemur
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: Tankut Baris Aktemur @ 2021-12-01 15:08 UTC (permalink / raw)
  To: gdb-patches

Hello,

This is a small series about suppressing CLI notifications.  This can
be useful for scripts.

Regards
Baris

Tankut Baris Aktemur (3):
  gdb/cli: convert cli_suppress_notification from int to bool
  gdb/cli: add a 'normal_stop' option to 'cli_suppress_notification'
  gdb: add the 'set/show suppress-notification-cli' command

 gdb/NEWS                                      |  5 +++
 gdb/cli/cli-cmds.c                            | 35 +++++++++++++++++++
 gdb/cli/cli-decode.c                          | 10 +++---
 gdb/cli/cli-decode.h                          |  2 +-
 gdb/cli/cli-interp.c                          |  9 ++---
 gdb/command.h                                 | 11 +++---
 .../gdb.base/cli-suppress-notification.c      | 22 ++++++++++++
 .../gdb.base/cli-suppress-notification.exp    | 33 +++++++++++++++++
 gdb/tui/tui-interp.c                          |  4 +++
 9 files changed, 117 insertions(+), 14 deletions(-)
 create mode 100644 gdb/testsuite/gdb.base/cli-suppress-notification.c
 create mode 100644 gdb/testsuite/gdb.base/cli-suppress-notification.exp

-- 
2.33.1

Intel Deutschland GmbH
Registered Address: Am Campeon 10, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de <http://www.intel.de>
Managing Directors: Christin Eisenschmid, Sharon Heck, Tiffany Doon Silva  
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 1/3] gdb/cli: convert cli_suppress_notification from int to bool
  2021-12-01 15:08 [PATCH 0/3] Suppressing CLI notifications Tankut Baris Aktemur
@ 2021-12-01 15:08 ` Tankut Baris Aktemur
  2022-01-14 15:52   ` Tom Tromey
  2021-12-01 15:08 ` [PATCH 2/3] gdb/cli: add a 'normal_stop' option to 'cli_suppress_notification' Tankut Baris Aktemur
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 9+ messages in thread
From: Tankut Baris Aktemur @ 2021-12-01 15:08 UTC (permalink / raw)
  To: gdb-patches

Convert the suppress_notification flag for the CLI from int to bool.
---
 gdb/cli/cli-decode.c | 10 +++++-----
 gdb/cli/cli-decode.h |  2 +-
 gdb/cli/cli-interp.c |  5 +----
 gdb/command.h        |  8 ++++----
 4 files changed, 11 insertions(+), 14 deletions(-)

diff --git a/gdb/cli/cli-decode.c b/gdb/cli/cli-decode.c
index 030cba44338..ebe6b924bf8 100644
--- a/gdb/cli/cli-decode.c
+++ b/gdb/cli/cli-decode.c
@@ -239,7 +239,7 @@ struct cmd_list_element *
 add_cmd_suppress_notification (const char *name, enum command_class theclass,
 			       cmd_simple_func_ftype *fun, const char *doc,
 			       struct cmd_list_element **list,
-			       int *suppress_notification)
+			       bool *suppress_notification)
 {
   struct cmd_list_element *element;
 
@@ -438,7 +438,7 @@ add_prefix_cmd_suppress_notification
 		cmd_simple_func_ftype *fun,
 		const char *doc, struct cmd_list_element **subcommands,
 		int allow_unknown, struct cmd_list_element **list,
-		int *suppress_notification)
+		bool *suppress_notification)
 {
   struct cmd_list_element *element
     = add_prefix_cmd (name, theclass, fun, doc, subcommands,
@@ -1312,7 +1312,7 @@ add_com_alias (const char *name, cmd_list_element *target,
 struct cmd_list_element *
 add_com_suppress_notification (const char *name, enum command_class theclass,
 			       cmd_simple_func_ftype *fun, const char *doc,
-			       int *suppress_notification)
+			       bool *suppress_notification)
 {
   return add_cmd_suppress_notification (name, theclass, fun, doc,
 					&cmdlist, suppress_notification);
@@ -2467,10 +2467,10 @@ cmd_func (struct cmd_list_element *cmd, const char *args, int from_tty)
 {
   if (!cmd->is_command_class_help ())
     {
-      gdb::optional<scoped_restore_tmpl<int>> restore_suppress;
+      gdb::optional<scoped_restore_tmpl<bool>> restore_suppress;
 
       if (cmd->suppress_notification != NULL)
-	restore_suppress.emplace (cmd->suppress_notification, 1);
+	restore_suppress.emplace (cmd->suppress_notification, true);
 
       cmd->func (args, from_tty, cmd);
     }
diff --git a/gdb/cli/cli-decode.h b/gdb/cli/cli-decode.h
index f7945ba2bf5..eee24bf8677 100644
--- a/gdb/cli/cli-decode.h
+++ b/gdb/cli/cli-decode.h
@@ -256,7 +256,7 @@ struct cmd_list_element
      cli_suppress_notification', which will be set to true in cmd_func
      when this command is being executed.  It will be set back to false
      when the command has been executed.  */
-  int *suppress_notification = nullptr;
+  bool *suppress_notification = nullptr;
 
 private:
   /* Local state (context) for this command.  This can be anything.  */
diff --git a/gdb/cli/cli-interp.c b/gdb/cli/cli-interp.c
index 47d1eff0547..db5e313d36e 100644
--- a/gdb/cli/cli-interp.c
+++ b/gdb/cli/cli-interp.c
@@ -68,10 +68,7 @@ cli_interp::~cli_interp ()
 }
 
 /* Suppress notification struct.  */
-struct cli_suppress_notification cli_suppress_notification =
-  {
-    0   /* user_selected_context_changed */
-  };
+struct cli_suppress_notification cli_suppress_notification;
 
 /* Returns the INTERP's data cast as cli_interp if INTERP is a CLI,
    and returns NULL otherwise.  */
diff --git a/gdb/command.h b/gdb/command.h
index bcd3882f811..6ae57dcc030 100644
--- a/gdb/command.h
+++ b/gdb/command.h
@@ -378,7 +378,7 @@ typedef void cmd_simple_func_ftype (const char *args, int from_tty);
 struct cli_suppress_notification
 {
   /* Inferior, thread, frame selected notification suppressed?  */
-  int user_selected_context;
+  bool user_selected_context = false;
 };
 
 extern struct cli_suppress_notification cli_suppress_notification;
@@ -421,7 +421,7 @@ extern struct cmd_list_element *add_cmd_suppress_notification
 			(const char *name, enum command_class theclass,
 			 cmd_simple_func_ftype *fun, const char *doc,
 			 struct cmd_list_element **list,
-			 int *suppress_notification);
+			 bool *suppress_notification);
 
 extern struct cmd_list_element *add_alias_cmd (const char *,
 					       cmd_list_element *,
@@ -467,7 +467,7 @@ extern struct cmd_list_element *add_prefix_cmd_suppress_notification
 			 const char *doc, struct cmd_list_element **subcommands,
 			 int allow_unknown,
 			 struct cmd_list_element **list,
-			 int *suppress_notification);
+			 bool *suppress_notification);
 
 extern struct cmd_list_element *add_abbrev_prefix_cmd (const char *,
 						       enum command_class,
@@ -615,7 +615,7 @@ extern cmd_list_element *add_com_alias (const char *name,
 extern struct cmd_list_element *add_com_suppress_notification
 		       (const char *name, enum command_class theclass,
 			cmd_simple_func_ftype *fun, const char *doc,
-			int *supress_notification);
+			bool *supress_notification);
 
 extern struct cmd_list_element *add_info (const char *,
 					  cmd_simple_func_ftype *fun,
-- 
2.33.1

Intel Deutschland GmbH
Registered Address: Am Campeon 10, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de <http://www.intel.de>
Managing Directors: Christin Eisenschmid, Sharon Heck, Tiffany Doon Silva  
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 2/3] gdb/cli: add a 'normal_stop' option to 'cli_suppress_notification'
  2021-12-01 15:08 [PATCH 0/3] Suppressing CLI notifications Tankut Baris Aktemur
  2021-12-01 15:08 ` [PATCH 1/3] gdb/cli: convert cli_suppress_notification from int to bool Tankut Baris Aktemur
@ 2021-12-01 15:08 ` Tankut Baris Aktemur
  2022-01-14 16:01   ` Tom Tromey
  2021-12-01 15:08 ` [PATCH 3/3] gdb: add the 'set/show suppress-notification-cli' command Tankut Baris Aktemur
  2022-01-14 12:13 ` [PATCH 0/3] Suppressing CLI notifications Aktemur, Tankut Baris
  3 siblings, 1 reply; 9+ messages in thread
From: Tankut Baris Aktemur @ 2021-12-01 15:08 UTC (permalink / raw)
  To: gdb-patches

Extend the 'cli_suppress_notification' struct with a new field,
'normal_stop', that can be used for checking if printing normal stop
events on the CLI should be suppressed.

This patch only introduces the flag.  The subsequent patch adds a user
command to turn the flag off/on.
---
 gdb/cli/cli-interp.c | 4 ++++
 gdb/command.h        | 3 +++
 gdb/tui/tui-interp.c | 4 ++++
 3 files changed, 11 insertions(+)

diff --git a/gdb/cli/cli-interp.c b/gdb/cli/cli-interp.c
index db5e313d36e..425c4b2f815 100644
--- a/gdb/cli/cli-interp.c
+++ b/gdb/cli/cli-interp.c
@@ -127,6 +127,10 @@ cli_on_normal_stop (struct bpstat *bs, int print_frame)
   if (!print_frame)
     return;
 
+  /* This event is suppressed.  */
+  if (cli_suppress_notification.normal_stop)
+    return;
+
   SWITCH_THRU_ALL_UIS ()
     {
       struct interp *interp = top_level_interpreter ();
diff --git a/gdb/command.h b/gdb/command.h
index 6ae57dcc030..2a4aacbd18f 100644
--- a/gdb/command.h
+++ b/gdb/command.h
@@ -379,6 +379,9 @@ struct cli_suppress_notification
 {
   /* Inferior, thread, frame selected notification suppressed?  */
   bool user_selected_context = false;
+
+  /* Normal stop event suppressed? */
+  bool normal_stop = false;
 };
 
 extern struct cli_suppress_notification cli_suppress_notification;
diff --git a/gdb/tui/tui-interp.c b/gdb/tui/tui-interp.c
index 0cd5b125919..1d9ac9585bc 100644
--- a/gdb/tui/tui-interp.c
+++ b/gdb/tui/tui-interp.c
@@ -84,6 +84,10 @@ tui_on_normal_stop (struct bpstat *bs, int print_frame)
   if (!print_frame)
     return;
 
+  /* This event is suppressed.  */
+  if (cli_suppress_notification.normal_stop)
+    return;
+
   SWITCH_THRU_ALL_UIS ()
     {
       struct interp *interp = top_level_interpreter ();
-- 
2.33.1

Intel Deutschland GmbH
Registered Address: Am Campeon 10, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de <http://www.intel.de>
Managing Directors: Christin Eisenschmid, Sharon Heck, Tiffany Doon Silva  
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 3/3] gdb: add the 'set/show suppress-notification-cli' command
  2021-12-01 15:08 [PATCH 0/3] Suppressing CLI notifications Tankut Baris Aktemur
  2021-12-01 15:08 ` [PATCH 1/3] gdb/cli: convert cli_suppress_notification from int to bool Tankut Baris Aktemur
  2021-12-01 15:08 ` [PATCH 2/3] gdb/cli: add a 'normal_stop' option to 'cli_suppress_notification' Tankut Baris Aktemur
@ 2021-12-01 15:08 ` Tankut Baris Aktemur
  2022-01-14 16:04   ` Tom Tromey
  2022-01-18 10:41   ` Andrew Burgess
  2022-01-14 12:13 ` [PATCH 0/3] Suppressing CLI notifications Aktemur, Tankut Baris
  3 siblings, 2 replies; 9+ messages in thread
From: Tankut Baris Aktemur @ 2021-12-01 15:08 UTC (permalink / raw)
  To: gdb-patches

GDB already has a flag to suppress printing notification events, such
as thread and inferior context switches, on the CLI.  This is used
internally when executing commands.  Make the flag available to the
user via a new command.  This is expected to be useful in scripts.
---
 gdb/NEWS                                      |  5 +++
 gdb/cli/cli-cmds.c                            | 35 +++++++++++++++++++
 .../gdb.base/cli-suppress-notification.c      | 22 ++++++++++++
 .../gdb.base/cli-suppress-notification.exp    | 33 +++++++++++++++++
 4 files changed, 95 insertions(+)
 create mode 100644 gdb/testsuite/gdb.base/cli-suppress-notification.c
 create mode 100644 gdb/testsuite/gdb.base/cli-suppress-notification.exp

diff --git a/gdb/NEWS b/gdb/NEWS
index eeca1d39b10..76c9738bf03 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -39,6 +39,11 @@ set logging enabled on|off
 show logging enabled
   These commands set or show whether logging is enabled or disabled.
 
+maint set suppress-notification-cli (on|off)
+maint show suppress-notification-cli
+  This controls whether printing the notification events is suppressed
+  for CLI.
+
 * Changed commands
 
 maint packet
diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c
index 3fe47940076..5ad0a29052c 100644
--- a/gdb/cli/cli-cmds.c
+++ b/gdb/cli/cli-cmds.c
@@ -192,6 +192,11 @@ static const char *const script_ext_enums[] = {
 
 static const char *script_ext_mode = script_ext_soft;
 \f
+
+/* User-controllable flag to suppress event notification on CLI.  */
+
+static bool user_wants_cli_suppress_notification = false;
+
 /* Utility used everywhere when at least one argument is needed and
    none is supplied.  */
 
@@ -2123,6 +2128,24 @@ show_max_user_call_depth (struct ui_file *file, int from_tty,
 		    value);
 }
 
+static void
+maint_show_suppress_notification_cli (ui_file *file, int from_tty,
+				      cmd_list_element *c, const char *value)
+{
+  fprintf_filtered (file, _("Suppression of printing CLI notification events "
+			    "is %s.\n"), value);
+}
+
+static void
+maint_set_suppress_notification_cli (const char *args, int from_tty,
+				     cmd_list_element *c)
+{
+  cli_suppress_notification.user_selected_context
+    = user_wants_cli_suppress_notification;
+  cli_suppress_notification.normal_stop
+    = user_wants_cli_suppress_notification;
+}
+
 /* Returns the cmd_list_element in SHOWLIST corresponding to the first
    argument of ARGV, which must contain one single value.
    Throws an error if no value provided, or value not correct.
@@ -2720,6 +2743,18 @@ Make \"wLapPeu\" an alias of 2 nested \"with\":\n\
 
   set_cmd_completer_handle_brkchars (c, alias_command_completer);
 
+  add_setshow_boolean_cmd ("suppress-notification-cli", no_class,
+			   &user_wants_cli_suppress_notification,
+			   _("\
+Set whether printing notification events on CLI is suppressed."), _("\
+Show whether printing notification events on CLI is suppressed."), _("\
+When on, printing notification events (such as inferior/thread switch)\n\
+on CLI is suppressed."),
+			   maint_set_suppress_notification_cli,
+			   maint_show_suppress_notification_cli,
+			   &maintenance_set_cmdlist,
+			   &maintenance_show_cmdlist);
+
   const char *source_help_text = xstrprintf (_("\
 Read commands from a file named FILE.\n\
 \n\
diff --git a/gdb/testsuite/gdb.base/cli-suppress-notification.c b/gdb/testsuite/gdb.base/cli-suppress-notification.c
new file mode 100644
index 00000000000..d5142fed2ca
--- /dev/null
+++ b/gdb/testsuite/gdb.base/cli-suppress-notification.c
@@ -0,0 +1,22 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2020-2021 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+int
+main ()
+{
+  return 0;
+}
diff --git a/gdb/testsuite/gdb.base/cli-suppress-notification.exp b/gdb/testsuite/gdb.base/cli-suppress-notification.exp
new file mode 100644
index 00000000000..97fc83eb94a
--- /dev/null
+++ b/gdb/testsuite/gdb.base/cli-suppress-notification.exp
@@ -0,0 +1,33 @@
+# Copyright 2020-2021 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# Test the cli-suppress-notification command.
+
+standard_testfile
+
+if {[prepare_for_testing "failed to prepare" ${binfile} ${srcfile}]} {
+    return
+}
+
+if {![runto_main]} {
+    return
+}
+
+gdb_test "inferior 1" ".*Switching to inferior 1 .* to thread 1 .*" \
+    "not suppressed"
+
+gdb_test_no_output "maint set suppress-notification-cli on"
+
+gdb_test_no_output "inferior 1" "suppressed"
-- 
2.33.1

Intel Deutschland GmbH
Registered Address: Am Campeon 10, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de <http://www.intel.de>
Managing Directors: Christin Eisenschmid, Sharon Heck, Tiffany Doon Silva  
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928


^ permalink raw reply	[flat|nested] 9+ messages in thread

* RE: [PATCH 0/3] Suppressing CLI notifications
  2021-12-01 15:08 [PATCH 0/3] Suppressing CLI notifications Tankut Baris Aktemur
                   ` (2 preceding siblings ...)
  2021-12-01 15:08 ` [PATCH 3/3] gdb: add the 'set/show suppress-notification-cli' command Tankut Baris Aktemur
@ 2022-01-14 12:13 ` Aktemur, Tankut Baris
  3 siblings, 0 replies; 9+ messages in thread
From: Aktemur, Tankut Baris @ 2022-01-14 12:13 UTC (permalink / raw)
  To: gdb-patches

On Wednesday, December 1, 2021 4:08 PM, Aktemur, Tankut Baris wrote:
> 
> Hello,
> 
> This is a small series about suppressing CLI notifications.  This can
> be useful for scripts.
> 
> Regards
> Baris
> 
> Tankut Baris Aktemur (3):
>   gdb/cli: convert cli_suppress_notification from int to bool
>   gdb/cli: add a 'normal_stop' option to 'cli_suppress_notification'
>   gdb: add the 'set/show suppress-notification-cli' command
> 

Kindly pinging.

Thanks
-Baris


Intel Deutschland GmbH
Registered Address: Am Campeon 10, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de <http://www.intel.de>
Managing Directors: Christin Eisenschmid, Sharon Heck, Tiffany Doon Silva  
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/3] gdb/cli: convert cli_suppress_notification from int to bool
  2021-12-01 15:08 ` [PATCH 1/3] gdb/cli: convert cli_suppress_notification from int to bool Tankut Baris Aktemur
@ 2022-01-14 15:52   ` Tom Tromey
  0 siblings, 0 replies; 9+ messages in thread
From: Tom Tromey @ 2022-01-14 15:52 UTC (permalink / raw)
  To: Tankut Baris Aktemur via Gdb-patches

>>>>> ">" == Tankut Baris Aktemur via Gdb-patches <gdb-patches@sourceware.org> writes:

>> Convert the suppress_notification flag for the CLI from int to bool.

Thanks.  This is ok.

Tom

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/3] gdb/cli: add a 'normal_stop' option to 'cli_suppress_notification'
  2021-12-01 15:08 ` [PATCH 2/3] gdb/cli: add a 'normal_stop' option to 'cli_suppress_notification' Tankut Baris Aktemur
@ 2022-01-14 16:01   ` Tom Tromey
  0 siblings, 0 replies; 9+ messages in thread
From: Tom Tromey @ 2022-01-14 16:01 UTC (permalink / raw)
  To: Tankut Baris Aktemur via Gdb-patches

>>>>> ">" == Tankut Baris Aktemur via Gdb-patches <gdb-patches@sourceware.org> writes:

>> Extend the 'cli_suppress_notification' struct with a new field,
>> 'normal_stop', that can be used for checking if printing normal stop
>> events on the CLI should be suppressed.

>> This patch only introduces the flag.  The subsequent patch adds a user
>> command to turn the flag off/on.

Thanks.  This is ok, though I think it shouldn't land until the
subsequent patch is also approved.

Tom

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 3/3] gdb: add the 'set/show suppress-notification-cli' command
  2021-12-01 15:08 ` [PATCH 3/3] gdb: add the 'set/show suppress-notification-cli' command Tankut Baris Aktemur
@ 2022-01-14 16:04   ` Tom Tromey
  2022-01-18 10:41   ` Andrew Burgess
  1 sibling, 0 replies; 9+ messages in thread
From: Tom Tromey @ 2022-01-14 16:04 UTC (permalink / raw)
  To: Tankut Baris Aktemur via Gdb-patches

>>>>> ">" == Tankut Baris Aktemur via Gdb-patches <gdb-patches@sourceware.org> writes:

>> GDB already has a flag to suppress printing notification events, such
>> as thread and inferior context switches, on the CLI.  This is used
>> internally when executing commands.  Make the flag available to the
>> user via a new command.  This is expected to be useful in scripts.

Why a "maint" command?

I think in general "maint" should be restricted to things that aren't
useful in any sort of normal way -- commands for gdb developers, or to
change internal settings that we think shouldn't really be changed.
This is reflected in the way that we are more lax about output changes
in maint commands.  (FWIW this is why I think we should move the "set
debug" settings under "maint".)

Also this requires a gdb.texinfo update, regardless of the spelling.

And it would be handy to see an example of when you'd want to use this.

thanks,
Tom

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 3/3] gdb: add the 'set/show suppress-notification-cli' command
  2021-12-01 15:08 ` [PATCH 3/3] gdb: add the 'set/show suppress-notification-cli' command Tankut Baris Aktemur
  2022-01-14 16:04   ` Tom Tromey
@ 2022-01-18 10:41   ` Andrew Burgess
  1 sibling, 0 replies; 9+ messages in thread
From: Andrew Burgess @ 2022-01-18 10:41 UTC (permalink / raw)
  To: Tankut Baris Aktemur; +Cc: gdb-patches

* Tankut Baris Aktemur <tankut.baris.aktemur@intel.com> [2021-12-01 16:08:29 +0100]:

> GDB already has a flag to suppress printing notification events, such
> as thread and inferior context switches, on the CLI.  This is used
> internally when executing commands.  Make the flag available to the
> user via a new command.  This is expected to be useful in scripts.

I agree with Tom that this should not be a maint command if you expect
users to be using it.  I also agree it needs a doc entry.

What I would add, is that I think you need to expand on
"notifications" is more places with an explicit list of exactly what
is being suppressed.  Even for someone familiar with GDB it's not
clear what this covers, and for a user, trying to achieve some result
it's not obvious what the flag is expected to do.

Thanks,
Andrew



> ---
>  gdb/NEWS                                      |  5 +++
>  gdb/cli/cli-cmds.c                            | 35 +++++++++++++++++++
>  .../gdb.base/cli-suppress-notification.c      | 22 ++++++++++++
>  .../gdb.base/cli-suppress-notification.exp    | 33 +++++++++++++++++
>  4 files changed, 95 insertions(+)
>  create mode 100644 gdb/testsuite/gdb.base/cli-suppress-notification.c
>  create mode 100644 gdb/testsuite/gdb.base/cli-suppress-notification.exp
> 
> diff --git a/gdb/NEWS b/gdb/NEWS
> index eeca1d39b10..76c9738bf03 100644
> --- a/gdb/NEWS
> +++ b/gdb/NEWS
> @@ -39,6 +39,11 @@ set logging enabled on|off
>  show logging enabled
>    These commands set or show whether logging is enabled or disabled.
>  
> +maint set suppress-notification-cli (on|off)
> +maint show suppress-notification-cli
> +  This controls whether printing the notification events is suppressed
> +  for CLI.
> +
>  * Changed commands
>  
>  maint packet
> diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c
> index 3fe47940076..5ad0a29052c 100644
> --- a/gdb/cli/cli-cmds.c
> +++ b/gdb/cli/cli-cmds.c
> @@ -192,6 +192,11 @@ static const char *const script_ext_enums[] = {
>  
>  static const char *script_ext_mode = script_ext_soft;
>  \f
> +
> +/* User-controllable flag to suppress event notification on CLI.  */
> +
> +static bool user_wants_cli_suppress_notification = false;
> +
>  /* Utility used everywhere when at least one argument is needed and
>     none is supplied.  */
>  
> @@ -2123,6 +2128,24 @@ show_max_user_call_depth (struct ui_file *file, int from_tty,
>  		    value);
>  }
>  
> +static void
> +maint_show_suppress_notification_cli (ui_file *file, int from_tty,
> +				      cmd_list_element *c, const char *value)
> +{
> +  fprintf_filtered (file, _("Suppression of printing CLI notification events "
> +			    "is %s.\n"), value);
> +}
> +
> +static void
> +maint_set_suppress_notification_cli (const char *args, int from_tty,
> +				     cmd_list_element *c)
> +{
> +  cli_suppress_notification.user_selected_context
> +    = user_wants_cli_suppress_notification;
> +  cli_suppress_notification.normal_stop
> +    = user_wants_cli_suppress_notification;
> +}
> +
>  /* Returns the cmd_list_element in SHOWLIST corresponding to the first
>     argument of ARGV, which must contain one single value.
>     Throws an error if no value provided, or value not correct.
> @@ -2720,6 +2743,18 @@ Make \"wLapPeu\" an alias of 2 nested \"with\":\n\
>  
>    set_cmd_completer_handle_brkchars (c, alias_command_completer);
>  
> +  add_setshow_boolean_cmd ("suppress-notification-cli", no_class,
> +			   &user_wants_cli_suppress_notification,
> +			   _("\
> +Set whether printing notification events on CLI is suppressed."), _("\
> +Show whether printing notification events on CLI is suppressed."), _("\
> +When on, printing notification events (such as inferior/thread switch)\n\
> +on CLI is suppressed."),
> +			   maint_set_suppress_notification_cli,
> +			   maint_show_suppress_notification_cli,
> +			   &maintenance_set_cmdlist,
> +			   &maintenance_show_cmdlist);
> +
>    const char *source_help_text = xstrprintf (_("\
>  Read commands from a file named FILE.\n\
>  \n\
> diff --git a/gdb/testsuite/gdb.base/cli-suppress-notification.c b/gdb/testsuite/gdb.base/cli-suppress-notification.c
> new file mode 100644
> index 00000000000..d5142fed2ca
> --- /dev/null
> +++ b/gdb/testsuite/gdb.base/cli-suppress-notification.c
> @@ -0,0 +1,22 @@
> +/* This testcase is part of GDB, the GNU debugger.
> +
> +   Copyright 2020-2021 Free Software Foundation, Inc.
> +
> +   This program is free software; you can redistribute it and/or modify
> +   it under the terms of the GNU General Public License as published by
> +   the Free Software Foundation; either version 3 of the License, or
> +   (at your option) any later version.
> +
> +   This program is distributed in the hope that it will be useful,
> +   but WITHOUT ANY WARRANTY; without even the implied warranty of
> +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +   GNU General Public License for more details.
> +
> +   You should have received a copy of the GNU General Public License
> +   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
> +
> +int
> +main ()
> +{
> +  return 0;
> +}
> diff --git a/gdb/testsuite/gdb.base/cli-suppress-notification.exp b/gdb/testsuite/gdb.base/cli-suppress-notification.exp
> new file mode 100644
> index 00000000000..97fc83eb94a
> --- /dev/null
> +++ b/gdb/testsuite/gdb.base/cli-suppress-notification.exp
> @@ -0,0 +1,33 @@
> +# Copyright 2020-2021 Free Software Foundation, Inc.
> +
> +# This program is free software; you can redistribute it and/or modify
> +# it under the terms of the GNU General Public License as published by
> +# the Free Software Foundation; either version 3 of the License, or
> +# (at your option) any later version.
> +#
> +# This program is distributed in the hope that it will be useful,
> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +# GNU General Public License for more details.
> +#
> +# You should have received a copy of the GNU General Public License
> +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
> +
> +# Test the cli-suppress-notification command.
> +
> +standard_testfile
> +
> +if {[prepare_for_testing "failed to prepare" ${binfile} ${srcfile}]} {
> +    return
> +}
> +
> +if {![runto_main]} {
> +    return
> +}
> +
> +gdb_test "inferior 1" ".*Switching to inferior 1 .* to thread 1 .*" \
> +    "not suppressed"
> +
> +gdb_test_no_output "maint set suppress-notification-cli on"
> +
> +gdb_test_no_output "inferior 1" "suppressed"
> -- 
> 2.33.1
> 
> Intel Deutschland GmbH
> Registered Address: Am Campeon 10, 85579 Neubiberg, Germany
> Tel: +49 89 99 8853-0, www.intel.de <http://www.intel.de>
> Managing Directors: Christin Eisenschmid, Sharon Heck, Tiffany Doon Silva  
> Chairperson of the Supervisory Board: Nicole Lau
> Registered Office: Munich
> Commercial Register: Amtsgericht Muenchen HRB 186928
> 
> 


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2022-01-18 10:42 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-01 15:08 [PATCH 0/3] Suppressing CLI notifications Tankut Baris Aktemur
2021-12-01 15:08 ` [PATCH 1/3] gdb/cli: convert cli_suppress_notification from int to bool Tankut Baris Aktemur
2022-01-14 15:52   ` Tom Tromey
2021-12-01 15:08 ` [PATCH 2/3] gdb/cli: add a 'normal_stop' option to 'cli_suppress_notification' Tankut Baris Aktemur
2022-01-14 16:01   ` Tom Tromey
2021-12-01 15:08 ` [PATCH 3/3] gdb: add the 'set/show suppress-notification-cli' command Tankut Baris Aktemur
2022-01-14 16:04   ` Tom Tromey
2022-01-18 10:41   ` Andrew Burgess
2022-01-14 12:13 ` [PATCH 0/3] Suppressing CLI notifications Aktemur, Tankut Baris

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).