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 5/6] new add_setshow_boolean_cmd_with_notify and circular-trace-buffer.
Date: Tue, 24 Jul 2012 16:12:00 -0000	[thread overview]
Message-ID: <1343146252-22558-6-git-send-email-yao@codesourcery.com> (raw)
In-Reply-To: <1343146252-22558-1-git-send-email-yao@codesourcery.com>

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-24  Yao Qi  <yao@codesourcery.com>

	* cli/cli-decode.c (add_setshow_auto_boolean_cmd): Move
	'boolean_enums' out.
	(add_setshow_boolean_cmd_with_notif): New.
	* command.h (extern void add_setshow_boolean_cmd): Declare
	it.
	* tracepoint.c (_initialize_tracepoint): Call
	add_setshow_boolean_cmd_with_notif.

gdb/testsuite:

2012-07-24  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                        |   26 +++++++++++++++++++++++++-
 gdb/command.h                               |   10 ++++++++++
 gdb/testsuite/gdb.mi/mi-cmd-opt-changed.exp |   17 +++++++++++++++++
 gdb/tracepoint.c                            |   12 ++++++------
 4 files changed, 58 insertions(+), 7 deletions(-)

diff --git a/gdb/cli/cli-decode.c b/gdb/cli/cli-decode.c
index 5d314db..b8dfb6c 100644
--- a/gdb/cli/cli-decode.c
+++ b/gdb/cli/cli-decode.c
@@ -486,6 +486,7 @@ 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
@@ -499,7 +500,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,
@@ -510,6 +510,30 @@ add_setshow_boolean_cmd (char *name, enum command_class class, int *var,
   c->enums = boolean_enums;
 }
 
+/* Same as add_setshow_boolean_cmd except that observer 'command_option_change'
+   will be notified if command option is changed.  */
+
+void
+add_setshow_boolean_cmd_with_notif (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)
+{
+  struct cmd_list_element *c;
+
+  add_setshow_cmd_full (name, class, var_boolean, var,
+			set_doc, show_doc, help_doc,
+			set_func, show_func,
+			set_list, show_list,
+			&c, NULL);
+  c->enums = boolean_enums;
+  c->notify_observer_p = 1;
+}
+
 /* Add element named NAME to both the set and show command LISTs (the
    list for set/show or some sublist thereof).  */
 void
diff --git a/gdb/command.h b/gdb/command.h
index 30c0eb2..c581997 100644
--- a/gdb/command.h
+++ b/gdb/command.h
@@ -277,6 +277,16 @@ extern void add_setshow_boolean_cmd (char *name,
 				     show_value_ftype *show_func,
 				     struct cmd_list_element **set_list,
 				     struct cmd_list_element **show_list);
+extern void add_setshow_boolean_cmd_with_notif (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 a733017..bedc2d7 100644
--- a/gdb/testsuite/gdb.mi/mi-cmd-opt-changed.exp
+++ b/gdb/testsuite/gdb.mi/mi-cmd-opt-changed.exp
@@ -53,6 +53,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..d09faf8 100644
--- a/gdb/tracepoint.c
+++ b/gdb/tracepoint.c
@@ -5344,17 +5344,17 @@ trace data collected in the meantime."),
 			   &setlist,
 			   &showlist);
 
-  add_setshow_boolean_cmd ("circular-trace-buffer", no_class,
-			   &circular_trace_buffer, _("\
+  add_setshow_boolean_cmd_with_notif ("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);
 
   add_setshow_string_cmd ("trace-user", class_trace,
 			  &trace_user, _("\
-- 
1.7.7.6


  parent reply	other threads:[~2012-07-24 16:12 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 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 ` [PATCH 4/6] new add_setshow_enum_cmd_with_notif and scheduler-locking Yao Qi
2012-07-24 20:50   ` Tom Tromey
2012-07-26 15:41     ` Pedro Alves
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 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 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:12 ` Yao Qi [this message]
2012-07-24 20:53   ` [PATCH 5/6] new add_setshow_boolean_cmd_with_notify and circular-trace-buffer 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-6-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