From: Ken Werner Date: Wed, 3 Nov 2010 13:49:38 +0000 (+0000) Subject: gdb: X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=c37f7098e9cb05b2574cf82e6ae299530ed407ba;p=binutils-gdb.git gdb: * value.h (value_non_lval): Declare. * value.c (value_non_lval): New function. * eval.c (evaluate_subexp_standard) : 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. --- diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 684372252ab..1304ac1bd69 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,11 @@ +2010-11-03 Ken Werner + + * value.h (value_non_lval): Declare. + * value.c (value_non_lval): New function. + * eval.c (evaluate_subexp_standard) : Call value_non_lval to ensure to return a + non-lvalue. + 2010-11-02 Doug Evans New python module gdb.printing, and new commands info pretty-printer, diff --git a/gdb/eval.c b/gdb/eval.c index 471dcd7a563..71c3ff8cae7 100644 --- a/gdb/eval.c +++ b/gdb/eval.c @@ -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 4b24a22ae82..38ee97f4344 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2010-11-03 Ken Werner + + * gdb.base/exprs.exp: Add tests for pre-/post- in-/decrement operators. + 2010-11-02 Doug Evans * 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 e84bf31b5a5..25ba68798d5 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 55fcd38a412..381318b987c 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 d7912a89bbb..543290a753d 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 */