This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[PATCH 4/6] new add_setshow_enum_cmd_with_notif and scheduler-locking.
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