Summary: | Printing character arrays | ||
---|---|---|---|
Product: | gdb | Reporter: | sabrown256 |
Component: | gdb | Assignee: | Not yet assigned to anyone <unassigned> |
Status: | RESOLVED WORKSFORME | ||
Severity: | normal | CC: | gdb-prs |
Priority: | P2 | ||
Version: | unknown | ||
Target Milestone: | 7.1 | ||
Host: | Target: | ||
Build: | Last reconfirmed: |
Description
sabrown256
2009-12-10 10:39:20 UTC
This works just fine for me: int main() { char a[100] = "foo bar baz"; return 0; } gcc -g t.c -o t gdb-7.0/build/gdb/gdb ./t GNU gdb (GDB) 7.0 ... This GDB was configured as "x86_64-unknown-linux-gnu". For bug reporting instructions, please see: <http://www.gnu.org/software/gdb/bugs/>... Reading symbols from /tmp/t...done. (gdb) list 1 int main() 2 { 3 char a[100] = "foo bar baz"; 4 return 0; 5 } (gdb) break 4 Breakpoint 1 at 0x400546: file t.c, line 4. (gdb) run Breakpoint 1, main () at t.c:4 4 return 0; (gdb) print a $1 = "foo bar baz", '\000' <repeats 88 times> Please provide a complete test case, as well as complete log of your GDB session (as I have done above). Subject: Re: Printing character arrays ppluzhnikov at google dot com wrote: > ------- Additional Comments From ppluzhnikov at google dot com 2009-12-10 17:13 ------- > This works just fine for me: > > int main() > { > char a[100] = "foo bar baz"; > return 0; > } > > gcc -g t.c -o t > gdb-7.0/build/gdb/gdb ./t > GNU gdb (GDB) 7.0 > ... > This GDB was configured as "x86_64-unknown-linux-gnu". > For bug reporting instructions, please see: > <http://www.gnu.org/software/gdb/bugs/>... > Reading symbols from /tmp/t...done. > (gdb) list > 1 int main() > 2 { > 3 char a[100] = "foo bar baz"; > 4 return 0; > 5 } > (gdb) break 4 > Breakpoint 1 at 0x400546: file t.c, line 4. > (gdb) run > > Breakpoint 1, main () at t.c:4 > 4 return 0; > (gdb) print a > $1 = "foo bar baz", '\000' <repeats 88 times> > > Please provide a complete test case, as well as complete log of your GDB session > (as I have done above). > > Here is an example from a typical debug session: GNU gdb (GDB) 7.0-ubuntu Copyright (C) 2009 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "x86_64-linux-gnu". For bug reporting instructions, please see: <http://www.gnu.org/software/gdb/bugs/>... Reading symbols from /store/apps/codes/dobby/dev/lnx-2.10-o/bin/dbman...done. Breakpoint 1 at 0x40cfac: file ../../dbplace.c, line 343. ... (gdb) p data[0] $1 = {id = 1, country = "", state = '\000' <repeats 127 times>, city = "", name = "", comment = "", start = "\000\000\000\000\000\000\000\000\000", end = "\000\000\000\000\000\000\000\000\000", longitude = 0, latitude = 0, elevation = 0} (gdb) whatis data[0].country type = char [128] (gdb) p data[0].country $2 = "" (gdb) p &data[0].country[0] $3 = 0x7ffff7ee8054 "Canada" (gdb) I have been seeing this consistently across a broad range of codes. They are in development, I have bugs, I use gdb - so I cannot say there is no problem with my codes. They are mainly clean under valgrind. In any event, the debugger should not have this kind of problem. I will try your example to see if it is Ubuntu's build that is funny. Thanks for the reply. Stewart Subject: Re: Printing character arrays ppluzhnikov at google dot com wrote: > ------- Additional Comments From ppluzhnikov at google dot com 2009-12-10 17:13 ------- > This works just fine for me: > > int main() > { > char a[100] = "foo bar baz"; > return 0; > } > > gcc -g t.c -o t > gdb-7.0/build/gdb/gdb ./t > GNU gdb (GDB) 7.0 > ... > This GDB was configured as "x86_64-unknown-linux-gnu". > For bug reporting instructions, please see: > <http://www.gnu.org/software/gdb/bugs/>... > Reading symbols from /tmp/t...done. > (gdb) list > 1 int main() > 2 { > 3 char a[100] = "foo bar baz"; > 4 return 0; > 5 } > (gdb) break 4 > Breakpoint 1 at 0x400546: file t.c, line 4. > (gdb) run > > Breakpoint 1, main () at t.c:4 > 4 return 0; > (gdb) print a > $1 = "foo bar baz", '\000' <repeats 88 times> > > Please provide a complete test case, as well as complete log of your GDB session > (as I have done above). > > I ran your example and got: Current directory is /gapps/codes/dobby/db/ GNU gdb (GDB) 7.0-ubuntu Copyright (C) 2009 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "x86_64-linux-gnu". For bug reporting instructions, please see: <http://www.gnu.org/software/gdb/bugs/>... Reading symbols from /store/apps/codes/dobby/db/foo...done. Breakpoint 1 at 0x40058e: file foo.c, line 4. (gdb) r Starting program: /store/apps/codes/dobby/db/foo Breakpoint 1, main () at foo.c:4 (gdb) p a $1 = "" (gdb) p &a[0] $2 = 0x7fffffffe0b0 "foo bar baz" (gdb) I will submit this to the Ubuntu folks. Stewart The problem appears to be in either GCC or GDB as distributed by Ubuntu. Both gdb-7.0 (official) and current CVS Head work fine. |