From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14057 invoked by alias); 6 Jul 2010 13:58:34 -0000 Received: (qmail 14045 invoked by uid 22791); 6 Jul 2010 13:58:32 -0000 X-SWARE-Spam-Status: No, hits=-1.9 required=5.0 tests=AWL,BAYES_00,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; Tue, 06 Jul 2010 13:58:16 +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 o66DwDOj007773 for ; Tue, 6 Jul 2010 13:58:13 GMT Received: from d06av01.portsmouth.uk.ibm.com (d06av01.portsmouth.uk.ibm.com [9.149.37.212]) by d06nrmr1806.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id o66DwDfd1511666 for ; Tue, 6 Jul 2010 14:58:13 +0100 Received: from d06av01.portsmouth.uk.ibm.com (loopback [127.0.0.1]) by d06av01.portsmouth.uk.ibm.com (8.12.11.20060308/8.13.3) with ESMTP id o66DwD6b025817 for ; Tue, 6 Jul 2010 14:58:13 +0100 Received: from leonard.localnet (dyn-9-152-224-29.boeblingen.de.ibm.com [9.152.224.29]) by d06av01.portsmouth.uk.ibm.com (8.12.11.20060308/8.12.11) with ESMTP id o66Dw7Ub025474 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Tue, 6 Jul 2010 14:58:13 +0100 From: Ken Werner To: gdb-patches@sourceware.org Subject: [patch] Small fix for assigning values to vectors Date: Tue, 06 Jul 2010 13:58:00 -0000 User-Agent: KMail/1.13.2 (Linux/2.6.32-23-generic-pae; KDE/4.4.2; i686; ; ) MIME-Version: 1.0 Content-Type: Multipart/Mixed; boundary="Boundary-00=_vZzMMWI6FA/LArG" Message-Id: <201007061558.07312.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-07/txt/msg00093.txt.bz2 --Boundary-00=_vZzMMWI6FA/LArG Content-Type: Text/Plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-length: 1454 Hi, I noticed that with the current GDB it is possible to assign values to not_lval-vector-values. Consider the following sample code: /* gcc -g -maltivec -mabi=altivec altivec.c -o altivec */ #include int test () { return 1; } vector int vtest () { return (vector int) {0, 1, 2, 3}; } int main () { return 0; } Here is the corresponding gdb session: gdb ./altivec start [...] (gdb) p test() $1 = 1 (gdb) p &test() Attempt to take address of value not located in memory. (gdb) set variable test() = 2 Left operand of assignment is not an lvalue. (gdb) (gdb) (gdb) p vtest() $2 = {0, 1, 2, 3} (gdb) p &vtest() $3 = (__vector signed int *) 0x10020008 (gdb) set variable vtest() = {3, 2, 1, 0} (gdb) p vtest() $4 = {0, 1, 2, 3} As can be seen the GDB behaves incorrect for vector types. A quick look to the valops.c:value_assign function shows that value_coerce_to_target creates a value with lval set to lval_memory for array types (including vectors). The code was introduced with the following patch: http://sourceware.org/ml/gdb- patches/2008-03/msg00079.html. I have to admit that I do not entirely understand why value_coerce_to_target is called here. The attached patch adds a check for vector types within value_coerce_to_target and extends the altivec-abi testcase. Tested on powerpc64-*-linux-gnu, no regressions. Any suggestions are welcome. Regards -ken --Boundary-00=_vZzMMWI6FA/LArG Content-Type: text/x-patch; charset="UTF-8"; name="vec_lval.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="vec_lval.patch" Content-length: 2099 Changelog: 2010-07-06 Ken Werner * valops.c (value_must_coerce_to_target): Return 0 in case of TYPE_VECTOR. testsuite/ChangeLog: 2010-07-06 Ken Werner * gdb.arch/altivec-abi.exp: New tests. Index: gdb/valops.c =================================================================== RCS file: /cvs/src/src/gdb/valops.c,v retrieving revision 1.248 diff -u -p -r1.248 valops.c --- gdb/valops.c 28 Jun 2010 20:35:52 -0000 1.248 +++ gdb/valops.c 6 Jul 2010 12:47:00 -0000 @@ -1424,6 +1424,9 @@ value_must_coerce_to_target (struct valu valtype = check_typedef (value_type (val)); + if (TYPE_VECTOR (valtype)) + return 0; + switch (TYPE_CODE (valtype)) { case TYPE_CODE_ARRAY: Index: gdb/testsuite/gdb.arch/altivec-abi.exp =================================================================== RCS file: /cvs/src/src/gdb/testsuite/gdb.arch/altivec-abi.exp,v retrieving revision 1.19 diff -u -p -r1.19 altivec-abi.exp --- gdb/testsuite/gdb.arch/altivec-abi.exp 2 Jul 2010 18:02:19 -0000 1.19 +++ gdb/testsuite/gdb.arch/altivec-abi.exp 6 Jul 2010 12:47:01 -0000 @@ -98,6 +98,16 @@ proc altivec_abi_tests { extra_flags for gdb_test "p vec_func(vshort_d,vushort_d,vint_d,vuint_d,vchar_d,vuchar_d,vfloat_d,x_d,y_d,a_d,b_d,c_d,intv_on_stack_d)" \ ".\[0-9\]+ = .0, 0, 0, 0." "call inferior function with vectors (2)" + # Attempt to take address of the return value of vec_func. + gdb_test "p &vec_func(vshort,vushort,vint,vuint,vchar,vuchar,vfloat,x,y,a,b,c,intv_on_stack)" \ + "Attempt to take address of value not located in memory." \ + "Attempt to take address of the return value of vec_func" + + # Attempt to assing a value to the return value of vec_func. + gdb_test "set variable vec_func(vshort,vushort,vint,vuint,vchar,vuchar,vfloat,x,y,a,b,c,intv_on_stack) = {0,1,2,3}" \ + "Left operand of assignment is not an lvalue." \ + "Attempt to assing a value to the return value of vec_func" + # Let's step into the function, to see if the args are printed correctly. gdb_test "step" \ $pattern1 \ --Boundary-00=_vZzMMWI6FA/LArG--