This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[PATCH 5/7] notify in boolean_cmd and circular-trace-buffer.
Hi,
Similar to previous patch, this patch is to add a new function
add_setshow_boolean_cmd_with_notif, and register command
"circular-trace-buffer" as an example to boolean command. A new
test case is added for it.
gdb:
2012-07-27 Yao Qi <yao@codesourcery.com>
* cli/cli-decode.c (add_setshow_auto_boolean_cmd): Move
'boolean_enums' out.
Return 'struct cmd_list_element *' for set command.
* command.h: Update declaration of add_setshow_auto_boolean_cmd.
* tracepoint.c (_initialize_tracepoint): Get the return value
of add_setshow_auto_boolean_cmd can call set_cmd_notify.
gdb/testsuite:
2012-07-27 Yao Qi <yao@codesourcery.com>
* gdb.mi/mi-cmd-opt-changed.exp (test_command_option_change): Test for command
'circular-trace-buffer'.
---
gdb/cli/cli-decode.c | 9 ++++++---
gdb/command.h | 19 ++++++++++---------
gdb/testsuite/gdb.mi/mi-cmd-opt-changed.exp | 17 +++++++++++++++++
gdb/tracepoint.c | 13 +++++++------
4 files changed, 40 insertions(+), 18 deletions(-)
diff --git a/gdb/cli/cli-decode.c b/gdb/cli/cli-decode.c
index 2dd4b1f..c185575 100644
--- a/gdb/cli/cli-decode.c
+++ b/gdb/cli/cli-decode.c
@@ -470,11 +470,13 @@ add_setshow_auto_boolean_cmd (char *name,
c->enums = auto_boolean_enums;
}
+static const char *boolean_enums[] = { "on", "off", NULL };
/* Add element named NAME to both the set and show command LISTs (the
list for set/show or some sublist thereof). CLASS is as in
add_cmd. VAR is address of the variable which will contain the
- value. SET_DOC and SHOW_DOC are the documentation strings. */
-void
+ value. SET_DOC and SHOW_DOC are the documentation strings. Return
+ the 'set' command handler.*/
+struct cmd_list_element *
add_setshow_boolean_cmd (char *name, enum command_class class, int *var,
const char *set_doc, const char *show_doc,
const char *help_doc,
@@ -483,7 +485,6 @@ add_setshow_boolean_cmd (char *name, enum command_class class, int *var,
struct cmd_list_element **set_list,
struct cmd_list_element **show_list)
{
- static const char *boolean_enums[] = { "on", "off", NULL };
struct cmd_list_element *c;
add_setshow_cmd_full (name, class, var_boolean, var,
@@ -492,6 +493,8 @@ add_setshow_boolean_cmd (char *name, enum command_class class, int *var,
set_list, show_list,
&c, NULL);
c->enums = boolean_enums;
+
+ return c;
}
/* Add element named NAME to both the set and show command LISTs (the
diff --git a/gdb/command.h b/gdb/command.h
index 3f3703c..692a16f 100644
--- a/gdb/command.h
+++ b/gdb/command.h
@@ -259,15 +259,16 @@ extern void add_setshow_auto_boolean_cmd (char *name,
struct cmd_list_element **set_list,
struct cmd_list_element **show_list);
-extern void add_setshow_boolean_cmd (char *name,
- enum command_class class,
- int *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_boolean_cmd (char *name,
+ enum command_class class,
+ int *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_filename_cmd (char *name,
enum command_class class,
diff --git a/gdb/testsuite/gdb.mi/mi-cmd-opt-changed.exp b/gdb/testsuite/gdb.mi/mi-cmd-opt-changed.exp
index c8011a9..e348483 100644
--- a/gdb/testsuite/gdb.mi/mi-cmd-opt-changed.exp
+++ b/gdb/testsuite/gdb.mi/mi-cmd-opt-changed.exp
@@ -51,6 +51,23 @@ proc test_command_option_change { } { with_test_prefix "cmd option" {
"\\&\"set scheduler-locking step\\\\n\"\r\n\\^done" \
"\"set scheduler-locking stepr\" no event"
+
+ foreach command { "circular-trace-buffer" } {
+
+ # The default value of each command option may be different, so we first
+ # set it to 'off', and this may or may not trigger MI notification.
+ mi_gdb_test "set ${command} off" ".*\\^done" "\"set ${command}\" warmup"
+
+ foreach boolean_opt { "on" "off" } {
+ mi_gdb_test "set ${command} ${boolean_opt}" \
+ ".*=option-changed,option=\"${command}\",value=\"${boolean_opt}\".*\\^done" \
+ "\"set ${command} ${boolean_opt}\""
+ }
+ mi_gdb_test "set ${command} off" \
+ "\\&\"set ${command} off\\\\n\"\r\n\\^done" \
+ "\"set ${command}\" no event"
+ }
+
mi_gdb_exit
}}
diff --git a/gdb/tracepoint.c b/gdb/tracepoint.c
index 8c8d4a8..e7db0f6 100644
--- a/gdb/tracepoint.c
+++ b/gdb/tracepoint.c
@@ -5344,17 +5344,18 @@ trace data collected in the meantime."),
&setlist,
&showlist);
- add_setshow_boolean_cmd ("circular-trace-buffer", no_class,
- &circular_trace_buffer, _("\
+ c = add_setshow_boolean_cmd ("circular-trace-buffer", no_class,
+ &circular_trace_buffer, _("\
Set target's use of circular trace buffer."), _("\
Show target's use of circular trace buffer."), _("\
Use this to make the trace buffer into a circular buffer,\n\
which will discard traceframes (oldest first) instead of filling\n\
up and stopping the trace run."),
- set_circular_trace_buffer,
- NULL,
- &setlist,
- &showlist);
+ set_circular_trace_buffer,
+ NULL,
+ &setlist,
+ &showlist);
+ set_cmd_notify (c);
add_setshow_string_cmd ("trace-user", class_trace,
&trace_user, _("\
--
1.7.7.6