From: Jan Kratochvil <jan.kratochvil@redhat.com>
To: Neven Sajko <nsajko@gmail.com>
Cc: gdb@sourceware.org
Subject: Re: Printing a 2D array in a C program
Date: Fri, 04 Mar 2016 17:49:00 -0000 [thread overview]
Message-ID: <20160304174859.GA15741@host1.jankratochvil.net> (raw)
In-Reply-To: <CAL+bK4MV9ZLkon2PONYRpF0506P8zE3=Ukm0F1zpVDHd2HpAtw@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 2173 bytes --]
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}}
[-- Attachment #2: Fix of the DWARF --]
[-- Type: text/plain, Size: 403 bytes --]
--- 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
[-- Attachment #3: Effect of the DWARF fix --]
[-- Type: text/plain, Size: 1488 bytes --]
<2><ae>: Abbrev Number: 7 (DW_TAG_formal_parameter)
<af> DW_AT_name : m
<b1> DW_AT_decl_file : 1
<b2> DW_AT_decl_line : 7
<b3> DW_AT_type : <0x101>
<b7> DW_AT_location : 2 byte block: 91 58 (DW_OP_fbreg: -40)
<1><f1>: Abbrev Number: 10 (DW_TAG_array_type)
<f2> DW_AT_type : <0x34>
<f6> DW_AT_sibling : <0x101>
<2><fa>: Abbrev Number: 11 (DW_TAG_subrange_type)
<fb> DW_AT_type : <0x65>
<ff> 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
next prev parent reply other threads:[~2016-03-04 17:49 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-04 14:27 Neven Sajko
2016-03-04 14:42 ` Jan Kratochvil
2016-03-04 16:15 ` Neven Sajko
2016-03-04 17:49 ` Jan Kratochvil [this message]
2016-03-04 18:24 ` Pedro Alves
2016-03-04 18:59 ` Jan Kratochvil
2016-03-04 19:16 ` Pedro Alves
2016-03-04 18:34 ` Andreas Schwab
2016-03-04 21:48 ` Neven Sajko
2016-03-04 22:16 ` Andreas Schwab
2016-03-05 0:59 ` Neven Sajko
2016-03-05 8:23 ` Andreas Schwab
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160304174859.GA15741@host1.jankratochvil.net \
--to=jan.kratochvil@redhat.com \
--cc=gdb@sourceware.org \
--cc=nsajko@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox