diff options
author | Ken Werner <ken.werner@de.ibm.com> | 2010-11-03 13:49:38 +0000 |
---|---|---|
committer | Ken Werner <ken.werner@de.ibm.com> | 2010-11-03 13:49:38 +0000 |
commit | c37f7098e9cb05b2574cf82e6ae299530ed407ba (patch) | |
tree | 04d07481c7bee9f22662d80e56efecb1311ce103 | |
parent | 2ebf396434301f62203a5f1d3ada888af8dd193d (diff) | |
download | gdb-c37f7098e9cb05b2574cf82e6ae299530ed407ba.zip gdb-c37f7098e9cb05b2574cf82e6ae299530ed407ba.tar.gz gdb-c37f7098e9cb05b2574cf82e6ae299530ed407ba.tar.bz2 |
gdb:
* value.h (value_non_lval): Declare.
* value.c (value_non_lval): New function.
* eval.c (evaluate_subexp_standard) <UNOP_POSTINCREMENT,
UNOP_POSTDECREMENT>: Call value_non_lval to ensure to return a
non-lvalue.
gdb/testsuite:
* gdb.base/exprs.exp: Add tests for pre-/post- in-/decrement operators.
-rw-r--r-- | gdb/ChangeLog | 8 | ||||
-rw-r--r-- | gdb/eval.c | 8 | ||||
-rw-r--r-- | gdb/testsuite/ChangeLog | 4 | ||||
-rw-r--r-- | gdb/testsuite/gdb.base/exprs.exp | 9 | ||||
-rw-r--r-- | gdb/value.c | 20 | ||||
-rw-r--r-- | gdb/value.h | 2 |
6 files changed, 49 insertions, 2 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 6843722..1304ac1 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,11 @@ +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, + UNOP_POSTDECREMENT>: Call value_non_lval to ensure to return a + non-lvalue. + 2010-11-02 Doug Evans <dje@google.com> New python module gdb.printing, and new commands info pretty-printer, @@ -2782,6 +2782,8 @@ evaluate_subexp_standard (struct type *expect_type, } else { + arg3 = value_non_lval (arg1); + if (ptrmath_type_p (exp->language_defn, value_type (arg1))) arg2 = value_ptradd (arg1, 1); else @@ -2794,7 +2796,7 @@ evaluate_subexp_standard (struct type *expect_type, } value_assign (arg1, arg2); - return arg1; + return arg3; } case UNOP_POSTDECREMENT: @@ -2807,6 +2809,8 @@ evaluate_subexp_standard (struct type *expect_type, } else { + arg3 = value_non_lval (arg1); + if (ptrmath_type_p (exp->language_defn, value_type (arg1))) arg2 = value_ptradd (arg1, -1); else @@ -2819,7 +2823,7 @@ evaluate_subexp_standard (struct type *expect_type, } value_assign (arg1, arg2); - return arg1; + return arg3; } case OP_THIS: diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 4b24a22..38ee97f 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,7 @@ +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> * gdb.python/py-pp-maint.c: New file. diff --git a/gdb/testsuite/gdb.base/exprs.exp b/gdb/testsuite/gdb.base/exprs.exp index e84bf31..25ba687 100644 --- a/gdb/testsuite/gdb.base/exprs.exp +++ b/gdb/testsuite/gdb.base/exprs.exp @@ -253,3 +253,12 @@ gdb_test "set output-radix 8" ".*" test_expr "print red" "\\$\[0-9\]* = red" test_expr "print/d red" "\\$\[0-9\]* = 0" gdb_test "set output-radix 10" ".*" + +# Pre-/post in-/decrement tests. +gdb_test "set variable v_int = 1" "" +gdb_test "print v_int++" "\\$\[0-9\]* = 1" +gdb_test "print ++v_int" "\\$\[0-9\]* = 3" +gdb_test "print v_int--" "\\$\[0-9\]* = 3" +gdb_test "print --v_int" "\\$\[0-9\]* = 1" +gdb_test "print v_int++ = 5" "Left operand of assignment is not an lvalue." +gdb_test "print v_int-- = 5" "Left operand of assignment is not an lvalue." diff --git a/gdb/value.c b/gdb/value.c index 55fcd38..381318b 100644 --- a/gdb/value.c +++ b/gdb/value.c @@ -826,6 +826,26 @@ value_copy (struct value *arg) return val; } +/* Return a version of ARG that is non-lvalue. */ + +struct value * +value_non_lval (struct value *arg) +{ + if (VALUE_LVAL (arg) != not_lval) + { + struct type *enc_type = value_enclosing_type (arg); + struct value *val = allocate_value (enc_type); + + memcpy (value_contents_all_raw (val), value_contents_all (arg), + TYPE_LENGTH (enc_type)); + val->type = arg->type; + set_value_embedded_offset (val, value_embedded_offset (arg)); + set_value_pointed_to_offset (val, value_pointed_to_offset (arg)); + return val; + } + return arg; +} + void set_value_component_location (struct value *component, const struct value *whole) diff --git a/gdb/value.h b/gdb/value.h index d7912a8..543290a 100644 --- a/gdb/value.h +++ b/gdb/value.h @@ -711,6 +711,8 @@ extern void preserve_values (struct objfile *); extern struct value *value_copy (struct value *); +extern struct value *value_non_lval (struct value *); + extern void preserve_one_value (struct value *, struct objfile *, htab_t); /* From valops.c */ |