From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 31609 invoked by alias); 1 Oct 2010 17:45:51 -0000 Received: (qmail 31587 invoked by uid 22791); 1 Oct 2010 17:45:48 -0000 X-SWARE-Spam-Status: No, hits=-1.7 required=5.0 tests=AWL,BAYES_00,TW_CP,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mtagate7.uk.ibm.com (HELO mtagate7.uk.ibm.com) (194.196.100.167) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 01 Oct 2010 17:45:41 +0000 Received: from d06nrmr1806.portsmouth.uk.ibm.com (d06nrmr1806.portsmouth.uk.ibm.com [9.149.39.193]) by mtagate7.uk.ibm.com (8.13.1/8.13.1) with ESMTP id o91HjajB005525 for ; Fri, 1 Oct 2010 17:45:36 GMT Received: from d06av04.portsmouth.uk.ibm.com (d06av04.portsmouth.uk.ibm.com [9.149.37.216]) by d06nrmr1806.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id o91HjWg53625182 for ; Fri, 1 Oct 2010 18:45:36 +0100 Received: from d06av04.portsmouth.uk.ibm.com (loopback [127.0.0.1]) by d06av04.portsmouth.uk.ibm.com (8.12.11.20060308/8.13.3) with ESMTP id o91HjVaP017662 for ; Fri, 1 Oct 2010 18:45:31 +0100 Received: from leonard.localnet (dyn-9-152-224-33.boeblingen.de.ibm.com [9.152.224.33]) by d06av04.portsmouth.uk.ibm.com (8.12.11.20060308/8.12.11) with ESMTP id o91HjSVj017616 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 1 Oct 2010 18:45:31 +0100 From: Ken Werner To: gdb-patches@sourceware.org, Joel Brobecker Subject: [patch] fix pre-/post- in-/decrement Date: Fri, 01 Oct 2010 17:45:00 -0000 User-Agent: KMail/1.13.2 (Linux/2.6.32-25-generic; KDE/4.4.2; i686; ; ) References: <201009171033.35808.ken@linux.vnet.ibm.com> <20100930185634.GC6213@adacore.com> In-Reply-To: <20100930185634.GC6213@adacore.com> MIME-Version: 1.0 Content-Type: Multipart/Mixed; boundary="Boundary-00=_34hpM7p8Uw9sVZe" Message-Id: <201010011945.27883.ken@linux.vnet.ibm.com> X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2010-10/txt/msg00012.txt.bz2 --Boundary-00=_34hpM7p8Uw9sVZe Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-length: 659 On Thursday, September 30, 2010 8:56:34 pm Joel Brobecker wrote: > Would you mind if we treated this as a separate patch, on top of > the current patch? I'd also like to add a test that verifies this, > hopefully not involving vector types. The attached patch prevents the pre-/post- in-/decrement operators from returning lvalues. The following gdb command for example should not assign a value to the result of the post increment operation but throw an error: print i++ = 3; I've added a few tests to the testsuite. Please let me know if there is a better place to put them. Tested on i686-*-linux-gnu with no regressions. OK to apply? Thanks -ken --Boundary-00=_34hpM7p8Uw9sVZe Content-Type: text/x-patch; charset="UTF-8"; name="pre_post_in_decrement.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="pre_post_in_decrement.patch" Content-length: 3685 ChangeLog: 2010-10-01 Ken Werner * eval.c evaluate_subexp_standard) Set VALUE_LVAL of the result to not_lval. : Copy arg1 to prevent returning a lvalue. testsuite/ChangeLog: 2010-10-01 Ken Werner * gdb.base/exprs.exp: Add tests for pre-/post- in-/decrement operators. Index: gdb/eval.c =================================================================== RCS file: /cvs/src/src/gdb/eval.c,v retrieving revision 1.139 diff -p -u -r1.139 eval.c --- gdb/eval.c 11 Aug 2010 16:48:26 -0000 1.139 +++ gdb/eval.c 1 Oct 2010 17:31:16 -0000 @@ -2702,7 +2702,10 @@ evaluate_subexp_standard (struct type *e arg2 = value_binop (tmp, arg2, BINOP_ADD); } - return value_assign (arg1, arg2); + /* Prevent to return a lvalue. */ + arg3 = value_assign (arg1, arg2); + VALUE_LVAL (arg3) = not_lval; + return arg3; } case UNOP_PREDECREMENT: @@ -2726,7 +2729,10 @@ evaluate_subexp_standard (struct type *e arg2 = value_binop (tmp, arg2, BINOP_SUB); } - return value_assign (arg1, arg2); + /* Prevent to return a lvalue. */ + arg3 = value_assign (arg1, arg2); + VALUE_LVAL (arg3) = not_lval; + return arg3; } case UNOP_POSTINCREMENT: @@ -2739,7 +2745,14 @@ evaluate_subexp_standard (struct type *e } else { - if (ptrmath_type_p (exp->language_defn, value_type (arg1))) + type = value_type (arg1); + arg3 = allocate_value (type); + + /* Copy the value to prevent to return a lvalue. */ + memcpy (value_contents_raw (arg3), value_contents (arg1), + TYPE_LENGTH (type)); + + if (ptrmath_type_p (exp->language_defn, type)) arg2 = value_ptradd (arg1, 1); else { @@ -2751,7 +2764,7 @@ evaluate_subexp_standard (struct type *e } value_assign (arg1, arg2); - return arg1; + return arg3; } case UNOP_POSTDECREMENT: @@ -2764,7 +2777,14 @@ evaluate_subexp_standard (struct type *e } else { - if (ptrmath_type_p (exp->language_defn, value_type (arg1))) + type = value_type (arg1); + arg3 = allocate_value (type); + + /* Copy the value to prevent to return a lvalue. */ + memcpy (value_contents_raw (arg3), value_contents (arg1), + TYPE_LENGTH (type)); + + if (ptrmath_type_p (exp->language_defn, type)) arg2 = value_ptradd (arg1, -1); else { @@ -2776,7 +2796,7 @@ evaluate_subexp_standard (struct type *e } value_assign (arg1, arg2); - return arg1; + return arg3; } case OP_THIS: Index: gdb/testsuite/gdb.base/exprs.exp =================================================================== RCS file: /cvs/src/src/gdb/testsuite/gdb.base/exprs.exp,v retrieving revision 1.19 diff -p -u -r1.19 exprs.exp --- gdb/testsuite/gdb.base/exprs.exp 10 Jun 2010 19:48:19 -0000 1.19 +++ gdb/testsuite/gdb.base/exprs.exp 1 Oct 2010 17:31:16 -0000 @@ -253,3 +253,14 @@ 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." +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." --Boundary-00=_34hpM7p8Uw9sVZe--