forked from Imagelibrary/binutils-gdb
gdb: make get_discrete_bounds return bool
get_discrete_bounds currently has three possible return values (see its current doc for details). It appears that for all callers, it would be sufficient to have a boolean "worked" / "didn't work" return value. Change the return type of get_discrete_bounds to bool and adjust all callers. Doing so simplifies the following patch. gdb/ChangeLog: * gdbtypes.h (get_discrete_bounds): Return bool, adjust all callers. * gdbtypes.c (get_discrete_bounds): Return bool. Change-Id: Ie51feee23c75f0cd7939742604282d745db59172
This commit is contained in:
committed by
Simon Marchi
parent
f5fca0ec15
commit
f47d1c255d
@@ -1,3 +1,9 @@
|
|||||||
|
2020-12-09 Simon Marchi <simon.marchi@efficios.com>
|
||||||
|
|
||||||
|
* gdbtypes.h (get_discrete_bounds): Return bool, adjust all
|
||||||
|
callers.
|
||||||
|
* gdbtypes.c (get_discrete_bounds): Return bool.
|
||||||
|
|
||||||
2020-12-09 Simon Marchi <simon.marchi@efficios.com>
|
2020-12-09 Simon Marchi <simon.marchi@efficios.com>
|
||||||
|
|
||||||
* ada-lang.c (ada_value_slice_from_ptr): Adjust.
|
* ada-lang.c (ada_value_slice_from_ptr): Adjust.
|
||||||
|
|||||||
@@ -2097,7 +2097,7 @@ constrained_packed_array_type (struct type *type, long *elt_bits)
|
|||||||
|
|
||||||
if ((check_typedef (index_type)->code () == TYPE_CODE_RANGE
|
if ((check_typedef (index_type)->code () == TYPE_CODE_RANGE
|
||||||
&& is_dynamic_type (check_typedef (index_type)))
|
&& is_dynamic_type (check_typedef (index_type)))
|
||||||
|| get_discrete_bounds (index_type, &low_bound, &high_bound) < 0)
|
|| !get_discrete_bounds (index_type, &low_bound, &high_bound))
|
||||||
low_bound = high_bound = 0;
|
low_bound = high_bound = 0;
|
||||||
if (high_bound < low_bound)
|
if (high_bound < low_bound)
|
||||||
*elt_bits = TYPE_LENGTH (new_type) = 0;
|
*elt_bits = TYPE_LENGTH (new_type) = 0;
|
||||||
@@ -2243,7 +2243,7 @@ value_subscript_packed (struct value *arr, int arity, struct value **ind)
|
|||||||
LONGEST lowerbound, upperbound;
|
LONGEST lowerbound, upperbound;
|
||||||
LONGEST idx;
|
LONGEST idx;
|
||||||
|
|
||||||
if (get_discrete_bounds (range_type, &lowerbound, &upperbound) < 0)
|
if (!get_discrete_bounds (range_type, &lowerbound, &upperbound))
|
||||||
{
|
{
|
||||||
lim_warning (_("don't know bounds of array"));
|
lim_warning (_("don't know bounds of array"));
|
||||||
lowerbound = upperbound = 0;
|
lowerbound = upperbound = 0;
|
||||||
|
|||||||
@@ -136,7 +136,7 @@ val_print_packed_array_elements (struct type *type, const gdb_byte *valaddr,
|
|||||||
{
|
{
|
||||||
LONGEST high;
|
LONGEST high;
|
||||||
|
|
||||||
if (get_discrete_bounds (index_type, &low, &high) < 0)
|
if (!get_discrete_bounds (index_type, &low, &high))
|
||||||
len = 1;
|
len = 1;
|
||||||
else if (low > high)
|
else if (low > high)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -698,8 +698,8 @@ evaluate_subexp_c (struct type *expect_type, struct expression *exp,
|
|||||||
LONGEST low_bound, high_bound;
|
LONGEST low_bound, high_bound;
|
||||||
int element_size = TYPE_LENGTH (type);
|
int element_size = TYPE_LENGTH (type);
|
||||||
|
|
||||||
if (get_discrete_bounds (expect_type->index_type (),
|
if (!get_discrete_bounds (expect_type->index_type (),
|
||||||
&low_bound, &high_bound) < 0)
|
&low_bound, &high_bound))
|
||||||
{
|
{
|
||||||
low_bound = 0;
|
low_bound = 0;
|
||||||
high_bound = (TYPE_LENGTH (expect_type) / element_size) - 1;
|
high_bound = (TYPE_LENGTH (expect_type) / element_size) - 1;
|
||||||
|
|||||||
@@ -1464,7 +1464,7 @@ evaluate_subexp_standard (struct type *expect_type,
|
|||||||
int element_size = TYPE_LENGTH (check_typedef (element_type));
|
int element_size = TYPE_LENGTH (check_typedef (element_type));
|
||||||
LONGEST low_bound, high_bound, index;
|
LONGEST low_bound, high_bound, index;
|
||||||
|
|
||||||
if (get_discrete_bounds (range_type, &low_bound, &high_bound) < 0)
|
if (!get_discrete_bounds (range_type, &low_bound, &high_bound))
|
||||||
{
|
{
|
||||||
low_bound = 0;
|
low_bound = 0;
|
||||||
high_bound = (TYPE_LENGTH (type) / element_size) - 1;
|
high_bound = (TYPE_LENGTH (type) / element_size) - 1;
|
||||||
@@ -1517,7 +1517,7 @@ evaluate_subexp_standard (struct type *expect_type,
|
|||||||
|| check_type->code () == TYPE_CODE_TYPEDEF)
|
|| check_type->code () == TYPE_CODE_TYPEDEF)
|
||||||
check_type = TYPE_TARGET_TYPE (check_type);
|
check_type = TYPE_TARGET_TYPE (check_type);
|
||||||
|
|
||||||
if (get_discrete_bounds (element_type, &low_bound, &high_bound) < 0)
|
if (!get_discrete_bounds (element_type, &low_bound, &high_bound))
|
||||||
error (_("(power)set type with unknown size"));
|
error (_("(power)set type with unknown size"));
|
||||||
memset (valaddr, '\0', TYPE_LENGTH (type));
|
memset (valaddr, '\0', TYPE_LENGTH (type));
|
||||||
for (tem = 0; tem < nargs; tem++)
|
for (tem = 0; tem < nargs; tem++)
|
||||||
|
|||||||
@@ -1024,15 +1024,9 @@ has_static_range (const struct range_bounds *bounds)
|
|||||||
&& bounds->stride.kind () == PROP_CONST);
|
&& bounds->stride.kind () == PROP_CONST);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* See gdbtypes.h. */
|
||||||
|
|
||||||
/* Set *LOWP and *HIGHP to the lower and upper bounds of discrete type
|
bool
|
||||||
TYPE.
|
|
||||||
|
|
||||||
Return 1 if type is a range type with two defined, constant bounds.
|
|
||||||
Else, return 0 if it is discrete (and bounds will fit in LONGEST).
|
|
||||||
Else, return -1. */
|
|
||||||
|
|
||||||
int
|
|
||||||
get_discrete_bounds (struct type *type, LONGEST *lowp, LONGEST *highp)
|
get_discrete_bounds (struct type *type, LONGEST *lowp, LONGEST *highp)
|
||||||
{
|
{
|
||||||
type = check_typedef (type);
|
type = check_typedef (type);
|
||||||
@@ -1043,7 +1037,7 @@ get_discrete_bounds (struct type *type, LONGEST *lowp, LONGEST *highp)
|
|||||||
constant bounds. */
|
constant bounds. */
|
||||||
if (type->bounds ()->low.kind () != PROP_CONST
|
if (type->bounds ()->low.kind () != PROP_CONST
|
||||||
|| type->bounds ()->high.kind () != PROP_CONST)
|
|| type->bounds ()->high.kind () != PROP_CONST)
|
||||||
return -1;
|
return false;
|
||||||
|
|
||||||
*lowp = type->bounds ()->low.const_val ();
|
*lowp = type->bounds ()->low.const_val ();
|
||||||
*highp = type->bounds ()->high.const_val ();
|
*highp = type->bounds ()->high.const_val ();
|
||||||
@@ -1053,20 +1047,17 @@ get_discrete_bounds (struct type *type, LONGEST *lowp, LONGEST *highp)
|
|||||||
gdb::optional<LONGEST> low_pos
|
gdb::optional<LONGEST> low_pos
|
||||||
= discrete_position (TYPE_TARGET_TYPE (type), *lowp);
|
= discrete_position (TYPE_TARGET_TYPE (type), *lowp);
|
||||||
|
|
||||||
if (!low_pos.has_value ())
|
if (low_pos.has_value ())
|
||||||
return 0;
|
*lowp = *low_pos;
|
||||||
|
|
||||||
*lowp = *low_pos;
|
|
||||||
|
|
||||||
gdb::optional<LONGEST> high_pos
|
gdb::optional<LONGEST> high_pos
|
||||||
= discrete_position (TYPE_TARGET_TYPE (type), *highp);
|
= discrete_position (TYPE_TARGET_TYPE (type), *highp);
|
||||||
|
|
||||||
if (!high_pos.has_value ())
|
if (high_pos.has_value ())
|
||||||
return 0;
|
*highp = *high_pos;
|
||||||
|
|
||||||
*highp = *high_pos;
|
|
||||||
}
|
}
|
||||||
return 1;
|
return true;
|
||||||
|
|
||||||
case TYPE_CODE_ENUM:
|
case TYPE_CODE_ENUM:
|
||||||
if (type->num_fields () > 0)
|
if (type->num_fields () > 0)
|
||||||
{
|
{
|
||||||
@@ -1094,19 +1085,22 @@ get_discrete_bounds (struct type *type, LONGEST *lowp, LONGEST *highp)
|
|||||||
*lowp = 0;
|
*lowp = 0;
|
||||||
*highp = -1;
|
*highp = -1;
|
||||||
}
|
}
|
||||||
return 0;
|
return true;
|
||||||
|
|
||||||
case TYPE_CODE_BOOL:
|
case TYPE_CODE_BOOL:
|
||||||
*lowp = 0;
|
*lowp = 0;
|
||||||
*highp = 1;
|
*highp = 1;
|
||||||
return 0;
|
return true;
|
||||||
|
|
||||||
case TYPE_CODE_INT:
|
case TYPE_CODE_INT:
|
||||||
if (TYPE_LENGTH (type) > sizeof (LONGEST)) /* Too big */
|
if (TYPE_LENGTH (type) > sizeof (LONGEST)) /* Too big */
|
||||||
return -1;
|
return false;
|
||||||
|
|
||||||
if (!TYPE_UNSIGNED (type))
|
if (!TYPE_UNSIGNED (type))
|
||||||
{
|
{
|
||||||
*lowp = -(1 << (TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1));
|
*lowp = -(1 << (TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1));
|
||||||
*highp = -*lowp - 1;
|
*highp = -*lowp - 1;
|
||||||
return 0;
|
return true;
|
||||||
}
|
}
|
||||||
/* fall through */
|
/* fall through */
|
||||||
case TYPE_CODE_CHAR:
|
case TYPE_CODE_CHAR:
|
||||||
@@ -1116,9 +1110,10 @@ get_discrete_bounds (struct type *type, LONGEST *lowp, LONGEST *highp)
|
|||||||
if TYPE_LENGTH (type) == sizeof (LONGEST). */
|
if TYPE_LENGTH (type) == sizeof (LONGEST). */
|
||||||
*highp = 1 << (TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1);
|
*highp = 1 << (TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1);
|
||||||
*highp = (*highp - 1) | *highp;
|
*highp = (*highp - 1) | *highp;
|
||||||
return 0;
|
return true;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return -1;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1135,13 +1130,11 @@ get_array_bounds (struct type *type, LONGEST *low_bound, LONGEST *high_bound)
|
|||||||
struct type *index = type->index_type ();
|
struct type *index = type->index_type ();
|
||||||
LONGEST low = 0;
|
LONGEST low = 0;
|
||||||
LONGEST high = 0;
|
LONGEST high = 0;
|
||||||
int res;
|
|
||||||
|
|
||||||
if (index == NULL)
|
if (index == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
res = get_discrete_bounds (index, &low, &high);
|
if (!get_discrete_bounds (index, &low, &high))
|
||||||
if (res == -1)
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (low_bound)
|
if (low_bound)
|
||||||
@@ -1217,8 +1210,9 @@ update_static_array_size (struct type *type)
|
|||||||
if (stride == 0)
|
if (stride == 0)
|
||||||
stride = range_type->bit_stride ();
|
stride = range_type->bit_stride ();
|
||||||
|
|
||||||
if (get_discrete_bounds (range_type, &low_bound, &high_bound) < 0)
|
if (!get_discrete_bounds (range_type, &low_bound, &high_bound))
|
||||||
low_bound = high_bound = 0;
|
low_bound = high_bound = 0;
|
||||||
|
|
||||||
element_type = check_typedef (TYPE_TARGET_TYPE (type));
|
element_type = check_typedef (TYPE_TARGET_TYPE (type));
|
||||||
/* Be careful when setting the array length. Ada arrays can be
|
/* Be careful when setting the array length. Ada arrays can be
|
||||||
empty arrays with the high_bound being smaller than the low_bound.
|
empty arrays with the high_bound being smaller than the low_bound.
|
||||||
@@ -1400,8 +1394,9 @@ create_set_type (struct type *result_type, struct type *domain_type)
|
|||||||
{
|
{
|
||||||
LONGEST low_bound, high_bound, bit_length;
|
LONGEST low_bound, high_bound, bit_length;
|
||||||
|
|
||||||
if (get_discrete_bounds (domain_type, &low_bound, &high_bound) < 0)
|
if (!get_discrete_bounds (domain_type, &low_bound, &high_bound))
|
||||||
low_bound = high_bound = 0;
|
low_bound = high_bound = 0;
|
||||||
|
|
||||||
bit_length = high_bound - low_bound + 1;
|
bit_length = high_bound - low_bound + 1;
|
||||||
TYPE_LENGTH (result_type)
|
TYPE_LENGTH (result_type)
|
||||||
= (bit_length + TARGET_CHAR_BIT - 1) / TARGET_CHAR_BIT;
|
= (bit_length + TARGET_CHAR_BIT - 1) / TARGET_CHAR_BIT;
|
||||||
|
|||||||
@@ -2262,7 +2262,13 @@ extern struct type *lookup_template_type (const char *, struct type *,
|
|||||||
|
|
||||||
extern int get_vptr_fieldno (struct type *, struct type **);
|
extern int get_vptr_fieldno (struct type *, struct type **);
|
||||||
|
|
||||||
extern int get_discrete_bounds (struct type *, LONGEST *, LONGEST *);
|
/* Set *LOWP and *HIGHP to the lower and upper bounds of discrete type
|
||||||
|
TYPE.
|
||||||
|
|
||||||
|
Return true if the two bounds are available, false otherwise. */
|
||||||
|
|
||||||
|
extern bool get_discrete_bounds (struct type *type, LONGEST *lowp,
|
||||||
|
LONGEST *highp);
|
||||||
|
|
||||||
extern int get_array_bounds (struct type *type, LONGEST *low_bound,
|
extern int get_array_bounds (struct type *type, LONGEST *low_bound,
|
||||||
LONGEST *high_bound);
|
LONGEST *high_bound);
|
||||||
|
|||||||
@@ -372,7 +372,7 @@ m2_is_long_set (struct type *type)
|
|||||||
This should be integrated into gdbtypes.c
|
This should be integrated into gdbtypes.c
|
||||||
inside get_discrete_bounds. */
|
inside get_discrete_bounds. */
|
||||||
|
|
||||||
static int
|
static bool
|
||||||
m2_get_discrete_bounds (struct type *type, LONGEST *lowp, LONGEST *highp)
|
m2_get_discrete_bounds (struct type *type, LONGEST *lowp, LONGEST *highp)
|
||||||
{
|
{
|
||||||
type = check_typedef (type);
|
type = check_typedef (type);
|
||||||
@@ -419,7 +419,7 @@ m2_is_long_set_of_type (struct type *type, struct type **of_type)
|
|||||||
l1 = type->field (i).type ()->bounds ()->low.const_val ();
|
l1 = type->field (i).type ()->bounds ()->low.const_val ();
|
||||||
h1 = type->field (len - 1).type ()->bounds ()->high.const_val ();
|
h1 = type->field (len - 1).type ()->bounds ()->high.const_val ();
|
||||||
*of_type = target;
|
*of_type = target;
|
||||||
if (m2_get_discrete_bounds (target, &l2, &h2) >= 0)
|
if (m2_get_discrete_bounds (target, &l2, &h2))
|
||||||
return (l1 == l2 && h1 == h2);
|
return (l1 == l2 && h1 == h2);
|
||||||
error (_("long_set failed to find discrete bounds for its subtype"));
|
error (_("long_set failed to find discrete bounds for its subtype"));
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ m2_print_long_set (struct type *type, const gdb_byte *valaddr,
|
|||||||
|
|
||||||
target = TYPE_TARGET_TYPE (range);
|
target = TYPE_TARGET_TYPE (range);
|
||||||
|
|
||||||
if (get_discrete_bounds (range, &field_low, &field_high) >= 0)
|
if (get_discrete_bounds (range, &field_low, &field_high))
|
||||||
{
|
{
|
||||||
for (i = low_bound; i <= high_bound; i++)
|
for (i = low_bound; i <= high_bound; i++)
|
||||||
{
|
{
|
||||||
@@ -137,7 +137,7 @@ m2_print_long_set (struct type *type, const gdb_byte *valaddr,
|
|||||||
if (field == len)
|
if (field == len)
|
||||||
break;
|
break;
|
||||||
range = type->field (field).type ()->index_type ();
|
range = type->field (field).type ()->index_type ();
|
||||||
if (get_discrete_bounds (range, &field_low, &field_high) < 0)
|
if (!get_discrete_bounds (range, &field_low, &field_high))
|
||||||
break;
|
break;
|
||||||
target = TYPE_TARGET_TYPE (range);
|
target = TYPE_TARGET_TYPE (range);
|
||||||
}
|
}
|
||||||
@@ -398,7 +398,7 @@ m2_value_print_inner (struct value *val, struct ui_file *stream, int recurse,
|
|||||||
|
|
||||||
fputs_filtered ("{", stream);
|
fputs_filtered ("{", stream);
|
||||||
|
|
||||||
i = get_discrete_bounds (range, &low_bound, &high_bound);
|
i = get_discrete_bounds (range, &low_bound, &high_bound) ? 0 : -1;
|
||||||
maybe_bad_bstring:
|
maybe_bad_bstring:
|
||||||
if (i < 0)
|
if (i < 0)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -343,7 +343,8 @@ pascal_value_print_inner (struct value *val, struct ui_file *stream,
|
|||||||
|
|
||||||
fputs_filtered ("[", stream);
|
fputs_filtered ("[", stream);
|
||||||
|
|
||||||
int bound_info = get_discrete_bounds (range, &low_bound, &high_bound);
|
int bound_info = (get_discrete_bounds (range, &low_bound, &high_bound)
|
||||||
|
? 0 : -1);
|
||||||
if (low_bound == 0 && high_bound == -1 && TYPE_LENGTH (type) > 0)
|
if (low_bound == 0 && high_bound == -1 && TYPE_LENGTH (type) > 0)
|
||||||
{
|
{
|
||||||
/* If we know the size of the set type, we can figure out the
|
/* If we know the size of the set type, we can figure out the
|
||||||
|
|||||||
@@ -1873,7 +1873,7 @@ value_bit_index (struct type *type, const gdb_byte *valaddr, int index)
|
|||||||
unsigned rel_index;
|
unsigned rel_index;
|
||||||
struct type *range = type->index_type ();
|
struct type *range = type->index_type ();
|
||||||
|
|
||||||
if (get_discrete_bounds (range, &low_bound, &high_bound) < 0)
|
if (!get_discrete_bounds (range, &low_bound, &high_bound))
|
||||||
return -2;
|
return -2;
|
||||||
if (index < low_bound || index > high_bound)
|
if (index < low_bound || index > high_bound)
|
||||||
return -1;
|
return -1;
|
||||||
|
|||||||
@@ -394,7 +394,7 @@ value_cast (struct type *type, struct value *arg2)
|
|||||||
int val_length = TYPE_LENGTH (type2);
|
int val_length = TYPE_LENGTH (type2);
|
||||||
LONGEST low_bound, high_bound, new_length;
|
LONGEST low_bound, high_bound, new_length;
|
||||||
|
|
||||||
if (get_discrete_bounds (range_type, &low_bound, &high_bound) < 0)
|
if (!get_discrete_bounds (range_type, &low_bound, &high_bound))
|
||||||
low_bound = 0, high_bound = 0;
|
low_bound = 0, high_bound = 0;
|
||||||
new_length = val_length / element_length;
|
new_length = val_length / element_length;
|
||||||
if (val_length % element_length != 0)
|
if (val_length % element_length != 0)
|
||||||
@@ -3773,7 +3773,7 @@ value_slice (struct value *array, int lowbound, int length)
|
|||||||
error (_("array not associated"));
|
error (_("array not associated"));
|
||||||
|
|
||||||
range_type = array_type->index_type ();
|
range_type = array_type->index_type ();
|
||||||
if (get_discrete_bounds (range_type, &lowerbound, &upperbound) < 0)
|
if (!get_discrete_bounds (range_type, &lowerbound, &upperbound))
|
||||||
error (_("slice from bad array or bitstring"));
|
error (_("slice from bad array or bitstring"));
|
||||||
|
|
||||||
if (lowbound < lowerbound || length < 0
|
if (lowbound < lowerbound || length < 0
|
||||||
|
|||||||
Reference in New Issue
Block a user