Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Yao Qi <yao@codesourcery.com>
To: <gdb-patches@sourceware.org>
Subject: [PATCH 4/6] new add_setshow_enum_cmd_with_notif and scheduler-locking.
Date: Tue, 24 Jul 2012 16:11:00 -0000	[thread overview]
Message-ID: <1343146252-22558-5-git-send-email-yao@codesourcery.com> (raw)
In-Reply-To: <1343146252-22558-1-git-send-email-yao@codesourcery.com>

Hi,
This patch is to add a new function add_setshow_enum_cmd_with_notif,
a friend function of add_setshow_enum_cmd.  If the command is
registered by this function, a MI notification is sent to MI frontend
when the option of command is changed.  We choose "scheduler-locking"
as one example of "enum" command, and write a test case for it.

gdb:

2012-07-23  Yao Qi  <yao@codesourcery.com>

	* cli/cli-decode.c (add_setshow_enum_cmd_with_notif): New.
	* command.h: Declare.
	* infrun.c (_initialize_infrun): Call
 	add_setshow_enum_cmd_with_notif.

gdb/testsuite:

2012-07-23  Yao Qi  <yao@codesourcery.com>

	* gdb.mi/mi-cmd-opt-changed.exp: New.
---
 gdb/cli/cli-decode.c                        |   28 ++++++++++++
 gdb/command.h                               |   12 +++++
 gdb/infrun.c                                |   11 +++--
 gdb/testsuite/gdb.mi/mi-cmd-opt-changed.exp |   61 +++++++++++++++++++++++++++
 4 files changed, 107 insertions(+), 5 deletions(-)
 create mode 100644 gdb/testsuite/gdb.mi/mi-cmd-opt-changed.exp

diff --git a/gdb/cli/cli-decode.c b/gdb/cli/cli-decode.c
index 6739aef..5d314db 100644
--- a/gdb/cli/cli-decode.c
+++ b/gdb/cli/cli-decode.c
@@ -431,6 +431,34 @@ add_setshow_enum_cmd (char *name,
   c->enums = enumlist;
 }
 
+/* Same as add_setshow_enum_cmd except that observer 'command_option_change'
+   will be notified if command option is changed.  */
+
+void
+add_setshow_enum_cmd_with_notif (char *name,
+				 enum command_class class,
+				 const char *const *enumlist,
+				 const char **var,
+				 const char *set_doc,
+				 const char *show_doc,
+				 const char *help_doc,
+				 cmd_sfunc_ftype *set_func,
+				 show_value_ftype *show_func,
+				 struct cmd_list_element **set_list,
+				 struct cmd_list_element **show_list)
+{
+  struct cmd_list_element *c;
+
+  add_setshow_cmd_full (name, class, var_enum, var,
+			set_doc, show_doc, help_doc,
+			set_func, show_func,
+			set_list, show_list,
+			&c, NULL);
+  c->enums = enumlist;
+
+  c->notify_observer_p = 1;
+}
+
 const char *auto_boolean_enums[] = { "on", "off", "auto", NULL };
 
 /* Add an auto-boolean command named NAME to both the set and show
diff --git a/gdb/command.h b/gdb/command.h
index 88895bb..30c0eb2 100644
--- a/gdb/command.h
+++ b/gdb/command.h
@@ -245,6 +245,18 @@ extern void add_setshow_enum_cmd (char *name,
 				  struct cmd_list_element **set_list,
 				  struct cmd_list_element **show_list);
 
+extern void add_setshow_enum_cmd_with_notif (char *name,
+					     enum command_class class,
+					     const char *const *enumlist,
+					     const char **var,
+					     const char *set_doc,
+					     const char *show_doc,
+					     const char *help_doc,
+					     cmd_sfunc_ftype *set_func,
+					     show_value_ftype *show_func,
+					     struct cmd_list_element **set_list,
+					     struct cmd_list_element **show_list);
+
 extern void add_setshow_auto_boolean_cmd (char *name,
 					  enum command_class class,
 					  enum auto_boolean *var,
diff --git a/gdb/infrun.c b/gdb/infrun.c
index efc4162..1c5778c 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -7250,8 +7250,8 @@ By default, the debugger will use the same inferior."),
 			show_follow_exec_mode_string,
 			&setlist, &showlist);
 
-  add_setshow_enum_cmd ("scheduler-locking", class_run, 
-			scheduler_enums, &scheduler_mode, _("\
+  add_setshow_enum_cmd_with_notif ("scheduler-locking", class_run, 
+				   scheduler_enums, &scheduler_mode, _("\
 Set mode for locking scheduler during execution."), _("\
 Show mode for locking scheduler during execution."), _("\
 off  == no locking (threads may preempt at any time)\n\
@@ -7259,9 +7259,10 @@ on   == full locking (no thread except the current thread may run)\n\
 step == scheduler locked during every single-step operation.\n\
 	In this mode, no other thread may run during a step command.\n\
 	Other threads may run while stepping over a function call ('next')."), 
-			set_schedlock_func,	/* traps on target vector */
-			show_scheduler_mode,
-			&setlist, &showlist);
+				   /* traps on target vector */
+				   set_schedlock_func,
+				   show_scheduler_mode,
+				   &setlist, &showlist);
 
   add_setshow_boolean_cmd ("schedule-multiple", class_run, &sched_multi, _("\
 Set mode for resuming threads of all processes."), _("\
diff --git a/gdb/testsuite/gdb.mi/mi-cmd-opt-changed.exp b/gdb/testsuite/gdb.mi/mi-cmd-opt-changed.exp
new file mode 100644
index 0000000..a733017
--- /dev/null
+++ b/gdb/testsuite/gdb.mi/mi-cmd-opt-changed.exp
@@ -0,0 +1,61 @@
+# Copyright 2012 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/>.
+
+load_lib mi-support.exp
+set MIFLAGS "-i=mi"
+
+set testfile "basics"
+set srcfile ${testfile}.c
+set binfile ${objdir}/${subdir}/mi-cmd-opt-changed
+
+if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
+     untested mi-cmd-opt-changed.exp
+     return -1
+}
+
+proc test_command_option_change { } { with_test_prefix "cmd option" {
+    if [mi_gdb_start] {
+	return
+    }
+    mi_run_to_main
+
+    foreach opt { "on" "off" "step" } {
+	mi_gdb_test "set scheduler-locking ${opt}" \
+	    ".*=option-changed,option=\"scheduler-locking\",value=\"${opt}\".*\\^done" \
+	    "\"set scheduler-locking ${opt}\""
+    }
+    foreach opt { "on" "off" "step" } {
+	mi_gdb_test "interpreter-exec console \"set scheduler-locking ${opt}\"" \
+	    ".*=option-changed,option=\"scheduler-locking\",value=\"${opt}\".*\\^done" \
+	    "interpreter-exec \"set scheduler-locking ${opt}\""
+    }
+    # Don't emit MI notification for request from MI.
+    mi_gdb_test "-gdb-set scheduler-locking on" \
+	{\^done} \
+	"\"set scheduler-locking on\" no event (requested by MI)"
+
+    mi_gdb_test "interpreter-exec mi \"-gdb-set scheduler-locking step\"" \
+	"\\&\"interpreter-exec mi .*\"-gdb-set scheduler-locking step.*\"\\\\n\"\r\n\\^done\r\n\\^done" \
+	"\"set scheduler-locking step\" no event (requested by MI interp)"
+    mi_gdb_test "set scheduler-locking step" \
+	"\\&\"set scheduler-locking step\\\\n\"\r\n\\^done" \
+	"\"set scheduler-locking stepr\" no event"
+
+    mi_gdb_exit
+}}
+
+test_command_option_change
+
+return 0
-- 
1.7.7.6


  parent reply	other threads:[~2012-07-24 16:11 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-24 16:11 [RFC 0/6] MI notification of command option change Yao Qi
2012-07-24 16:11 ` [PATCH 1/6] new observer command_option_changed Yao Qi
2012-07-24 20:39   ` Tom Tromey
2012-07-25  3:56     ` Yao Qi
2012-07-25 14:44       ` Tom Tromey
2012-07-26 15:21         ` Pedro Alves
2012-07-25 14:32   ` Tom Tromey
2012-07-26  8:55     ` Yao Qi
2012-07-24 16:11 ` [PATCH 6/6] new add_setshow_string_cmd_with_notif and trace-notes Yao Qi
2012-07-24 20:54   ` Tom Tromey
2012-07-24 16:11 ` [PATCH 3/6] attach to command_option-changed observer Yao Qi
2012-07-24 17:10   ` Eli Zaretskii
2012-07-24 20:47   ` Tom Tromey
2012-07-26 12:47     ` Yao Qi
2012-07-26 13:59       ` Tom Tromey
2012-07-26 15:31   ` Pedro Alves
2012-07-24 16:11 ` [PATCH 2/6] allow to suppress more mi notification Yao Qi
2012-07-24 20:40   ` Tom Tromey
2012-07-26 15:30   ` Pedro Alves
2012-07-27  2:57     ` Yao Qi
2012-07-27 13:27       ` Pedro Alves
2012-07-24 16:11 ` Yao Qi [this message]
2012-07-24 20:50   ` [PATCH 4/6] new add_setshow_enum_cmd_with_notif and scheduler-locking Tom Tromey
2012-07-26 15:41     ` Pedro Alves
2012-07-24 16:12 ` [PATCH 5/6] new add_setshow_boolean_cmd_with_notify and circular-trace-buffer Yao Qi
2012-07-24 20:53   ` 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=1343146252-22558-5-git-send-email-yao@codesourcery.com \
    --to=yao@codesourcery.com \
    --cc=gdb-patches@sourceware.org \
    /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