public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug gdb/11076] New: Printing character arrays
@ 2009-12-10 10:39 sabrown256 at gmail dot com
  2009-12-10 17:13 ` [Bug gdb/11076] " ppluzhnikov at google dot com
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: sabrown256 at gmail dot com @ 2009-12-10 10:39 UTC (permalink / raw)
  To: gdb-prs

GDB 7.0 has problem printing character arrays.

If you have declaration in source such as:
char a[100];

print a -> ""
print &a[0] -> "foo bar baz"

On the other hand if you have:
char *b;

print b -> "foo bar baz"

Character arrays in structs have the same problem.

-- 
           Summary: Printing character arrays
           Product: gdb
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: gdb
        AssignedTo: unassigned at sourceware dot org
        ReportedBy: sabrown256 at gmail dot com
                CC: gdb-prs at sourceware dot org


http://sourceware.org/bugzilla/show_bug.cgi?id=11076

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug gdb/11076] Printing character arrays
  2009-12-10 10:39 [Bug gdb/11076] New: Printing character arrays sabrown256 at gmail dot com
@ 2009-12-10 17:13 ` ppluzhnikov at google dot com
  2009-12-10 19:13 ` sabrown256 at gmail dot com
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: ppluzhnikov at google dot com @ 2009-12-10 17:13 UTC (permalink / raw)
  To: gdb-prs


------- 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).

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |WAITING


http://sourceware.org/bugzilla/show_bug.cgi?id=11076

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug gdb/11076] Printing character arrays
  2009-12-10 10:39 [Bug gdb/11076] New: Printing character arrays sabrown256 at gmail dot com
  2009-12-10 17:13 ` [Bug gdb/11076] " ppluzhnikov at google dot com
@ 2009-12-10 19:13 ` sabrown256 at gmail dot com
  2009-12-10 19:15 ` sabrown256 at gmail dot com
  2009-12-11  4:51 ` ppluzhnikov at google dot com
  3 siblings, 0 replies; 5+ messages in thread
From: sabrown256 at gmail dot com @ 2009-12-10 19:13 UTC (permalink / raw)
  To: gdb-prs


------- Additional Comments From sabrown256 at gmail dot com  2009-12-10 19:13 -------
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




-- 


http://sourceware.org/bugzilla/show_bug.cgi?id=11076

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug gdb/11076] Printing character arrays
  2009-12-10 10:39 [Bug gdb/11076] New: Printing character arrays sabrown256 at gmail dot com
  2009-12-10 17:13 ` [Bug gdb/11076] " ppluzhnikov at google dot com
  2009-12-10 19:13 ` sabrown256 at gmail dot com
@ 2009-12-10 19:15 ` sabrown256 at gmail dot com
  2009-12-11  4:51 ` ppluzhnikov at google dot com
  3 siblings, 0 replies; 5+ messages in thread
From: sabrown256 at gmail dot com @ 2009-12-10 19:15 UTC (permalink / raw)
  To: gdb-prs


------- Additional Comments From sabrown256 at gmail dot com  2009-12-10 19:15 -------
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



-- 


http://sourceware.org/bugzilla/show_bug.cgi?id=11076

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug gdb/11076] Printing character arrays
  2009-12-10 10:39 [Bug gdb/11076] New: Printing character arrays sabrown256 at gmail dot com
                   ` (2 preceding siblings ...)
  2009-12-10 19:15 ` sabrown256 at gmail dot com
@ 2009-12-11  4:51 ` ppluzhnikov at google dot com
  3 siblings, 0 replies; 5+ messages in thread
From: ppluzhnikov at google dot com @ 2009-12-11  4:51 UTC (permalink / raw)
  To: gdb-prs


------- Additional Comments From ppluzhnikov at google dot com  2009-12-11 04:51 -------
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.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|WAITING                     |RESOLVED
         Resolution|                            |WORKSFORME


http://sourceware.org/bugzilla/show_bug.cgi?id=11076

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2009-12-11  4:51 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-12-10 10:39 [Bug gdb/11076] New: Printing character arrays sabrown256 at gmail dot com
2009-12-10 17:13 ` [Bug gdb/11076] " ppluzhnikov at google dot com
2009-12-10 19:13 ` sabrown256 at gmail dot com
2009-12-10 19:15 ` sabrown256 at gmail dot com
2009-12-11  4:51 ` ppluzhnikov at google dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).