This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH 1/3] var_zuinteger_unlimited and 'set listsize'.


Hi,
This patch is to add new var_types 'var_zuinteger_unlimited' and
fix 'set listsize'.

gdb:

2012-08-01  Yao Qi  <yao@codesourcery.com>
	    Mark Kettenis  <kettenis@gnu.org>

	* cli/cli-decode.c (add_setshow_zuinteger_unlimited_cmd): New.
	* cli/cli-setshow.c (do_setshow_command): Handle case
	'var_zuinteger_unlimited'.
	(do_setshow_command): Check the range for var_uinteger and
	var_zuinteger.
	* command.h (typedef enum var_types): New enum
	'var_zuinteger_unlimited'.
	Declare add_setshow_zuinteger_unlimited_cmd.
	* source.c (_initialize_source): Call add_setshow_zuinteger_unlimited_cmd.

gdb/doc:

2012-08-01  Yao Qi  <yao@codesourcery.com>

	* gdb.texinfo (List): Describe the meaning of 0 and -1 in
	'set listsize'.

gdb/testsuite:

2012-08-01  Yao Qi  <yao@codesourcery.com>

	* gdb.base/list.exp (set_listsize): Don't set arg to "unlimited"
	when it is less than 0.
---
 gdb/cli/cli-decode.c            |   19 +++++++++++++
 gdb/cli/cli-setshow.c           |   56 ++++++++++++++++++++++++++++++++------
 gdb/command.h                   |   16 +++++++++++
 gdb/doc/gdb.texinfo             |    2 +
 gdb/source.c                    |    8 +++---
 gdb/testsuite/gdb.base/list.exp |    2 +-
 6 files changed, 89 insertions(+), 14 deletions(-)

diff --git a/gdb/cli/cli-decode.c b/gdb/cli/cli-decode.c
index c337b43..bd679d8 100644
--- a/gdb/cli/cli-decode.c
+++ b/gdb/cli/cli-decode.c
@@ -627,6 +627,25 @@ add_setshow_zinteger_cmd (char *name, enum command_class class,
 			NULL, NULL);
 }
 
+void
+add_setshow_zuinteger_unlimited_cmd (char *name,
+				     enum command_class class,
+				     unsigned 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)
+{
+  add_setshow_cmd_full (name, class, var_zuinteger_unlimited, var,
+			set_doc, show_doc, help_doc,
+			set_func, show_func,
+			set_list, show_list,
+			NULL, 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
diff --git a/gdb/cli/cli-setshow.c b/gdb/cli/cli-setshow.c
index 7ffb89e..77c836b 100644
--- a/gdb/cli/cli-setshow.c
+++ b/gdb/cli/cli-setshow.c
@@ -209,24 +209,34 @@ do_setshow_command (char *arg, int from_tty, struct cmd_list_element *c)
 	  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;
+	  {
+	    LONGEST val;
+
+	    if (arg == NULL)
+	      error_no_arg (_("integer to set it to."));
+	    val = parse_and_eval_long (arg);
+
+	    if (val < 0 || val > UINT_MAX)
+	      error (_("integer %s out of range"), plongest (val));
+
+	    if (c->var_type == var_uinteger && val == 0)
+	      val = UINT_MAX;
+
+	    *(unsigned int *) c->var = val;
+	  }
 	  break;
 	case var_integer:
 	case var_zinteger:
 	  {
-	    unsigned int val;
+	    LONGEST val;
 
 	    if (arg == NULL)
 	      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;
-	    else if (val >= INT_MAX)
-	      error (_("integer %u out of range"), val);
+	    else if (val < INT_MIN || val > INT_MAX)
+	      error (_("integer %s out of range"), plongest (val));
 	    else
 	      *(int *) c->var = val;
 	    break;
@@ -296,6 +306,27 @@ do_setshow_command (char *arg, int from_tty, struct cmd_list_element *c)
 	    *(const char **) c->var = match;
 	  }
 	  break;
+	case var_zuinteger_unlimited:
+	  {
+	    LONGEST val;
+
+	    if (arg == NULL)
+	      error_no_arg (_("integer to set it to."));
+	    val = parse_and_eval_long (arg);
+
+	    /* Don't allow user to input UINT_MAX, which is reserved for
+	       'unlimited'.  */
+	    if (val >= UINT_MAX)
+	      error (_("integer %s out of range"), plongest (val));
+	    else if (val < -1)
+	      error (_("only -1 is allowed to set as unlimited"));
+
+	    if (val == -1)
+	      val = UINT_MAX;
+
+	    *(unsigned int *) c->var = val;
+	  }
+	  break;
 	default:
 	  error (_("gdb internal error: bad var_type in do_setshow_command"));
 	}
@@ -363,7 +394,14 @@ do_setshow_command (char *arg, int from_tty, struct cmd_list_element *c)
 	  else
 	    fprintf_filtered (stb, "%d", *(int *) c->var);
 	  break;
-
+	case var_zuinteger_unlimited:
+	  {
+	    if (*(unsigned int *) c->var == UINT_MAX)
+	      fputs_filtered ("unlimited", stb);
+	    else
+	      fprintf_filtered (stb, "%u", *(unsigned int *) c->var);
+	  }
+	  break;
 	default:
 	  error (_("gdb internal error: bad var_type in do_setshow_command"));
 	}
diff --git a/gdb/command.h b/gdb/command.h
index 88895bb..fc09e69 100644
--- a/gdb/command.h
+++ b/gdb/command.h
@@ -99,6 +99,10 @@ typedef enum var_types
     /* ZeroableUnsignedInteger.  *VAR is an unsigned int.  Zero really
        means zero.  */
     var_zuinteger,
+    /* ZeroableUnsignedInteger with unlimited value.  *VAR is an unsigned
+       int, but its range is [0, UINT_MAX - 1].  UINT_MAX stands for
+       unlimited.  */
+    var_zuinteger_unlimited,
     /* Enumerated type.  Can only have one of the specified values.
        *VAR is a char pointer to the name of the element that we
        find.  */
@@ -354,6 +358,18 @@ extern void add_setshow_zuinteger_cmd (char *name,
 				       struct cmd_list_element **set_list,
 				       struct cmd_list_element **show_list);
 
+extern void
+  add_setshow_zuinteger_unlimited_cmd (char *name,
+				       enum command_class class,
+				       unsigned 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);
+
 /* Do a "show" command for each thing on a command list.  */
 
 extern void cmd_show_list (struct cmd_list_element *, int, char *);
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index a4503bf..f481c95 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -6705,6 +6705,8 @@ the @code{list} command.  You can change this using @code{set listsize}:
 @item set listsize @var{count}
 Make the @code{list} command display @var{count} source lines (unless
 the @code{list} argument explicitly specifies some other number).
+Setting the @var{count} to -1 means there's no limit and 0 suppress
+printing.
 
 @kindex show listsize
 @item show listsize
diff --git a/gdb/source.c b/gdb/source.c
index 0ff0782..31e104f 100644
--- a/gdb/source.c
+++ b/gdb/source.c
@@ -1965,12 +1965,12 @@ The matching line number is also stored as the value of \"$_\"."));
       add_com_alias ("?", "reverse-search", class_files, 0);
     }
 
-  add_setshow_integer_cmd ("listsize", class_support, &lines_to_list, _("\
+  add_setshow_zuinteger_unlimited_cmd ("listsize", class_support,
+				       &lines_to_list, _("\
 Set number of source lines gdb will list by default."), _("\
 Show number of source lines gdb will list by default."), NULL,
-			    NULL,
-			    show_lines_to_list,
-			    &setlist, &showlist);
+				       NULL, show_lines_to_list,
+				       &setlist, &showlist);
 
   add_cmd ("substitute-path", class_files, set_substitute_path_command,
            _("\
diff --git a/gdb/testsuite/gdb.base/list.exp b/gdb/testsuite/gdb.base/list.exp
index 16d25d2..f01b028 100644
--- a/gdb/testsuite/gdb.base/list.exp
+++ b/gdb/testsuite/gdb.base/list.exp
@@ -62,7 +62,7 @@ proc set_listsize { arg } {
     if [gdb_test "set listsize $arg" ".*" "setting listsize to $arg #$set_listsize_count"] {
 	return 0;
     }
-    if { $arg <= 0 } {
+    if { $arg < 0 } {
 	set arg "unlimited";
     }
 
-- 
1.7.7.6


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]