From ef0026f03b3a4e892477fddf5e7da722b656db61 Mon Sep 17 00:00:00 2001 From: Pedro Alves Date: Wed, 20 Mar 2013 18:58:16 +0000 Subject: 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 PR gdb/15289 * cli/cli-setshow.c (do_set_command) : 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. : 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. : Throw error if the value is greater than INT_MAX, not greater or equal. (do_show_command) : Use %d for printing int, not %u. gdb/testsuite/ 2013-03-20 Pedro Alves 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". --- gdb/testsuite/gdb.base/remote.exp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'gdb/testsuite/gdb.base/remote.exp') diff --git a/gdb/testsuite/gdb.base/remote.exp b/gdb/testsuite/gdb.base/remote.exp index dea9bdc..dfaf646 100644 --- a/gdb/testsuite/gdb.base/remote.exp +++ b/gdb/testsuite/gdb.base/remote.exp @@ -155,4 +155,14 @@ gdb_test "show remote memory-read-packet-size" \ gdb_test "x/17ub random_data" \ ":\[ \t\]+60\[ \t\]+74\[ \t\]+216\[ \t\]+38\[ \t\]+149\[ \t\]+49\[ \t\]+207\[ \t\]+44.*:\[ \t\]+124\[ \t\]+38\[ \t\]+93\[ \t\]+125\[ \t\]+232\[ \t\]+67\[ \t\]+228\[ \t\]+56.*:\[ \t\]+161" +# Regression test for gdb/15289. Make sure -1 is accepted and handled +# as "unlimited". +gdb_test_no_output "set remote hardware-watchpoint-limit -1" +gdb_test_no_output "set remote hardware-breakpoint-limit -1" + +# This is just being thorough. Assume (at least) a 32-bit host int, +# and make sure 32-bit INT_MAX is accepted by a zinteger command. +gdb_test_no_output "set remote hardware-watchpoint-limit 2147483647" +gdb_test_no_output "set remote hardware-breakpoint-limit 2147483647" + gdb_exit -- cgit v1.1