diff options
author | Pedro Alves <palves@redhat.com> | 2013-03-20 18:58:16 +0000 |
---|---|---|
committer | Pedro Alves <palves@redhat.com> | 2013-03-20 18:58:16 +0000 |
commit | ef0026f03b3a4e892477fddf5e7da722b656db61 (patch) | |
tree | ded68ed34577e9933caff052746e185fa4f2ff81 /gdb/cli/cli-setshow.c | |
parent | 24d6c2a0bb797940d1f6f16ce8be8c80b1eab4db (diff) | |
download | gdb-ef0026f03b3a4e892477fddf5e7da722b656db61.zip gdb-ef0026f03b3a4e892477fddf5e7da722b656db61.tar.gz gdb-ef0026f03b3a4e892477fddf5e7da722b656db61.tar.bz2 |
Fix PR gdb/15289 - "set remote hardware-watchpoint-limit" broken (zinteger commands)
This is a regression from 7.5, introduced/exposed by:
http://sourceware.org/ml/gdb-patches/2012-07/msg00259.html
There are a series of issues with this code.
It does:
unsigned int val = parse_and_eval_long (arg);
^^^^^^^^^^^^
(unsigned, usually 32-bit) while parse_and_eval_long returns a LONGEST
(usually 64-bit), so we lose precision without noticing:
(gdb) set remote hardware-watchpoint-limit 0x100000000
(gdb) show remote hardware-watchpoint-limit 0x100000000
The maximum number of target hardware watchpoints is 0.
While at it, print the invalid number with plongest, so the user sees
what GDB thought the number was:
(gdb) set remote hardware-watchpoint-limit 0x100000000
integer 4294967296 out of range
So with "set remote hardware-watchpoint-limit -1", val ends converted
to 0xffffffff, which then fails the
else if (val >= INT_MAX)
error (_("integer %u out of range"), val);
test.
Looking at that INT_MAX check, we forbid INT_MAX itself, but we
shouldn't, as that does fit in 'int' -- we want to forbid values
_greater_ than INT_MAX (and less than INT_MIN, while at it):
(gdb) set remote hardware-watchpoint-limit 2147483647
integer 2147483647 out of range
The same problem is in the new var_zuinteger_unlimited code, which
also uses "int" for variable.
Also, when printing a 'signed int', we should use %d, not %u.
This adds a couple regression tests. Not completely thorough in checking
all kinds of invalid input; I'm saving more exaustive testing around
zXXinteger commands for something like new test-assisting commands
like "maint test cmd-zinteger -1", where testing would focus on the
command types, and thus be independent of particular user commands of
particular GDB features.
Tested on x86_64 Fedora 17.
gdb/
2013-03-20 Pedro Alves <palves@redhat.com>
PR gdb/15289
* cli/cli-setshow.c (do_set_command)
<var_uinteger, var_zuinteger>: Use LONGEST for variable holding
the result of parsing the command argument. Throw error if the
value is greater than UINT_MAX. Print the invalid value with
plongest.
<var_integer, var_zinteger>: Use LONGEST for variable holding the
result of parsing the command argument. Throw error if the value
is greater than INT_MAX, not greater or equal. Also throw error
if the value is less than INT_MIN. Print the invalid value with
plongest.
<var_zuinteger_unlimited>: Throw error if the value is greater
than INT_MAX, not greater or equal.
(do_show_command) <var_integer, var_zinteger,
var_zuinteger_unlimited>: Use %d for printing int, not %u.
gdb/testsuite/
2013-03-20 Pedro Alves <palves@redhat.com>
PR gdb/15289
* gdb.base/remote.exp: Test
"set remote hardware-watchpoint-limit -1",
"set remote hardware-breakpoint-limit -1",
"set remote hardware-watchpoint-limit 2147483647" and
"set remote hardware-breakpoint-limit 2147483647".
Diffstat (limited to 'gdb/cli/cli-setshow.c')
-rw-r--r-- | gdb/cli/cli-setshow.c | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/gdb/cli/cli-setshow.c b/gdb/cli/cli-setshow.c index 0a859c2..3a0e978 100644 --- a/gdb/cli/cli-setshow.c +++ b/gdb/cli/cli-setshow.c @@ -272,13 +272,17 @@ do_set_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 val = parse_and_eval_long (arg); + LONGEST val; + + if (arg == NULL) + error_no_arg (_("integer to set it to.")); + val = parse_and_eval_long (arg); if (c->var_type == var_uinteger && val == 0) val = UINT_MAX; + else if (val > UINT_MAX) + error (_("integer %s out of range"), plongest (val)); if (*(unsigned int *) c->var != val) { @@ -291,15 +295,16 @@ do_set_command (char *arg, int from_tty, struct cmd_list_element *c) 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) val = INT_MAX; - else if (val >= INT_MAX) - error (_("integer %u out of range"), val); + else if (val > INT_MAX || val < INT_MIN) + error (_("integer %s out of range"), plongest (val)); if (*(int *) c->var != val) { @@ -387,7 +392,7 @@ do_set_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 >= INT_MAX) + if (val > INT_MAX) error (_("integer %s out of range"), plongest (val)); else if (val < -1) error (_("only -1 is allowed to set as unlimited")); @@ -588,7 +593,7 @@ do_show_command (char *arg, int from_tty, struct cmd_list_element *c) if (*(int *) c->var == -1) fputs_filtered ("unlimited", stb); else - fprintf_filtered (stb, "%u", *(int *) c->var); + fprintf_filtered (stb, "%d", *(int *) c->var); } break; default: |