Make breakpoint/location number parsing error output consistent

... and also make GDB catch a few more cases of invalid input.

This fixes the inconsistency in GDB's output (e.g., "bad" vs "Bad")
exposed by the new tests added in the previous commit.

Also, makes the "0-0" and "inverted range" cases be loud errors.

Also makes GDB reject negative breakpoint number in ranges.  We
already rejected negative number literals, but you could still subvert
that via convenience variables, like:

  (gdb) set $bp -1
  (gdb) disable $bp.1-2

The change to get_number_trailer fixes a bug exposed by the new tests.
The function did not handle parsing "-$num".  [This wasn't visible in
the gdb.multi/tids.exp (which has similar tests) because the TID range
parsing is implemented differently.]

gdb/ChangeLog:
2017-11-07  Pedro Alves  <palves@redhat.com>

	* breakpoint.c (extract_bp_kind): New enum.
	(extract_bp_num, extract_bp_or_bp_range): New functions, partially
	factored out from ...
	(extract_bp_number_and_location): ... here.
	* cli/cli-utils.c (get_number_trailer): Handle '-$variable'.

gdb/testsuite/ChangeLog:
2017-11-07  Pedro Alves  <palves@redhat.com>

	* gdb.base/ena-dis-br.exp (test_ena_dis_br): Adjust test.
	* gdb.cp/ena-dis-br-range.exp: Adjust tests.
	(disable_invalid, disable_inverted, disable_negative): New
	procedures.
	("bad numbers"): New set of tests.
This commit is contained in:
Pedro Alves
2017-11-07 11:00:32 +00:00
parent cee62dbd87
commit 95e95a6de2
6 changed files with 208 additions and 84 deletions

View File

@@ -30,6 +30,13 @@ get_number_trailer (const char **pp, int trailer)
{
int retval = 0; /* default */
const char *p = *pp;
bool negative = false;
if (*p == '-')
{
++p;
negative = true;
}
if (*p == '$')
{
@@ -70,11 +77,10 @@ get_number_trailer (const char **pp, int trailer)
}
else
{
if (*p == '-')
++p;
const char *p1 = p;
while (*p >= '0' && *p <= '9')
++p;
if (p == *pp)
if (p == p1)
/* There is no number here. (e.g. "cond a == b"). */
{
/* Skip non-numeric token. */
@@ -84,7 +90,7 @@ get_number_trailer (const char **pp, int trailer)
retval = 0;
}
else
retval = atoi (*pp);
retval = atoi (p1);
}
if (!(isspace (*p) || *p == '\0' || *p == trailer))
{
@@ -95,7 +101,7 @@ get_number_trailer (const char **pp, int trailer)
}
p = skip_spaces (p);
*pp = p;
return retval;
return negative ? -retval : retval;
}
/* See documentation in cli-utils.h. */