public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug gdb/16933] New: p omits trailing 0 when printing a range of chars
@ 2014-05-12  8:00 f.heckenbach@fh-soft.de
  2014-05-12 16:29 ` [Bug gdb/16933] " schwab@linux-m68k.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: f.heckenbach@fh-soft.de @ 2014-05-12  8:00 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=16933

            Bug ID: 16933
           Summary: p omits trailing 0 when printing a range of chars
           Product: gdb
           Version: 7.7
            Status: NEW
          Severity: normal
          Priority: P2
         Component: gdb
          Assignee: unassigned at sourceware dot org
          Reporter: f.heckenbach@fh-soft.de

This bug was reported as Debian bug #666216 for gdb 7-0. According to Hector
Oron, it is still reproducable with 7.7-1.

p omits trailing 0 when printing a range of chars.
To reproduce:

# echo 'char foo[5] = { 1, 2, 0, 4, 0 };' > foo.c
# gcc -c -g foo.c
# gdb foo.o
(gdb) p foo[0]@5
$1 = "\001\002\000\004"

What I really wanted would be "{1, 2, 0, 4, 0}", like for other
integer types, since I explicitly selected a single element and gave
a range (@5), but if it must print it as a string, it should at
least print all of the bytes.

I know that's probably due to C's notorious confusion between
integers and characters, and I also know there are other ways to
dump some bytes in gdb.

But still it seems plain wrong to print 4 chars if 5 items were
explicitly requested, just because the last one happens to be 0.
Note that it's not printing a 0-terminated string either: The
embedded "\000" is printed; just one terminating 0 is omitted.

(Which gets very confusing with larger arrays, if you look for
something near the end, thinking the last one printed is the last
one requested and then go hunting your off-by-one bug, only to
realize later there wasn't any ...)

-- 
You are receiving this mail because:
You are on the CC list for the bug.


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

* [Bug gdb/16933] p omits trailing 0 when printing a range of chars
  2014-05-12  8:00 [Bug gdb/16933] New: p omits trailing 0 when printing a range of chars f.heckenbach@fh-soft.de
@ 2014-05-12 16:29 ` schwab@linux-m68k.org
  2014-05-12 16:38 ` f.heckenbach@fh-soft.de
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: schwab@linux-m68k.org @ 2014-05-12 16:29 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=16933

--- Comment #1 from Andreas Schwab <schwab@linux-m68k.org> ---
"\001\002\000\004\000" would be wrong because that has 6 elements and implies
that there is another zero following.

-- 
You are receiving this mail because:
You are on the CC list for the bug.


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

* [Bug gdb/16933] p omits trailing 0 when printing a range of chars
  2014-05-12  8:00 [Bug gdb/16933] New: p omits trailing 0 when printing a range of chars f.heckenbach@fh-soft.de
  2014-05-12 16:29 ` [Bug gdb/16933] " schwab@linux-m68k.org
@ 2014-05-12 16:38 ` f.heckenbach@fh-soft.de
  2024-01-01 23:43 ` ssbssa at sourceware dot org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: f.heckenbach@fh-soft.de @ 2014-05-12 16:38 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=16933

--- Comment #2 from Frank Heckenbach <f.heckenbach@fh-soft.de> ---
> https://sourceware.org/bugzilla/show_bug.cgi?id=16933
> 
> --- Comment #1 from Andreas Schwab <schwab@linux-m68k.org> ---
> "\001\002\000\004\000" would be wrong because that has 6 elements and implies
> that there is another zero following.

I see. But for the same reason this is then also wrong:

# echo 'char foo[5] = { 1, 2, 0, 4 };' > foo.c
# gcc -c -g foo.c
# gdb foo.o
(gdb) p foo[0]@4
$1 = "\001\002\000\004"

So AIUI gdb must not print a range of chars as a string at all and
should really print "{1, 2, 0, 4, 0}" or "{1, 2, 0, 4}", resp., as
I'd actually prefer anyway.

-- 
You are receiving this mail because:
You are on the CC list for the bug.


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

* [Bug gdb/16933] p omits trailing 0 when printing a range of chars
  2014-05-12  8:00 [Bug gdb/16933] New: p omits trailing 0 when printing a range of chars f.heckenbach@fh-soft.de
  2014-05-12 16:29 ` [Bug gdb/16933] " schwab@linux-m68k.org
  2014-05-12 16:38 ` f.heckenbach@fh-soft.de
@ 2024-01-01 23:43 ` ssbssa at sourceware dot org
  2024-01-10 16:26 ` ssbssa at sourceware dot org
  2024-01-10 16:28 ` ssbssa at sourceware dot org
  4 siblings, 0 replies; 6+ messages in thread
From: ssbssa at sourceware dot org @ 2024-01-01 23:43 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=16933

Hannes Domani <ssbssa at sourceware dot org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ssbssa at sourceware dot org

--- Comment #3 from Hannes Domani <ssbssa at sourceware dot org> ---
See also PR16020.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

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

* [Bug gdb/16933] p omits trailing 0 when printing a range of chars
  2014-05-12  8:00 [Bug gdb/16933] New: p omits trailing 0 when printing a range of chars f.heckenbach@fh-soft.de
                   ` (2 preceding siblings ...)
  2024-01-01 23:43 ` ssbssa at sourceware dot org
@ 2024-01-10 16:26 ` ssbssa at sourceware dot org
  2024-01-10 16:28 ` ssbssa at sourceware dot org
  4 siblings, 0 replies; 6+ messages in thread
From: ssbssa at sourceware dot org @ 2024-01-10 16:26 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=16933

Hannes Domani <ssbssa at sourceware dot org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dedeco.balaco at yahoo dot com

--- Comment #4 from Hannes Domani <ssbssa at sourceware dot org> ---
*** Bug 21467 has been marked as a duplicate of this bug. ***

-- 
You are receiving this mail because:
You are on the CC list for the bug.

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

* [Bug gdb/16933] p omits trailing 0 when printing a range of chars
  2014-05-12  8:00 [Bug gdb/16933] New: p omits trailing 0 when printing a range of chars f.heckenbach@fh-soft.de
                   ` (3 preceding siblings ...)
  2024-01-10 16:26 ` ssbssa at sourceware dot org
@ 2024-01-10 16:28 ` ssbssa at sourceware dot org
  4 siblings, 0 replies; 6+ messages in thread
From: ssbssa at sourceware dot org @ 2024-01-10 16:28 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=16933

--- Comment #5 from Hannes Domani <ssbssa at sourceware dot org> ---
(In reply to Hannes Domani from comment #3)
> See also PR16020.

And also PR26842.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

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

end of thread, other threads:[~2024-01-10 16:28 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-05-12  8:00 [Bug gdb/16933] New: p omits trailing 0 when printing a range of chars f.heckenbach@fh-soft.de
2014-05-12 16:29 ` [Bug gdb/16933] " schwab@linux-m68k.org
2014-05-12 16:38 ` f.heckenbach@fh-soft.de
2024-01-01 23:43 ` ssbssa at sourceware dot org
2024-01-10 16:26 ` ssbssa at sourceware dot org
2024-01-10 16:28 ` ssbssa at sourceware dot org

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