From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19608 invoked by alias); 19 Oct 2010 07:38:51 -0000 Received: (qmail 19480 invoked by uid 22791); 19 Oct 2010 07:38:50 -0000 X-SWARE-Spam-Status: No, hits=-1.6 required=5.0 tests=AWL,BAYES_00,TW_BJ,TW_CP,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mtagate2.uk.ibm.com (HELO mtagate2.uk.ibm.com) (194.196.100.162) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 19 Oct 2010 07:38:44 +0000 Received: from d06nrmr1707.portsmouth.uk.ibm.com (d06nrmr1707.portsmouth.uk.ibm.com [9.149.39.225]) by mtagate2.uk.ibm.com (8.13.1/8.13.1) with ESMTP id o9J7ce6j024510 for ; Tue, 19 Oct 2010 07:38:40 GMT Received: from d06av08.portsmouth.uk.ibm.com (d06av08.portsmouth.uk.ibm.com [9.149.37.249]) by d06nrmr1707.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id o9J7ceU33428472 for ; Tue, 19 Oct 2010 08:38:40 +0100 Received: from d06av08.portsmouth.uk.ibm.com (loopback [127.0.0.1]) by d06av08.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id o9J7cdP7029344 for ; Tue, 19 Oct 2010 08:38:40 +0100 Received: from leonard.localnet (dyn-9-152-224-33.boeblingen.de.ibm.com [9.152.224.33]) by d06av08.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id o9J7cZ0A029304 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 19 Oct 2010 08:38:39 +0100 From: Ken Werner To: Tom Tromey Subject: Re: [patch] fix pre-/post- in-/decrement Date: Tue, 19 Oct 2010 07:38:00 -0000 User-Agent: KMail/1.13.5 (Linux/2.6.35-22-generic-pae; KDE/4.5.1; i686; ; ) Cc: Joel Brobecker , Daniel Jacobowitz , Ulrich Weigand , gdb-patches@sourceware.org References: <201010041301.o94D1QHV032611@d12av02.megacenter.de.ibm.com> <201010131123.40225.ken@linux.vnet.ibm.com> In-Reply-To: MIME-Version: 1.0 Content-Type: Multipart/Mixed; boundary="Boundary-00=_6rUvMJKc+yJ3ug6" Message-Id: <201010190938.35120.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/msg00289.txt.bz2 --Boundary-00=_6rUvMJKc+yJ3ug6 Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-length: 1227 On Wednesday, October 13, 2010 9:00:28 pm Tom Tromey wrote: > Ken> I don't see how to control the type of the result of an operator > Ken> there. I'm still quite new to the GDB parsing internals and would > Ken> appreciate any insights. > > It is probably a bit of a pain, since the IR generated by the parser is > a bit unusual (as compilers go). > > However, it seems to me that it would be much friendlier for users to > report this as a parse error rather than a runtime error. > > One option would be to write a C/C++ implementation of the language_defn > la_post_parser method, which would look at the expression to see if this > constraint is violated. > > Another option would be to try to implement it in the grammar. Ok - I see. Thanks for your suggestions. This seems to be something bigger and could be implemented as part of a future patch :). I think for now the non- language dependent parts of the patch would be sufficient. The attached patch only contains the fix for the post in-/decrement operators as this is what the vec_unop patch (http://sourceware.org/ml/gdb- patches/2010-10/msg00031.html) prevents from going upstream. Tested on i686-*-linux-gnu with no regressions. OK to apply? Regards Ken --Boundary-00=_6rUvMJKc+yJ3ug6 Content-Type: text/x-patch; charset="UTF-8"; name="post_in_decrement.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="post_in_decrement.patch" Content-length: 3990 ChangeLog: 2010-10-18 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. testsuite/ChangeLog: 2010-10-18 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 18 Oct 2010 17:43:52 -0000 @@ -2739,6 +2739,8 @@ evaluate_subexp_standard (struct type *e } else { + arg3 = value_non_lval (arg1); + if (ptrmath_type_p (exp->language_defn, value_type (arg1))) arg2 = value_ptradd (arg1, 1); else @@ -2751,7 +2753,7 @@ evaluate_subexp_standard (struct type *e } value_assign (arg1, arg2); - return arg1; + return arg3; } case UNOP_POSTDECREMENT: @@ -2764,6 +2766,8 @@ evaluate_subexp_standard (struct type *e } else { + arg3 = value_non_lval (arg1); + if (ptrmath_type_p (exp->language_defn, value_type (arg1))) arg2 = value_ptradd (arg1, -1); else @@ -2776,7 +2780,7 @@ evaluate_subexp_standard (struct type *e } value_assign (arg1, arg2); - return arg1; + return arg3; } case OP_THIS: Index: gdb/value.c =================================================================== RCS file: /cvs/src/src/gdb/value.c,v retrieving revision 1.113 diff -p -u -r1.113 value.c --- gdb/value.c 30 Sep 2010 18:58:07 -0000 1.113 +++ gdb/value.c 18 Oct 2010 17:43:52 -0000 @@ -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: gdb/value.h =================================================================== RCS file: /cvs/src/src/gdb/value.h,v retrieving revision 1.162 diff -p -u -r1.162 value.h --- gdb/value.h 15 Oct 2010 18:54:13 -0000 1.162 +++ gdb/value.h 18 Oct 2010 17:43:52 -0000 @@ -711,6 +711,8 @@ extern void preserve_values (struct objf 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 */ 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 18 Oct 2010 17:43:52 -0000 @@ -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." --Boundary-00=_6rUvMJKc+yJ3ug6--