diff options
author | Ken Werner <ken.werner@de.ibm.com> | 2010-11-03 14:06:27 +0000 |
---|---|---|
committer | Ken Werner <ken.werner@de.ibm.com> | 2010-11-03 14:06:27 +0000 |
commit | 120bd36024971107c9f5dce6882e343c836a6402 (patch) | |
tree | 30540b525cde8e6b84e8bb78a4cfa77ab9acddc5 | |
parent | c37f7098e9cb05b2574cf82e6ae299530ed407ba (diff) | |
download | gdb-120bd36024971107c9f5dce6882e343c836a6402.zip gdb-120bd36024971107c9f5dce6882e343c836a6402.tar.gz gdb-120bd36024971107c9f5dce6882e343c836a6402.tar.bz2 |
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.
-rw-r--r-- | gdb/ChangeLog | 6 | ||||
-rw-r--r-- | gdb/testsuite/ChangeLog | 4 | ||||
-rw-r--r-- | gdb/testsuite/gdb.base/gnu_vector.exp | 14 | ||||
-rw-r--r-- | gdb/valarith.c | 45 | ||||
-rw-r--r-- | gdb/valops.c | 14 |
5 files changed, 78 insertions, 5 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 1304ac1..93817ec 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,11 @@ 2010-11-03 Ken Werner <ken.werner@de.ibm.com> + * valarith.c (value_pos, value_neg, value_complement): Handle + vector types. + * valops.c (value_one): Likewise. + +2010-11-03 Ken Werner <ken.werner@de.ibm.com> + * value.h (value_non_lval): Declare. * value.c (value_non_lval): New function. * eval.c (evaluate_subexp_standard) <UNOP_POSTINCREMENT, diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 38ee97f..c062b02 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,5 +1,9 @@ 2010-11-03 Ken Werner <ken.werner@de.ibm.com> + * gdb.base/gnu_vector.exp: Add unary operator tests. + +2010-11-03 Ken Werner <ken.werner@de.ibm.com> + * gdb.base/exprs.exp: Add tests for pre-/post- in-/decrement operators. 2010-11-02 Doug Evans <dje@google.com> diff --git a/gdb/testsuite/gdb.base/gnu_vector.exp b/gdb/testsuite/gdb.base/gnu_vector.exp index e786365..870b563 100644 --- a/gdb/testsuite/gdb.base/gnu_vector.exp +++ b/gdb/testsuite/gdb.base/gnu_vector.exp @@ -50,7 +50,7 @@ if { ![runto main] } { gdb_test "print c4" "\\\$$decimal = \\{1, 2, 3, 4\\}" gdb_test "print c4\[2\]" "\\\$$decimal = 3" -# Test binary operators on integer vector types +# Test operators on integer vector types gdb_test "print i4a" "\\\$$decimal = \\{2, 4, 8, 16\\}" gdb_test "print i4b" "\\\$$decimal = \\{1, 2, 8, 4\\}" # Arithmetic operators @@ -59,15 +59,23 @@ gdb_test "print i4a - i4b" "\\\$$decimal = \\{1, 2, 0, 12\\}" gdb_test "print i4a * i4b" "\\\$$decimal = \\{2, 8, 64, 64\\}" gdb_test "print i4a / i4b" "\\\$$decimal = \\{2, 2, 1, 4\\}" gdb_test "print i4a % i4b" "\\\$$decimal = \\{0, 0, 0, 0\\}" +gdb_test "print i4a++" "\\\$$decimal = \\{2, 4, 8, 16\\}" +gdb_test "print ++i4a" "\\\$$decimal = \\{4, 6, 10, 18\\}" +gdb_test "print i4a--" "\\\$$decimal = \\{4, 6, 10, 18\\}" +gdb_test "print --i4a" "\\\$$decimal = \\{2, 4, 8, 16\\}" +gdb_test "print +i4a" "\\\$$decimal = \\{2, 4, 8, 16\\}" +gdb_test "print -i4a" "\\\$$decimal = \\{-2, -4, -8, -16\\}" + # Bitwise operators gdb_test "print i4a & i4b" "\\\$$decimal = \\{0, 0, 8, 0\\}" gdb_test "print i4a | i4b" "\\\$$decimal = \\{3, 6, 8, 20\\}" gdb_test "print i4a ^ i4b" "\\\$$decimal = \\{3, 6, 0, 20\\}" +gdb_test "print ~i4a" "\\\$$decimal = \\{-3, -5, -9, -17\\}" # Shift operators gdb_test "print i4a << i4b" "\\\$$decimal = \\{4, 16, 2048, 256\\}" gdb_test "print i4a >> i4b" "\\\$$decimal = \\{1, 1, 0, 1\\}" -# Test binary operators on floating point vector types +# Test operators on floating point vector types gdb_test "print f4a" "\\\$$decimal = \\{2, 4, 8, 16\\}" gdb_test "print f4b" "\\\$$decimal = \\{1, 2, 8, 4\\}" # Arithmetic operators @@ -75,6 +83,8 @@ gdb_test "print f4a + f4b" "\\\$$decimal = \\{3, 6, 16, 20\\}" gdb_test "print f4a - f4b" "\\\$$decimal = \\{1, 2, 0, 12\\}" gdb_test "print f4a * f4b" "\\\$$decimal = \\{2, 8, 64, 64\\}" gdb_test "print f4a / f4b" "\\\$$decimal = \\{2, 2, 1, 4\\}" +gdb_test "print +f4a" "\\\$$decimal = \\{2, 4, 8, 16\\}" +gdb_test "print -f4a" "\\\$$decimal = \\{-2, -4, -8, -16\\}" # Test scalar to vector widening gdb_test "print (int2) 1" "\\\$$decimal = \\{1, 1\\}" diff --git a/gdb/valarith.c b/gdb/valarith.c index 88f1448..f6e3a05 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, diff --git a/gdb/valops.c b/gdb/valops.c index 07b62a1..22ba54a 100644 --- a/gdb/valops.c +++ b/gdb/valops.c @@ -871,6 +871,20 @@ value_one (struct type *type, enum lval_type lv) { val = value_from_longest (type, (LONGEST) 1); } + else if (TYPE_CODE (type1) == TYPE_CODE_ARRAY && TYPE_VECTOR (type1)) + { + struct type *eltype = check_typedef (TYPE_TARGET_TYPE (type1)); + int i, n = TYPE_LENGTH (type1) / TYPE_LENGTH (eltype); + struct value *tmp; + + val = allocate_value (type); + for (i = 0; i < n; i++) + { + tmp = value_one (eltype, lv); + memcpy (value_contents_writeable (val) + i * TYPE_LENGTH (eltype), + value_contents_all (tmp), TYPE_LENGTH (eltype)); + } + } else { error (_("Not a numeric type.")); |