From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18698 invoked by alias); 4 Mar 2016 17:49:06 -0000 Mailing-List: contact gdb-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sourceware.org Received: (qmail 18668 invoked by uid 89); 4 Mar 2016 17:49:05 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=ascii, DIE, 14b, 2224 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Fri, 04 Mar 2016 17:49:04 +0000 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (Postfix) with ESMTPS id F3BD11E3B; Fri, 4 Mar 2016 17:49:02 +0000 (UTC) Received: from host1.jankratochvil.net (ovpn-116-55.ams2.redhat.com [10.36.116.55]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u24HmxLp029603 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Fri, 4 Mar 2016 12:49:02 -0500 Date: Fri, 04 Mar 2016 17:49:00 -0000 From: Jan Kratochvil To: Neven Sajko Cc: gdb@sourceware.org Subject: Re: Printing a 2D array in a C program Message-ID: <20160304174859.GA15741@host1.jankratochvil.net> References: <20160304144231.GA7767@host1.jankratochvil.net> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="/9DWx/yDrRhgMJTb" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) X-IsSubscribed: yes X-SW-Source: 2016-03/txt/msg00009.txt.bz2 --/9DWx/yDrRhgMJTb Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-length: 2173 On Fri, 04 Mar 2016 17:15:26 +0100, Neven Sajko wrote: > But in p `print *m` just gets me {a11, ..., a1n}. I think it is a bug in GCC. I haven't found it in GCC Bugzilla. I haven't filed it anywhere yet. All these compilers fail the same way: gcc-5.3.1-2.fc23.x86_64 gcc-6.0.0-0.13.fc25.x86_64 gcc (GCC) 6.0.0 20160213 (experimental) clang-3.7.0-4.fc23.x86_64 clang-3.8.0-0.3.fc25.x86_64 The .s diff is for: gcc -o matrix.s matrix.c -Wall -g -S -dA Jan The array variable: (gdb) s f (n=1) at matrix2.c:22 (gdb) ptype m type = int [17][17] (gdb) p m $1 = {{-134241616, 32767, -134252848, 32767, -140382932, 32767, 2224, 0, -134252032, 32767, -136422399, 32767, 2224, 0, -140329216, 32767, -134252112}, {32767, -134252032, 32767, -11384, 32767, -11388, 32767, 1, 0, -136460380, 32767, -140329216, 32767, [...] -10400, 32767, -134225592, 32767, 0, 0, 1, 0, 4195965, 0, 4195328, 0, 0, 0, 4195888}} The bug with the parameter: (gdb) s p (m=0x7fffffffd2a0, n=1) at matrix2.c:9 (gdb) ptype m type = int (*)[17] (gdb) p m $2 = (int (*)[17]) 0x7fffffffd2a0 (gdb) p *m $3 = {-134241616, 32767, -134252848, 32767, -140382932, 32767, 2224, 0, -134252032, 32767, -136422399, 32767, 2224, 0, -140329216, 32767, -134252112} Workaroundable by: (gdb) p *(int[17][17] *)m $4 = {{-134241616, 32767, -134252848, 32767, -140382932, 32767, 2224, 0, -134252032, 32767, -136422399, 32767, 2224, 0, -140329216, 32767, -134252112}, {32767, -134252032, 32767, -11384, 32767, -11388, 32767, 1, 0, -136460380, 32767, -140329216, 32767, [...] -10400, 32767, -134225592, 32767, 0, 0, 1, 0, 4195965, 0, 4195328, 0, 0, 0, 4195888}} After fixed DWARF without the workaround: (gdb) s p (m=0x7fffffffd2a0, n=1) at matrix2.c:9 (gdb) ptype m type = int (*)[17][17] (gdb) p m $1 = (int (*)[17][17]) 0x7fffffffd2a0 (gdb) p *m $2 = {{-134241616, 32767, -134252848, 32767, -140382932, 32767, 2224, 0, -134252032, 32767, -136422399, 32767, 2224, 0, -140329216, 32767, -134252112}, {32767, -134252032, 32767, -11384, 32767, -11388, 32767, 1, 0, -136460380, 32767, -140329216, 32767, [...] -10400, 32767, -134225592, 32767, 0, 0, 1, 0, 4195965, 0, 4195328, 0, 0, 0, 4195888}} --/9DWx/yDrRhgMJTb Content-Type: text/plain; charset=us-ascii Content-Description: Fix of the DWARF Content-Disposition: inline; filename="matrix2.s.diff" Content-length: 403 --- matrix2.s-orig 2016-03-04 18:30:45.846203946 +0100 +++ matrix2.s 2016-03-04 18:33:33.912409159 +0100 @@ -329,7 +329,7 @@ main: .byte 0 # end of children of DIE 0xf1 .uleb128 0xc # (DIE (0x101) DW_TAG_pointer_type) .byte 0x8 # DW_AT_byte_size - .long 0xf1 # DW_AT_type + .long 0x13d # DW_AT_type .uleb128 0xd # (DIE (0x107) DW_TAG_subprogram) # DW_AT_external .ascii "f\0" # DW_AT_name --/9DWx/yDrRhgMJTb Content-Type: text/plain; charset=us-ascii Content-Description: Effect of the DWARF fix Content-Disposition: inline; filename="matrix2.wi.diff" Content-length: 1488 <2>: Abbrev Number: 7 (DW_TAG_formal_parameter) DW_AT_name : m DW_AT_decl_file : 1 DW_AT_decl_line : 7 DW_AT_type : <0x101> DW_AT_location : 2 byte block: 91 58 (DW_OP_fbreg: -40) <1>: Abbrev Number: 10 (DW_TAG_array_type) DW_AT_type : <0x34> DW_AT_sibling : <0x101> <2>: Abbrev Number: 11 (DW_TAG_subrange_type) DW_AT_type : <0x65> DW_AT_upper_bound : 16 <2><100>: Abbrev Number: 0 <1><101>: Abbrev Number: 12 (DW_TAG_pointer_type) <102> DW_AT_byte_size : 8 - <103> DW_AT_type : <0xf1> + <103> DW_AT_type : <0x13d> <1><107>: Abbrev Number: 13 (DW_TAG_subprogram) <2><12f>: Abbrev Number: 8 (DW_TAG_variable) <130> DW_AT_name : m <132> DW_AT_decl_file : 1 <133> DW_AT_decl_line : 18 <134> DW_AT_type : <0x13d> <138> DW_AT_location : 3 byte block: 91 e0 76 (DW_OP_fbreg: -1184) <2><13c>: Abbrev Number: 0 <1><13d>: Abbrev Number: 10 (DW_TAG_array_type) <13e> DW_AT_type : <0x34> <142> DW_AT_sibling : <0x153> <2><146>: Abbrev Number: 11 (DW_TAG_subrange_type) <147> DW_AT_type : <0x65> <14b> DW_AT_upper_bound : 16 <2><14c>: Abbrev Number: 11 (DW_TAG_subrange_type) <14d> DW_AT_type : <0x65> <151> DW_AT_upper_bound : 16 <2><152>: Abbrev Number: 0 --/9DWx/yDrRhgMJTb--