From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9719 invoked by alias); 24 Sep 2010 15:55:34 -0000 Received: (qmail 9696 invoked by uid 22791); 24 Sep 2010 15:55:30 -0000 X-SWARE-Spam-Status: No, hits=-1.7 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; Fri, 24 Sep 2010 15:55:23 +0000 Received: from d06nrmr1707.portsmouth.uk.ibm.com (d06nrmr1707.portsmouth.uk.ibm.com [9.149.39.225]) by mtagate7.uk.ibm.com (8.13.1/8.13.1) with ESMTP id o8OFtJLb005534 for ; Fri, 24 Sep 2010 15:55:19 GMT Received: from d06av02.portsmouth.uk.ibm.com (d06av02.portsmouth.uk.ibm.com [9.149.37.228]) by d06nrmr1707.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id o8OFtJaN3174612 for ; Fri, 24 Sep 2010 16:55:19 +0100 Received: from d06av02.portsmouth.uk.ibm.com (loopback [127.0.0.1]) by d06av02.portsmouth.uk.ibm.com (8.12.11.20060308/8.13.3) with ESMTP id o8OFtJXg018150 for ; Fri, 24 Sep 2010 16:55:19 +0100 Received: from leonard.localnet (dyn-9-152-224-33.boeblingen.de.ibm.com [9.152.224.33]) by d06av02.portsmouth.uk.ibm.com (8.12.11.20060308/8.12.11) with ESMTP id o8OFtFmE018062 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 24 Sep 2010 16:55:19 +0100 From: Ken Werner To: Jan Kratochvil Subject: Re: [patch] const array types Date: Fri, 24 Sep 2010 18:36:00 -0000 User-Agent: KMail/1.13.2 (Linux/2.6.32-24-generic; KDE/4.4.2; i686; ; ) Cc: gdb-patches@sourceware.org References: <201009151920.37105.ken@linux.vnet.ibm.com> <20100923223709.GA25145@host1.dyn.jankratochvil.net> In-Reply-To: <20100923223709.GA25145@host1.dyn.jankratochvil.net> MIME-Version: 1.0 Content-Type: Multipart/Mixed; boundary="Boundary-00=_jnMnMtWnqwzhTMp" Message-Id: <201009241755.15373.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-09/txt/msg00438.txt.bz2 --Boundary-00=_jnMnMtWnqwzhTMp Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-length: 1593 On Friday, September 24, 2010 12:37:09 am Jan Kratochvil wrote: > On Wed, 15 Sep 2010 19:20:37 +0200, Ken Werner wrote: > > The attached patch changes the dwarf parsing of const types. In case the > > const qualifier is applied to an array type, the element type is so > > qualified, not the array type. Comments are welcome. > > I have filed now http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45765 as > I believe it could be fixed more at the DWARF producer side. > > It is questionable whether it gets accepted and fixed by GCC and whether > you would like it then fixed in GDB even for older GCCs and non-GCC > compilers. > > I believe besides TYPE_CODE_ARRAY the same logic should be applied even to > all the fields of TYPE_CODE_STRUCT and TYPE_CODE_UNION (excluding the > static fields). While ISO C99 does not say so (or does?) GCC behaves > correctly: C99 is pretty clear for const arrays but structs and unions seem to be different. Section 6.5.2.3 says that the result of the . and -> operators have the const version of the type. So, in that case we probably don't want to copy the type in the dwarf reader but alter the result types in case of field access. > I would find this patch OK even if it fixes only the TYPE_CODE_ARRAY. Thanks for reviewing. I've changed the last make_cv_type argument to NULL and attached a new version of that patch, OK to apply? > > + make_cv_type (1, TYPE_VOLATILE (el_type), el_type, 0); > > ^ NULL? > I would find NULL for a pointer parameter more readable. Fixed. Regards Ken --Boundary-00=_jnMnMtWnqwzhTMp Content-Type: text/x-patch; charset="UTF-8"; name="const_array.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="const_array.patch" Content-length: 4689 ChangeLog: 2010-09-24 Ken Werner * gdb/dwarf2read.c (read_tag_const_type): Handle const arrays. testsuite/ChangeLog: 2010-09-24 Ken Werner * gdb.base/constvars.c (logical, lugged, luck, lunar, lumen, lurk, lush, lynx) New constant. * gdb.base/constvars.exp: Test const array types. * gdb.dwarf2/dw2-strp.exp: Add const qualifier for ptype tests. Index: gdb/dwarf2read.c =================================================================== RCS file: /cvs/src/src/gdb/dwarf2read.c,v retrieving revision 1.460 diff -p -u -r1.460 dwarf2read.c --- gdb/dwarf2read.c 22 Sep 2010 19:22:44 -0000 1.460 +++ gdb/dwarf2read.c 24 Sep 2010 15:17:02 -0000 @@ -7632,6 +7632,29 @@ read_tag_const_type (struct die_info *di if (cv_type) return cv_type; + /* In case the const qualifier is applied to an array type, the element type + is so qualified, not the array type (section 6.7.3 of C99). */ + if (TYPE_CODE (base_type) == TYPE_CODE_ARRAY) + { + struct type *el_type, *inner_array; + + base_type = copy_type (base_type); + inner_array = base_type; + + while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array)) == TYPE_CODE_ARRAY) + { + TYPE_TARGET_TYPE (inner_array) = + copy_type (TYPE_TARGET_TYPE (inner_array)); + inner_array = TYPE_TARGET_TYPE (inner_array); + } + + el_type = TYPE_TARGET_TYPE (inner_array); + TYPE_TARGET_TYPE (inner_array) = + make_cv_type (1, TYPE_VOLATILE (el_type), el_type, NULL); + + return set_die_type (die, base_type, cu);; + } + cv_type = make_cv_type (1, TYPE_VOLATILE (base_type), base_type, 0); return set_die_type (die, cv_type, cu); } Index: gdb/testsuite/gdb.base/constvars.c =================================================================== RCS file: /cvs/src/src/gdb/testsuite/gdb.base/constvars.c,v retrieving revision 1.4 diff -p -u -r1.4 constvars.c --- gdb/testsuite/gdb.base/constvars.c 12 Nov 2009 19:35:26 -0000 1.4 +++ gdb/testsuite/gdb.base/constvars.c 24 Sep 2010 15:17:02 -0000 @@ -84,6 +84,16 @@ main (void) float *const lissome = &leeway; double *const locust = &legacy; + /* constant arrays */ + const char logical[2] = {laconic, laconic}; + const unsigned char lugged[2] = {laggard, laggard}; + const short luck[2] = {lagoon, lagoon}; + const unsigned short lunar[2] = {laity, laity}; + const long lumen[2] = {lambent, lambent}; + const unsigned long lurk[2] = {laminated, laminated}; + const float lush[2] = {lampoon, lampoon}; + const double lynx[2] = {languid, languid}; + /* volatile variables */ volatile char vox = 'X'; Index: gdb/testsuite/gdb.base/constvars.exp =================================================================== RCS file: /cvs/src/src/gdb/testsuite/gdb.base/constvars.exp,v retrieving revision 1.23 diff -p -u -r1.23 constvars.exp --- gdb/testsuite/gdb.base/constvars.exp 24 May 2010 22:03:59 -0000 1.23 +++ gdb/testsuite/gdb.base/constvars.exp 24 Sep 2010 15:17:02 -0000 @@ -253,6 +253,16 @@ proc do_constvar_tests {} { gdb_test "ptype locust" "type = double \\* const" local_compiler_xfail_check + gdb_test "ptype logical" "type = const char \\\[2\\\]" + gdb_test "ptype lugged" "type = const unsigned char \\\[2\\\]" + gdb_test "ptype luck" "type = const short( int)? \\\[2\\\]" + gdb_test "ptype lunar" "type = const (unsigned short|short unsigned)( int)? \\\[2\\\]" + gdb_test "ptype lumen" "type = const long( int)? \\\[2\\\]" + gdb_test "ptype lurk" "type = const (unsigned long|long unsigned)( int)? \\\[2\\\]" + gdb_test "ptype lush" "type = const float \\\[2\\\]" + gdb_test "ptype lynx" "type = const double \\\[2\\\]" + + local_compiler_xfail_check local_compiler_xfail_check_2 gdb_test "ptype crass" "type = struct crass \{\[\r\n\]+\[\ \t\]+char \\* const ptr;\[\r\n\]+\}" local_compiler_xfail_check Index: gdb/testsuite/gdb.dwarf2/dw2-strp.exp =================================================================== RCS file: /cvs/src/src/gdb/testsuite/gdb.dwarf2/dw2-strp.exp,v retrieving revision 1.4 diff -p -u -r1.4 dw2-strp.exp --- gdb/testsuite/gdb.dwarf2/dw2-strp.exp 1 Jan 2010 07:32:02 -0000 1.4 +++ gdb/testsuite/gdb.dwarf2/dw2-strp.exp 24 Sep 2010 15:17:02 -0000 @@ -49,7 +49,7 @@ gdb_reinitialize_dir $srcdir/$subdir gdb_load ${binfile} gdb_test "p a_string" " = \"hello world!\\\\n\"" -gdb_test "ptype a_string" "type = char \\\[14\\\]" +gdb_test "ptype a_string" "type = const char \\\[14\\\]" gdb_test "p a_string2" " = \"hello world2\\\\n\"" -gdb_test "ptype a_string2" "type = char \\\[14\\\]" +gdb_test "ptype a_string2" "type = const char \\\[14\\\]" --Boundary-00=_jnMnMtWnqwzhTMp--