This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Also handle "set input-radix 0" and "set output-radix 0"
- From: Pedro Alves <pedro at codesourcery dot com>
- To: gdb-patches at sourceware dot org
- Date: Mon, 29 Dec 2008 20:22:56 +0000
- Subject: Also handle "set input-radix 0" and "set output-radix 0"
Ok, one issue at a time then.
It was with dismay that I noticed today that "set input-radix 0" and
"set output-radix 0" actually do surprising things too. I missed
it yesterday somehow because PR7536 only talks about "set input-radix 1".
http://sourceware.org/ml/gdb-patches/2008-12/msg00431.html
(gdb) set input-radix 0
Input radix now set to decimal 4294967295, hex ffffffff, octal 37777777777.
In addition, we can have "unlimited" radices:
(gdb) show input-radix
Default input radix for entering numbers is unlimited.
(gdb) set output-radix 0
Unsupported output radix ``decimal 4294967295''; output radix unchanged.
(gdb) show output-radix
Default output radix for printing of values is unlimited.
But,
(gdb) set radix 0
Unsupported output radix ``decimal 0''; output radix unchanged.
This is because "set radix" is implemented with a regular set_cmd
and hence doesn't do any 0->UINT_MAX conversion.
This one was labelled as OMG in the table at:
http://sourceware.org/ml/gdb-patches/2008-12/msg00448.html
The issue here is that the input-radix and output-radix commands
are set as add_setshow_uinteger_cmd commands.
/* Unsigned Integer. *VAR is an unsigned int. The user can type 0
to mean "unlimited", which is stored in *VAR as UINT_MAX. */
var_uinteger,
By the time the setter function is reached, the 0->UINT_MAX conversion
had already been done. Note that is was broken and independent of
my yesterdays change to fix input-radix 1. I see it on 6.8 as well.
So, here we have an example of an unsigned setting, where we never
want to show "unlimited", or convert 0->(U)INT_MAX internally.
I think that for these cases, a new var_zuinteger is what makes sense.
Several other settings that fall in integer, uinteger or zinteger
types currently, could/should move to this type.
Anyone disagrees?
--
Pedro Alves
2008-12-29 Pedro Alves <pedro@codesourcery.com>
* cli/cli-decode.c (add_setshow_zuinteger_cmd): New.
* cli/cli-setshow.c (do_setshow_command): Handle it.
* command.h (enum var_types): Add var_zuinteger.
(add_setshow_zuinteger_cmd): Declare.
* valprint.c (_initialize_valprint): Change the set input-radix
and set output-radix commands to zuinteger type.
2008-12-29 Pedro Alves <pedro@codesourcery.com>
* gdb.base/radix.exp: Add tests to ensure that that set
input-radix 0 and set output-radix 0 are really rejected.
---
gdb/cli/cli-decode.c | 21 +++++++++++++++++++++
gdb/cli/cli-setshow.c | 6 ++++++
gdb/command.h | 14 ++++++++++++++
gdb/testsuite/gdb.base/radix.exp | 17 +++++++++++++++--
gdb/valprint.c | 20 ++++++++++----------
5 files changed, 66 insertions(+), 12 deletions(-)
Index: src/gdb/cli/cli-decode.c
===================================================================
--- src.orig/gdb/cli/cli-decode.c 2008-12-29 19:46:01.000000000 +0000
+++ src/gdb/cli/cli-decode.c 2008-12-29 20:20:53.000000000 +0000
@@ -639,6 +639,27 @@ add_setshow_zinteger_cmd (char *name, en
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
+ value. SET_DOC and SHOW_DOC are the documentation strings. */
+void
+add_setshow_zuinteger_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, var,
+ set_doc, show_doc, help_doc,
+ set_func, show_func,
+ set_list, show_list,
+ NULL, NULL);
+}
+
/* Remove the command named NAME from the command list. Return the
list commands which were aliased to the deleted command. If the
command had no aliases, return NULL. The various *HOOKs are set to
Index: src/gdb/cli/cli-setshow.c
===================================================================
--- src.orig/gdb/cli/cli-setshow.c 2008-12-29 19:43:42.000000000 +0000
+++ src/gdb/cli/cli-setshow.c 2008-12-29 19:49:02.000000000 +0000
@@ -232,6 +232,11 @@ do_setshow_command (char *arg, int from_
error_no_arg (_("integer to set it to."));
*(int *) c->var = parse_and_eval_long (arg);
break;
+ case var_zuinteger:
+ if (arg == NULL)
+ error_no_arg (_("integer to set it to."));
+ *(unsigned int *) c->var = parse_and_eval_long (arg);
+ break;
case var_enum:
{
int i;
@@ -351,6 +356,7 @@ do_setshow_command (char *arg, int from_
break;
}
/* else fall through */
+ case var_zuinteger:
case var_zinteger:
fprintf_filtered (stb->stream, "%u", *(unsigned int *) c->var);
break;
Index: src/gdb/command.h
===================================================================
--- src.orig/gdb/command.h 2008-12-29 19:43:37.000000000 +0000
+++ src/gdb/command.h 2008-12-29 20:20:41.000000000 +0000
@@ -87,6 +87,9 @@ typedef enum var_types
/* ZeroableInteger. *VAR is an int. Like Unsigned Integer except
that zero really means zero. */
var_zinteger,
+ /* ZeroableUnsignedInteger. *VAR is an unsigned int. Zero really
+ means zero. */
+ var_zuinteger,
/* Enumerated type. Can only have one of the specified values. *VAR is a
char pointer to the name of the element that we find. */
var_enum
@@ -332,6 +335,17 @@ extern void add_setshow_zinteger_cmd (ch
struct cmd_list_element **set_list,
struct cmd_list_element **show_list);
+extern void add_setshow_zuinteger_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 *);
Index: src/gdb/valprint.c
===================================================================
--- src.orig/gdb/valprint.c 2008-12-29 19:41:21.000000000 +0000
+++ src/gdb/valprint.c 2008-12-29 19:43:25.000000000 +0000
@@ -1576,21 +1576,21 @@ Show printing of addresses."), NULL,
show_addressprint,
&setprintlist, &showprintlist);
- add_setshow_uinteger_cmd ("input-radix", class_support, &input_radix_1,
- _("\
+ add_setshow_zuinteger_cmd ("input-radix", class_support, &input_radix_1,
+ _("\
Set default input radix for entering numbers."), _("\
Show default input radix for entering numbers."), NULL,
- set_input_radix,
- show_input_radix,
- &setlist, &showlist);
+ set_input_radix,
+ show_input_radix,
+ &setlist, &showlist);
- add_setshow_uinteger_cmd ("output-radix", class_support, &output_radix_1,
- _("\
+ add_setshow_zuinteger_cmd ("output-radix", class_support, &output_radix_1,
+ _("\
Set default output radix for printing of values."), _("\
Show default output radix for printing of values."), NULL,
- set_output_radix,
- show_output_radix,
- &setlist, &showlist);
+ set_output_radix,
+ show_output_radix,
+ &setlist, &showlist);
/* The "set radix" and "show radix" commands are special in that
they are like normal set and show commands but allow two normally
Index: src/gdb/testsuite/gdb.base/radix.exp
===================================================================
--- src.orig/gdb/testsuite/gdb.base/radix.exp 2008-12-29 19:53:34.000000000 +0000
+++ src/gdb/testsuite/gdb.base/radix.exp 2008-12-29 19:55:04.000000000 +0000
@@ -162,19 +162,32 @@ gdb_test "set radix" \
"Input and output radices now set to decimal 10, hex a, octal 12\." \
"Reset radices"
+gdb_test "set input-radix 0" \
+ "Nonsense input radix ``decimal 0''; input radix unchanged\\." \
+ "Reject input-radix 0"
+gdb_test "show input-radix" \
+ "Default input radix for entering numbers is 10\\." \
+ "Input radix unchanged after rejecting 0"
+
gdb_test "set input-radix 1" \
"Nonsense input radix ``decimal 1''; input radix unchanged\\." \
"Reject input-radix 1"
gdb_test "show input-radix" \
"Default input radix for entering numbers is 10\\." \
- "Input radix unchanged after rejection"
+ "Input radix unchanged after rejecting 1"
+gdb_test "set output-radix 0" \
+ "Unsupported output radix ``decimal 0''; output radix unchanged\\." \
+ "Reject output-radix 0"
+gdb_test "show output-radix" \
+ "Default output radix for printing of values is 10\\." \
+ "Output radix unchanged after rejecting 0"
gdb_test "set output-radix 1" \
"Unsupported output radix ``decimal 1''; output radix unchanged\\." \
"Reject output-radix 1"
gdb_test "show output-radix" \
"Default output radix for printing of values is 10\\." \
- "Output radix unchanged after rejection"
+ "Output radix unchanged after rejecting 1"
gdb_test "set radix 7" \
"Unsupported output radix ``decimal 7''; output radix unchanged\\." \