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 1/6] new observer command_option_changed.
Date: Tue, 24 Jul 2012 16:11:00 -0000	[thread overview]
Message-ID: <1343146252-22558-2-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 an extra field 'notify_observer_p' to identify
the command will notify observer 'command_option_changed', and teach
GDB to check the change of command option, and notify observer.

gdb:

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

	* cli/cli-decode.c (add_cmd): Set field 'notify_observer_p' to 0.
	(add_setshow_auto_boolean_cmd): Move auto_boolean_enums out.
	Remove 'static'.
	* cli/cli-decode.h (struct cmd_list_element) <notify_observer_p>:
	New field.
	Declare 'auto_boolean_enums'.
	* cli/cli-setshow.c (do_setshow_command): Notify observer
	command_option_changed if the option of command is changed.

gdb/doc:

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

	* observer.texi: New observer command_option_changed.
---
 gdb/cli/cli-decode.c  |    4 +-
 gdb/cli/cli-decode.h  |    4 ++
 gdb/cli/cli-setshow.c |  142 ++++++++++++++++++++++++++++++++++++++++---------
 gdb/doc/observer.texi |    5 ++
 4 files changed, 129 insertions(+), 26 deletions(-)

diff --git a/gdb/cli/cli-decode.c b/gdb/cli/cli-decode.c
index c337b43..6739aef 100644
--- a/gdb/cli/cli-decode.c
+++ b/gdb/cli/cli-decode.c
@@ -203,6 +203,7 @@ add_cmd (char *name, enum command_class class, void (*fun) (char *, int),
   c->user_commands = NULL;
   c->cmd_pointer = NULL;
   c->alias_chain = NULL;
+  c->notify_observer_p = 0;
 
   return c;
 }
@@ -430,6 +431,8 @@ add_setshow_enum_cmd (char *name,
   c->enums = enumlist;
 }
 
+const char *auto_boolean_enums[] = { "on", "off", "auto", NULL };
+
 /* Add an auto-boolean command named NAME to both the set and show
    command list lists.  CLASS is as in add_cmd.  VAR is address of the
    variable which will contain the value.  DOC is the documentation
@@ -445,7 +448,6 @@ add_setshow_auto_boolean_cmd (char *name,
 			      struct cmd_list_element **set_list,
 			      struct cmd_list_element **show_list)
 {
-  static const char *auto_boolean_enums[] = { "on", "off", "auto", NULL };
   struct cmd_list_element *c;
 
   add_setshow_cmd_full (name, class, var_auto_boolean, var,
diff --git a/gdb/cli/cli-decode.h b/gdb/cli/cli-decode.h
index b5e0790..73001a2 100644
--- a/gdb/cli/cli-decode.h
+++ b/gdb/cli/cli-decode.h
@@ -210,6 +210,9 @@ struct cmd_list_element
 
     /* Link pointer for aliases on an alias list.  */
     struct cmd_list_element *alias_chain;
+
+    /* Notify 'command_option_changed' observer if it is true.  */
+    int notify_observer_p;
   };
 
 extern void help_cmd_list (struct cmd_list_element *, enum command_class,
@@ -232,5 +235,6 @@ extern void not_just_help_class_command (char *arg, int from_tty);
 
 extern void print_doc_line (struct ui_file *, char *);
 
+extern const char *auto_boolean_enums[];
 
 #endif /* !defined (CLI_DECODE_H) */
diff --git a/gdb/cli/cli-setshow.c b/gdb/cli/cli-setshow.c
index 7ffb89e..9369b29 100644
--- a/gdb/cli/cli-setshow.c
+++ b/gdb/cli/cli-setshow.c
@@ -28,6 +28,8 @@
 #include "cli/cli-cmds.h"
 #include "cli/cli-setshow.h"
 
+#include "observer.h"
+
 /* Prototypes for local functions.  */
 
 static int parse_binary_operation (char *);
@@ -170,50 +172,122 @@ do_setshow_command (char *arg, int from_tty, struct cmd_list_element *c)
 #endif
 	    *q++ = '\0';
 	    new = (char *) xrealloc (new, q - new);
-	    xfree (*(char **) c->var);
-	    *(char **) c->var = new;
+
+	    if (*(char **) c->var == NULL
+		|| strcmp (*(char **) c->var, new) != 0)
+	      {
+		xfree (*(char **) c->var);
+		*(char **) c->var = new;
+
+		if (c->notify_observer_p)
+		  observer_notify_command_option_changed (c->name, new);
+	      }
+	    else
+	      xfree (new);
 	  }
 	  break;
 	case var_string_noescape:
 	  if (arg == NULL)
 	    arg = "";
-	  xfree (*(char **) c->var);
-	  *(char **) c->var = xstrdup (arg);
+
+	  if (*(char **) c->var == NULL || strcmp (*(char **) c->var, arg) != 0)
+	    {
+	      xfree (*(char **) c->var);
+	      *(char **) c->var = xstrdup (arg);
+
+	      if (c->notify_observer_p)
+		observer_notify_command_option_changed (c->name, arg);
+	    }
 	  break;
 	case var_filename:
 	  if (arg == NULL)
 	    error_no_arg (_("filename to set it to."));
 	  /* FALLTHROUGH */
 	case var_optional_filename:
-	  xfree (*(char **) c->var);
+	  {
+	    char *val = NULL;
 
-	  if (arg != NULL)
-	    {
-	      /* Clear trailing whitespace of filename.  */
-	      char *ptr = arg + strlen (arg) - 1;
+	    if (arg != NULL)
+	      {
+		/* Clear trailing whitespace of filename.  */
+		char *ptr = arg + strlen (arg) - 1;
 
-	      while (ptr >= arg && (*ptr == ' ' || *ptr == '\t'))
-		ptr--;
-	      *(ptr + 1) = '\0';
+		while (ptr >= arg && (*ptr == ' ' || *ptr == '\t'))
+		  ptr--;
+		*(ptr + 1) = '\0';
 
-	      *(char **) c->var = tilde_expand (arg);
-	    }
-	  else
-	    *(char **) c->var = xstrdup ("");
+		val = tilde_expand (arg);
+	      }
+	    else
+	      val = xstrdup ("");
+
+	    if (*(char **) c->var == NULL
+		|| strcmp (*(char **) c->var, val) != 0)
+	      {
+		xfree (*(char **) c->var);
+		*(char **) c->var = val;
+
+		if (c->notify_observer_p)
+		  observer_notify_command_option_changed (c->name, val);
+	      }
+	    else
+	      xfree (val);
+	  }
 	  break;
 	case var_boolean:
-	  *(int *) c->var = parse_binary_operation (arg);
+	  {
+	    int val = parse_binary_operation (arg);
+
+	    if (val != *(int *) c->var)
+	      {
+		*(int *) c->var = val;
+
+		if (c->notify_observer_p)
+		  observer_notify_command_option_changed (c->name,
+							  val ? "on" : "off");
+	      }
+	  }
 	  break;
 	case var_auto_boolean:
-	  *(enum auto_boolean *) c->var = parse_auto_binary_operation (arg);
+	  {
+	    enum auto_boolean val = parse_auto_binary_operation (arg);
+
+	    if (*(enum auto_boolean *) c->var != val)
+	      {
+		*(enum auto_boolean *) c->var = val;
+
+		if (c->notify_observer_p)
+		  {
+		    char *s = (char *) auto_boolean_enums[val];
+
+		    observer_notify_command_option_changed (c->name, s);
+		  }
+	      }
+	  }
 	  break;
 	case var_uinteger:
 	case var_zuinteger:
 	  if (arg == NULL)
 	    error_no_arg (_("integer to set it to."));
-	  *(unsigned int *) c->var = parse_and_eval_long (arg);
-	  if (c->var_type == var_uinteger && *(unsigned int *) c->var == 0)
-	    *(unsigned int *) c->var = UINT_MAX;
+	  {
+	    unsigned int val = parse_and_eval_long (arg);
+
+	    if (c->var_type == var_uinteger && val == 0)
+	      val = UINT_MAX;
+
+	    if (*(unsigned int *) c->var != val)
+	      {
+		*(unsigned int *) c->var = val;
+
+		if (c->notify_observer_p)
+		  {
+		    char s[64];
+
+		    xsnprintf (s, sizeof s, "%d", val);
+		    observer_notify_command_option_changed (c->name, s);
+		  }
+	      }
+	  }
 	  break;
 	case var_integer:
 	case var_zinteger:
@@ -224,11 +298,23 @@ do_setshow_command (char *arg, int from_tty, struct cmd_list_element *c)
 	      error_no_arg (_("integer to set it to."));
 	    val = parse_and_eval_long (arg);
 	    if (val == 0 && c->var_type == var_integer)
-	      *(int *) c->var = INT_MAX;
+	      val = INT_MAX;
 	    else if (val >= INT_MAX)
 	      error (_("integer %u out of range"), val);
-	    else
-	      *(int *) c->var = val;
+
+
+	    if (*(int *) c->var != val)
+	      {
+		*(int *) c->var = val;
+
+		if (c->notify_observer_p)
+		  {
+		    char s[64];
+
+		    xsnprintf (s, sizeof s, "%d", val);
+		    observer_notify_command_option_changed (c->name, s);
+		  }
+	      }
 	    break;
 	  }
 	case var_enum:
@@ -293,7 +379,13 @@ do_setshow_command (char *arg, int from_tty, struct cmd_list_element *c)
 	    if (nmatches > 1)
 	      error (_("Ambiguous item \"%s\"."), arg);
 
-	    *(const char **) c->var = match;
+	    if (*(const char **) c->var != match)
+	      {
+		*(const char **) c->var = match;
+
+		if (c->notify_observer_p)
+		    observer_notify_command_option_changed (c->name, match);
+	      }
 	  }
 	  break;
 	default:
diff --git a/gdb/doc/observer.texi b/gdb/doc/observer.texi
index 14d4ac3..a45df36 100644
--- a/gdb/doc/observer.texi
+++ b/gdb/doc/observer.texi
@@ -234,6 +234,11 @@ the current top-level prompt.
 Variable gdb_datadir has been set.  The value may not necessarily change.
 @end deftypefun
 
+@deftypefun void command_option_changed (const char *@var{command}, const char *@var{option})
+The option of some @code{set} commands in console are changed.  This method is called after
+a command @code{set command option}.
+@end deftypefun
+
 @deftypefun void test_notification (int @var{somearg})
 This observer is used for internal testing.  Do not use.  
 See testsuite/gdb.gdb/observer.exp.
-- 
1.7.7.6


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

Thread overview: 28+ 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 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 ` Yao Qi [this message]
2012-07-24 20:39   ` [PATCH 1/6] new observer command_option_changed 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 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:12 ` [PATCH 5/6] new add_setshow_boolean_cmd_with_notify and circular-trace-buffer Yao Qi
2012-07-24 20:53   ` Tom Tromey
2012-07-27 15:23 [RCF 0/6 V2] MI notification of command option change Yao Qi
2012-07-27 15:23 ` [PATCH 1/6] new observer command_option_changed Yao Qi
2012-07-27 17:56   ` 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-2-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