summaryrefslogtreecommitdiff
path: root/gdb/valarith.c
diff options
context:
space:
mode:
authorKen Werner <ken.werner@de.ibm.com>2010-11-03 14:06:27 +0000
committerKen Werner <ken.werner@de.ibm.com>2010-11-03 14:06:27 +0000
commit120bd36024971107c9f5dce6882e343c836a6402 (patch)
tree30540b525cde8e6b84e8bb78a4cfa77ab9acddc5 /gdb/valarith.c
parentc37f7098e9cb05b2574cf82e6ae299530ed407ba (diff)
downloadbinutils-gdb-120bd36024971107c9f5dce6882e343c836a6402.tar.gz
gdb:
* valarith.c (value_pos, value_neg, value_complement): Handle vector types. * valops.c (value_one): Likewise. gdb/testsuite: * gdb.base/gnu_vector.exp: Add unary operator tests.
Diffstat (limited to 'gdb/valarith.c')
-rw-r--r--gdb/valarith.c45
1 files changed, 42 insertions, 3 deletions
diff --git a/gdb/valarith.c b/gdb/valarith.c
index 88f1448b0dd..f6e3a057242 100644
--- a/gdb/valarith.c
+++ b/gdb/valarith.c
@@ -1712,6 +1712,14 @@ value_pos (struct value *arg1)
{
return value_from_longest (type, value_as_long (arg1));
}
+ else if (TYPE_CODE (type) == TYPE_CODE_ARRAY && TYPE_VECTOR (type))
+ {
+ struct value *val = allocate_value (type);
+
+ memcpy (value_contents_raw (val), value_contents (arg1),
+ TYPE_LENGTH (type));
+ return val;
+ }
else
{
error ("Argument to positive operation not a number.");
@@ -1749,6 +1757,20 @@ value_neg (struct value *arg1)
{
return value_from_longest (type, -value_as_long (arg1));
}
+ else if (TYPE_CODE (type) == TYPE_CODE_ARRAY && TYPE_VECTOR (type))
+ {
+ struct value *tmp, *val = allocate_value (type);
+ struct type *eltype = check_typedef (TYPE_TARGET_TYPE (type));
+ int i, n = TYPE_LENGTH (type) / TYPE_LENGTH (eltype);
+
+ for (i = 0; i < n; i++)
+ {
+ tmp = value_neg (value_subscript (arg1, i));
+ memcpy (value_contents_writeable (val) + i * TYPE_LENGTH (eltype),
+ value_contents_all (tmp), TYPE_LENGTH (eltype));
+ }
+ return val;
+ }
else
{
error (_("Argument to negate operation not a number."));
@@ -1760,14 +1782,31 @@ struct value *
value_complement (struct value *arg1)
{
struct type *type;
+ struct value *val;
arg1 = coerce_ref (arg1);
type = check_typedef (value_type (arg1));
- if (!is_integral_type (type))
- error (_("Argument to complement operation not an integer or boolean."));
+ if (is_integral_type (type))
+ val = value_from_longest (type, ~value_as_long (arg1));
+ else if (TYPE_CODE (type) == TYPE_CODE_ARRAY && TYPE_VECTOR (type))
+ {
+ struct value *tmp;
+ struct type *eltype = check_typedef (TYPE_TARGET_TYPE (type));
+ int i, n = TYPE_LENGTH (type) / TYPE_LENGTH (eltype);
+
+ val = allocate_value (type);
+ for (i = 0; i < n; i++)
+ {
+ tmp = value_complement (value_subscript (arg1, i));
+ memcpy (value_contents_writeable (val) + i * TYPE_LENGTH (eltype),
+ value_contents_all (tmp), TYPE_LENGTH (eltype));
+ }
+ }
+ else
+ error (_("Argument to complement operation not an integer, boolean."));
- return value_from_longest (type, ~value_as_long (arg1));
+ return val;
}
/* The INDEX'th bit of SET value whose value_type is TYPE,