This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[PATCH 3/6] notify in enum_cmd and scheduler-locking.
Hi,
This patch is to change add_setshow_enum_cmd to return
'struct cmd_list_element *' for set command. If the command is
set by 'set_cmd_notify', 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.
This is V2, compared with V1, I change add_setshow_enum_cmd to
return set command handler, and use 'set_cmd_notify' to set command.
gdb:
2012-07-27 Yao Qi <yao@codesourcery.com>
* cli/cli-decode.c (set_cmd_notify): New.
(add_setshow_enum_cmd): Return 'struct cmd_list_element *' for
set command.
* command.h: Declare set_cmd_notify. Update the declaration of
add_setshow_enum_cmd.
* infrun.c (_initialize_infrun): Get the return value of
add_setshow_enum_cmd and call set_cmd_notify.
gdb/testsuite:
2012-07-27 Yao Qi <yao@codesourcery.com>
* gdb.mi/mi-cmd-opt-changed.exp: New.
---
gdb/cli/cli-decode.c | 16 ++++++-
gdb/command.h | 25 ++++++-----
gdb/infrun.c | 13 ++++--
gdb/testsuite/gdb.mi/mi-cmd-opt-changed.exp | 59 +++++++++++++++++++++++++++
4 files changed, 95 insertions(+), 18 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 35c7e1e..2dd4b1f 100644
--- a/gdb/cli/cli-decode.c
+++ b/gdb/cli/cli-decode.c
@@ -323,6 +323,15 @@ empty_sfunc (char *args, int from_tty, struct cmd_list_element *c)
{
}
+/* The observer 'command_option_changed' will be notified when command
+ CMD option is changed. */
+
+void
+set_cmd_notify (struct cmd_list_element *cmd)
+{
+ cmd->notify_observer_p = 1;
+}
+
/* Add element named NAME to command list LIST (the list for set/show
or some sublist thereof).
TYPE is set_cmd or show_cmd.
@@ -406,9 +415,10 @@ add_setshow_cmd_full (char *name,
/* Add element named NAME to command list LIST (the list for set or
some sublist thereof). CLASS is as in add_cmd. ENUMLIST is a list
of strings which may follow NAME. VAR is address of the variable
- which will contain the matching string (from ENUMLIST). */
+ which will contain the matching string (from ENUMLIST). Return the
+ 'set' command handler. */
-void
+struct cmd_list_element *
add_setshow_enum_cmd (char *name,
enum command_class class,
const char *const *enumlist,
@@ -429,6 +439,8 @@ add_setshow_enum_cmd (char *name,
set_list, show_list,
&c, NULL);
c->enums = enumlist;
+
+ return c;
}
const char * const auto_boolean_enums[] = { "on", "off", "auto", NULL };
diff --git a/gdb/command.h b/gdb/command.h
index 88895bb..3f3703c 100644
--- a/gdb/command.h
+++ b/gdb/command.h
@@ -193,6 +193,8 @@ extern struct cmd_list_element *deprecate_cmd (struct cmd_list_element *,
extern void deprecated_cmd_warning (char **);
+extern void set_cmd_notify (struct cmd_list_element *);
+
extern int lookup_cmd_composition (char *text,
struct cmd_list_element **alias,
struct cmd_list_element **prefix_cmd,
@@ -233,17 +235,18 @@ typedef void (show_value_ftype) (struct ui_file *file,
instead print the value out directly. */
extern show_value_ftype deprecated_show_value_hack;
-extern void add_setshow_enum_cmd (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 struct cmd_list_element *
+ add_setshow_enum_cmd (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,
diff --git a/gdb/infrun.c b/gdb/infrun.c
index efc4162..39ec552 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -7059,6 +7059,7 @@ _initialize_infrun (void)
{
int i;
int numsigs;
+ struct cmd_list_element *c;
add_info ("signals", signals_info, _("\
What debugger does when program gets various signals.\n\
@@ -7250,8 +7251,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, _("\
+ c = add_setshow_enum_cmd ("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 +7260,11 @@ 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);
+ set_cmd_notify (c);
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..c8011a9
--- /dev/null
+++ b/gdb/testsuite/gdb.mi/mi-cmd-opt-changed.exp
@@ -0,0 +1,59 @@
+# 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"
+
+standard_testfile basics.c
+
+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