/* Perform arithmetic and other operations on values, for GDB.
Copyright (C) 1986, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996,
- 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009
- Free Software Foundation, Inc.
+ 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009,
+ 2010 Free Software Foundation, Inc.
This file is part of GDB.
an integer nor a pointer of the same type."));
sz = TYPE_LENGTH (check_typedef (TYPE_TARGET_TYPE (type1)));
+ if (sz == 0)
+ {
+ warning (_("Type size unknown, assuming 1. "
+ "Try casting to a known type, or void *."));
+ sz = 1;
+ }
+
return (value_as_long (arg1) - value_as_long (arg2)) / sz;
}
struct value *
value_subscript (struct value *array, LONGEST index)
{
- struct value *bound;
int c_style = current_language->c_style_arrays;
struct type *tarray;
{
struct type *range_type = TYPE_INDEX_TYPE (tarray);
LONGEST lowerbound, upperbound;
- get_discrete_bounds (range_type, &lowerbound, &upperbound);
+ get_discrete_bounds (range_type, &lowerbound, &upperbound);
if (VALUE_LVAL (array) != lval_memory)
return value_subscripted_rvalue (array, index, lowerbound);
unsigned int elt_offs = elt_size * longest_to_int (index - lowerbound);
struct value *v;
- if (index < lowerbound || elt_offs >= TYPE_LENGTH (array_type))
+ if (index < lowerbound || (!TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (array_type)
+ && elt_offs >= TYPE_LENGTH (array_type)))
error (_("no such vector element"));
v = allocate_value (elt_type);
For now, we do not overload the `=' operator. */
int
-binop_user_defined_p (enum exp_opcode op, struct value *arg1, struct value *arg2)
+binop_types_user_defined_p (enum exp_opcode op,
+ struct type *type1, struct type *type2)
{
- struct type *type1, *type2;
if (op == BINOP_ASSIGN || op == BINOP_CONCAT)
return 0;
- type1 = check_typedef (value_type (arg1));
+ type1 = check_typedef (type1);
if (TYPE_CODE (type1) == TYPE_CODE_REF)
type1 = check_typedef (TYPE_TARGET_TYPE (type1));
- type2 = check_typedef (value_type (arg2));
+ type2 = check_typedef (type1);
if (TYPE_CODE (type2) == TYPE_CODE_REF)
type2 = check_typedef (TYPE_TARGET_TYPE (type2));
|| TYPE_CODE (type2) == TYPE_CODE_STRUCT);
}
+/* Check to see if either argument is a structure, or a reference to
+ one. This is called so we know whether to go ahead with the normal
+ binop or look for a user defined function instead.
+
+ For now, we do not overload the `=' operator. */
+
+int
+binop_user_defined_p (enum exp_opcode op,
+ struct value *arg1, struct value *arg2)
+{
+ return binop_types_user_defined_p (op, value_type (arg1), value_type (arg2));
+}
+
/* Check to see if argument is a structure. This is called so
we know whether to go ahead with the normal unop or look for a
user defined function instead.
unop_user_defined_p (enum exp_opcode op, struct value *arg1)
{
struct type *type1;
+
if (op == UNOP_ADDR)
return 0;
type1 = check_typedef (value_type (arg1));
if (noside == EVAL_AVOID_SIDE_EFFECTS)
{
struct type *return_type;
+
return_type
= TYPE_TARGET_TYPE (check_typedef (value_type (argvec[0])));
return value_zero (return_type, VALUE_LVAL (arg1));
if (noside == EVAL_AVOID_SIDE_EFFECTS)
{
struct type *return_type;
+
return_type
= TYPE_TARGET_TYPE (check_typedef (value_type (argvec[0])));
return value_zero (return_type, VALUE_LVAL (arg1));
if (TYPE_CODE (type2) == TYPE_CODE_INT)
{
struct type *tmp = type1;
+
type1 = tmp;
tmp = type2;
inval1 = arg2;
if (TYPE_CODE (type2) == TYPE_CODE_CHAR)
{
char_type = type2;
+
inchar = (char) unpack_long (type2,
value_contents (inval2));
for (idx = 0; idx < count; idx++)
else
{
char_type = TYPE_TARGET_TYPE (type2);
+
for (idx = 0; idx < count; idx++)
{
memcpy (ptr + (idx * inval2len), value_contents (inval2),
if (TYPE_CODE (type1) == TYPE_CODE_CHAR)
{
char_type = type1;
+
*ptr = (char) unpack_long (type1, value_contents (inval1));
}
else
{
char_type = TYPE_TARGET_TYPE (type1);
+
memcpy (ptr, value_contents (inval1), inval1len);
}
if (TYPE_CODE (type2) == TYPE_CODE_CHAR)
other types if one of them is not decimal floating point. */
static void
value_args_as_decimal (struct value *arg1, struct value *arg2,
- gdb_byte *x, int *len_x, gdb_byte *y, int *len_y)
+ gdb_byte *x, int *len_x, enum bfd_endian *byte_order_x,
+ gdb_byte *y, int *len_y, enum bfd_endian *byte_order_y)
{
struct type *type1, *type2;
if (TYPE_CODE (type1) == TYPE_CODE_DECFLOAT)
{
+ *byte_order_x = gdbarch_byte_order (get_type_arch (type1));
*len_x = TYPE_LENGTH (type1);
memcpy (x, value_contents (arg1), *len_x);
}
else if (is_integral_type (type1))
{
+ *byte_order_x = gdbarch_byte_order (get_type_arch (type2));
*len_x = TYPE_LENGTH (type2);
- decimal_from_integral (arg1, x, *len_x);
+ decimal_from_integral (arg1, x, *len_x, *byte_order_x);
}
else
error (_("Don't know how to convert from %s to %s."), TYPE_NAME (type1),
if (TYPE_CODE (type2) == TYPE_CODE_DECFLOAT)
{
+ *byte_order_y = gdbarch_byte_order (get_type_arch (type2));
*len_y = TYPE_LENGTH (type2);
memcpy (y, value_contents (arg2), *len_y);
}
else if (is_integral_type (type2))
{
+ *byte_order_y = gdbarch_byte_order (get_type_arch (type1));
*len_y = TYPE_LENGTH (type1);
- decimal_from_integral (arg2, y, *len_y);
+ decimal_from_integral (arg2, y, *len_y, *byte_order_y);
}
else
error (_("Don't know how to convert from %s to %s."), TYPE_NAME (type1),
if (TYPE_CODE (type1) == TYPE_CODE_DECFLOAT
|| TYPE_CODE (type2) == TYPE_CODE_DECFLOAT)
{
- struct type *v_type;
int len_v1, len_v2, len_v;
+ enum bfd_endian byte_order_v1, byte_order_v2, byte_order_v;
gdb_byte v1[16], v2[16];
gdb_byte v[16];
result_type = type1;
len_v = TYPE_LENGTH (result_type);
+ byte_order_v = gdbarch_byte_order (get_type_arch (result_type));
- value_args_as_decimal (arg1, arg2, v1, &len_v1, v2, &len_v2);
+ value_args_as_decimal (arg1, arg2, v1, &len_v1, &byte_order_v1,
+ v2, &len_v2, &byte_order_v2);
switch (op)
{
case BINOP_MUL:
case BINOP_DIV:
case BINOP_EXP:
- decimal_binop (op, v1, len_v1, v2, len_v2, v, len_v);
+ decimal_binop (op, v1, len_v1, byte_order_v1,
+ v2, len_v2, byte_order_v2,
+ v, len_v, byte_order_v);
break;
default:
in target format. real.c in GCC probably has the necessary
code. */
DOUBLEST v1, v2, v = 0;
+
v1 = value_as_double (arg1);
v2 = value_as_double (arg2);
|| TYPE_CODE (type2) == TYPE_CODE_BOOL)
{
LONGEST v1, v2, v = 0;
+
v1 = value_as_long (arg1);
v2 = value_as_long (arg2);
val = allocate_value (result_type);
store_signed_integer (value_contents_raw (val),
TYPE_LENGTH (result_type),
+ gdbarch_byte_order (get_type_arch (result_type)),
v);
}
else
{
LONGEST v2_signed = value_as_long (arg2);
ULONGEST v1, v2, v = 0;
+
v1 = (ULONGEST) value_as_long (arg1);
v2 = (ULONGEST) v2_signed;
v = v1 < v2;
break;
+ case BINOP_GTR:
+ v = v1 > v2;
+ break;
+
+ case BINOP_LEQ:
+ v = v1 <= v2;
+ break;
+
+ case BINOP_GEQ:
+ v = v1 >= v2;
+ break;
+
default:
error (_("Invalid binary operation on numbers."));
}
val = allocate_value (result_type);
store_unsigned_integer (value_contents_raw (val),
TYPE_LENGTH (value_type (val)),
+ gdbarch_byte_order
+ (get_type_arch (result_type)),
v);
}
else
{
LONGEST v1, v2, v = 0;
+
v1 = value_as_long (arg1);
v2 = value_as_long (arg2);
v = v1 == v2;
break;
+ case BINOP_NOTEQUAL:
+ v = v1 != v2;
+ break;
+
case BINOP_LESS:
v = v1 < v2;
break;
+ case BINOP_GTR:
+ v = v1 > v2;
+ break;
+
+ case BINOP_LEQ:
+ v = v1 <= v2;
+ break;
+
+ case BINOP_GEQ:
+ v = v1 >= v2;
+ break;
+
default:
error (_("Invalid binary operation on numbers."));
}
val = allocate_value (result_type);
store_signed_integer (value_contents_raw (val),
TYPE_LENGTH (value_type (val)),
+ gdbarch_byte_order
+ (get_type_arch (result_type)),
v);
}
}
if (TYPE_CODE (type1) == TYPE_CODE_FLT)
return 0 == value_as_double (arg1);
else if (TYPE_CODE (type1) == TYPE_CODE_DECFLOAT)
- return decimal_is_zero (value_contents (arg1), TYPE_LENGTH (type1));
+ return decimal_is_zero (value_contents (arg1), TYPE_LENGTH (type1),
+ gdbarch_byte_order (get_type_arch (type1)));
len = TYPE_LENGTH (type1);
p = value_contents (arg1);
/* NOTE: kettenis/20050816: Avoid compiler bug on systems where
`long double' values are returned in static storage (m68k). */
DOUBLEST d = value_as_double (arg1);
+
return d == value_as_double (arg2);
}
else if ((code1 == TYPE_CODE_DECFLOAT || is_int1)
{
gdb_byte v1[16], v2[16];
int len_v1, len_v2;
+ enum bfd_endian byte_order_v1, byte_order_v2;
- value_args_as_decimal (arg1, arg2, v1, &len_v1, v2, &len_v2);
+ value_args_as_decimal (arg1, arg2, v1, &len_v1, &byte_order_v1,
+ v2, &len_v2, &byte_order_v2);
- return decimal_compare (v1, len_v1, v2, len_v2) == 0;
+ return decimal_compare (v1, len_v1, byte_order_v1,
+ v2, len_v2, byte_order_v2) == 0;
}
/* FIXME: Need to promote to either CORE_ADDR or LONGEST, whichever
}
}
+/* Compare values based on their raw contents. Useful for arrays since
+ value_equal coerces them to pointers, thus comparing just the address
+ of the array instead of its contents. */
+
+int
+value_equal_contents (struct value *arg1, struct value *arg2)
+{
+ struct type *type1, *type2;
+
+ type1 = check_typedef (value_type (arg1));
+ type2 = check_typedef (value_type (arg2));
+
+ return (TYPE_CODE (type1) == TYPE_CODE (type2)
+ && TYPE_LENGTH (type1) == TYPE_LENGTH (type2)
+ && memcmp (value_contents (arg1), value_contents (arg2),
+ TYPE_LENGTH (type1)) == 0);
+}
+
/* Simulate the C operator < by returning 1
iff ARG1's contents are less than ARG2's. */
/* NOTE: kettenis/20050816: Avoid compiler bug on systems where
`long double' values are returned in static storage (m68k). */
DOUBLEST d = value_as_double (arg1);
+
return d < value_as_double (arg2);
}
else if ((code1 == TYPE_CODE_DECFLOAT || is_int1)
{
gdb_byte v1[16], v2[16];
int len_v1, len_v2;
+ enum bfd_endian byte_order_v1, byte_order_v2;
- value_args_as_decimal (arg1, arg2, v1, &len_v1, v2, &len_v2);
+ value_args_as_decimal (arg1, arg2, v1, &len_v1, &byte_order_v1,
+ v2, &len_v2, &byte_order_v2);
- return decimal_compare (v1, len_v1, v2, len_v2) == -1;
+ return decimal_compare (v1, len_v1, byte_order_v1,
+ v2, len_v2, byte_order_v2) == -1;
}
else if (code1 == TYPE_CODE_PTR && code2 == TYPE_CODE_PTR)
return value_as_address (arg1) < value_as_address (arg2);
LONGEST word;
unsigned rel_index;
struct type *range = TYPE_INDEX_TYPE (type);
+
if (get_discrete_bounds (range, &low_bound, &high_bound) < 0)
return -2;
if (index < low_bound || index > high_bound)
return -1;
rel_index = index - low_bound;
- word = extract_unsigned_integer (valaddr + (rel_index / TARGET_CHAR_BIT), 1);
+ word = extract_unsigned_integer (valaddr + (rel_index / TARGET_CHAR_BIT), 1,
+ gdbarch_byte_order (gdbarch));
rel_index %= TARGET_CHAR_BIT;
if (gdbarch_bits_big_endian (gdbarch))
rel_index = TARGET_CHAR_BIT - 1 - rel_index;
int member;
struct type *settype = check_typedef (value_type (set));
struct type *eltype = check_typedef (value_type (element));
+
if (TYPE_CODE (eltype) == TYPE_CODE_RANGE)
eltype = TYPE_TARGET_TYPE (eltype);
if (TYPE_CODE (settype) != TYPE_CODE_SET)