gdb:
authorKen Werner <ken.werner@de.ibm.com>
Wed, 3 Nov 2010 13:49:38 +0000 (13:49 +0000)
committerKen Werner <ken.werner@de.ibm.com>
Wed, 3 Nov 2010 13:49:38 +0000 (13:49 +0000)
* 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.

gdb/ChangeLog
gdb/eval.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.base/exprs.exp
gdb/value.c
gdb/value.h

index 684372252ab3ebd4f5f2efafff3e9dfcca514e5d..1304ac1bd69dd30e27c8623b3c747c20e283daef 100644 (file)
@@ -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,
index 471dcd7a56359a7844ac161e19c65ef12ae58282..71c3ff8cae76576099479e8bf957488d7e7b421b 100644 (file)
@@ -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:
index 4b24a22ae823a6b6a43c188ee2006e52c6bfa7db..38ee97f4344fbf17bf347debc55f424b3674d891 100644 (file)
@@ -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.
index e84bf31b5a55fb9101299d354573073eea55a59e..25ba68798d5c21202efb5f6acc06f53ebf506b4a 100644 (file)
@@ -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."
index 55fcd38a41206e0779430a441a312cb7b056d809..381318b987c36cee05ea58ff09c361b962fa424c 100644 (file)
@@ -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)
index d7912a89bbb9fd4a8009155a6b21655ed5450c8c..543290a753d14872f41a4dc54c4ee43ec19b5104 100644 (file)
@@ -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 */
This page took 0.068634 seconds and 4 git commands to generate.