public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug python/31743] New: <repeats N times> is confusing inside a python pretty printer
@ 2024-05-16  9:16 jwakely.gcc at gmail dot com
  2024-05-16  9:21 ` [Bug python/31743] " jwakely.gcc at gmail dot com
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: jwakely.gcc at gmail dot com @ 2024-05-16  9:16 UTC (permalink / raw)
  To: gdb-prs

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

            Bug ID: 31743
           Summary: <repeats N times> is confusing inside a python pretty
                    printer
           Product: gdb
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: python
          Assignee: unassigned at sourceware dot org
          Reporter: jwakely.gcc at gmail dot com
  Target Milestone: ---

#include <vector>
int
main()
{
  std::vector<const char*> v;
  v.emplace_back("=================================== 
=============================\n");
  v.emplace_back("abcdefghijklmnopqrstuvwxyz\n");
  return 0;
}

$ gdb -q -ex start -ex "n 3" -ex "p v" -ex cont -ex q a.out
Reading symbols from a.out...
Temporary breakpoint 1 at 0x40119f: file s.cc, line 6.
Starting program: /tmp/a.out 
[Thread debugging using libthread_db enabled]                                   
Using host libthread_db library "/lib64/libthread_db.so.1".

Temporary breakpoint 1, main () at s.cc:6
6         std::vector<const char*> v;
9         return 0;
$1 = std::vector of length 2, capacity 2 = {0x402010 '=' <repeats 35 times>, " 
", '=' <repeats 29 times>, "\n", 0x402054 "abcdefghijklmnopqrstuvwxyz\n"}
Continuing.
[Inferior 1 (process 634451) exited normally]

This output is very confusing, as we have commas inserted before/after the
<repeats...> text which get confused with the commas between the vector
elements.

It's worse for a vector<string> or vector<string_view> because we don't even
get the const char* addresses like 0x402010 as delimiters between elements:

#include <vector>
#include <string_view>
int
main()
{
  std::vector<std::string_view> v;
  v.emplace_back("=================================== 
=============================\n");
  v.emplace_back("abcdefghijklmnopqrstuvwxyz\n");
  return 0;
}

$ gdb -q -ex start -ex "n 3" -ex "p v" -ex cont -ex q a.out
Reading symbols from a.out...
Temporary breakpoint 1 at 0x40119f: file s.cc, line 6.
Starting program: /tmp/a.out 
[Thread debugging using libthread_db enabled]                                   
Using host libthread_db library "/lib64/libthread_db.so.1".

Temporary breakpoint 1, main () at s.cc:6
6         std::vector<std::string_view> v;
9         return 0;
$1 = std::vector of length 2, capacity 2 = {'=' <repeats 35 times>, "  ", '='
<repeats 29 times>, "\n", "abcdefghijklmnopqrstuvwxyz\n"}
Continuing.
[Inferior 1 (process 634576) exited normally]


It takes quite a lot of effort to see that this is all part of the same v[0]
object:

'=' <repeats 35 times>, "  ", '=' <repeats 29 times>, "\n"

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

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

* [Bug python/31743] <repeats N times> is confusing inside a python pretty printer
  2024-05-16  9:16 [Bug python/31743] New: <repeats N times> is confusing inside a python pretty printer jwakely.gcc at gmail dot com
@ 2024-05-16  9:21 ` jwakely.gcc at gmail dot com
  2024-05-16  9:21 ` jwakely.gcc at gmail dot com
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: jwakely.gcc at gmail dot com @ 2024-05-16  9:21 UTC (permalink / raw)
  To: gdb-prs

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

Jonathan Wakely <jwakely.gcc at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|https://sourceware.org/bugz |
                   |illa/show_bug.cgi?id=21875  |

--- Comment #1 from Jonathan Wakely <jwakely.gcc at gmail dot com> ---
One solution would be for GDB to save the current repeats count before invoking
any pretty printer, then set it to unlimited, then restore the original count
after the printer finishes. But that would completely disable a quite useful
feature for displaying large arrays.

I think it would be better if the repeats display could be adjusted to be
unambiguous when it occurs as part of a larger data structure, e.g. maybe
without the commas between the parts:

$1 = std::vector of length 2, capacity 2 = {'=' <repeats 35 times> "  " '='
<repeats 29 times> "\n"}, "abcdefghijklmnopqrstuvwxyz\n"}

Or automatically enclosing it in braces if it's going to be abbreviated by the
repeats count:

$1 = std::vector of length 2, capacity 2 = {{'=' <repeats 35 times>, "  ", '='
<repeats 29 times>, "\n"}, "abcdefghijklmnopqrstuvwxyz\n"}

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

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

* [Bug python/31743] <repeats N times> is confusing inside a python pretty printer
  2024-05-16  9:16 [Bug python/31743] New: <repeats N times> is confusing inside a python pretty printer jwakely.gcc at gmail dot com
  2024-05-16  9:21 ` [Bug python/31743] " jwakely.gcc at gmail dot com
@ 2024-05-16  9:21 ` jwakely.gcc at gmail dot com
  2024-05-16  9:33 ` jwakely.gcc at gmail dot com
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: jwakely.gcc at gmail dot com @ 2024-05-16  9:21 UTC (permalink / raw)
  To: gdb-prs

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

Jonathan Wakely <jwakely.gcc at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://sourceware.org/bugz
                   |                            |illa/show_bug.cgi?id=21875

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

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

* [Bug python/31743] <repeats N times> is confusing inside a python pretty printer
  2024-05-16  9:16 [Bug python/31743] New: <repeats N times> is confusing inside a python pretty printer jwakely.gcc at gmail dot com
  2024-05-16  9:21 ` [Bug python/31743] " jwakely.gcc at gmail dot com
  2024-05-16  9:21 ` jwakely.gcc at gmail dot com
@ 2024-05-16  9:33 ` jwakely.gcc at gmail dot com
  2024-05-16  9:34 ` [Bug python/31743] Strings containing <repeats N times> are " jwakely.gcc at gmail dot com
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: jwakely.gcc at gmail dot com @ 2024-05-16  9:33 UTC (permalink / raw)
  To: gdb-prs

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

--- Comment #2 from Jonathan Wakely <jwakely.gcc at gmail dot com> ---
I think this is only a problem when the repeats feature is used for strings. If
I try a similar example with std::vector<std::array<int, 20>> it looks fine:

$1 = std::vector of length 2, capacity 2 = {{_M_elems = {7, 8, 9, 0 <repeats 17
times>}}, {_M_elems = {0, 1, 2, 0 <repeats 17 times>}}}


I think the difference is that for an arbitrary array the adjacent elements are
never coalesced into a double-quoted string, they're always shown one-by-one
and so the <repeats...> part works well.

For the string case we get a mix of quoted strings and single chars:

"quoted string", 'c' <repeats N times>, "another quoted string"


Given that adjacent strings are concatenated in C and C++, i.e., "foo" "bar"
means "foobar", maybe we could make the display more consistent with that:

"quoted string" <'c' repeats N times> "another quoted string"

This doesn't put commas between the quoted parts, and doesn't switch between
the two forms "s" and 'c' so is a bit closer to being a valid string literal in
C.

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

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

* [Bug python/31743] Strings containing <repeats N times> are confusing inside a python pretty printer
  2024-05-16  9:16 [Bug python/31743] New: <repeats N times> is confusing inside a python pretty printer jwakely.gcc at gmail dot com
                   ` (2 preceding siblings ...)
  2024-05-16  9:33 ` jwakely.gcc at gmail dot com
@ 2024-05-16  9:34 ` jwakely.gcc at gmail dot com
  2024-05-16  9:37 ` drepper.fsp at gmail dot com
  2024-05-16 14:25 ` ssbssa at sourceware dot org
  5 siblings, 0 replies; 7+ messages in thread
From: jwakely.gcc at gmail dot com @ 2024-05-16  9:34 UTC (permalink / raw)
  To: gdb-prs

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

Jonathan Wakely <jwakely.gcc at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|<repeats N times> is        |Strings containing <repeats
                   |confusing inside a python   |N times> are confusing
                   |pretty printer              |inside a python pretty
                   |                            |printer

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

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

* [Bug python/31743] Strings containing <repeats N times> are confusing inside a python pretty printer
  2024-05-16  9:16 [Bug python/31743] New: <repeats N times> is confusing inside a python pretty printer jwakely.gcc at gmail dot com
                   ` (3 preceding siblings ...)
  2024-05-16  9:34 ` [Bug python/31743] Strings containing <repeats N times> are " jwakely.gcc at gmail dot com
@ 2024-05-16  9:37 ` drepper.fsp at gmail dot com
  2024-05-16 14:25 ` ssbssa at sourceware dot org
  5 siblings, 0 replies; 7+ messages in thread
From: drepper.fsp at gmail dot com @ 2024-05-16  9:37 UTC (permalink / raw)
  To: gdb-prs

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

Ulrich Drepper <drepper.fsp at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |drepper.fsp at gmail dot com

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

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

* [Bug python/31743] Strings containing <repeats N times> are confusing inside a python pretty printer
  2024-05-16  9:16 [Bug python/31743] New: <repeats N times> is confusing inside a python pretty printer jwakely.gcc at gmail dot com
                   ` (4 preceding siblings ...)
  2024-05-16  9:37 ` drepper.fsp at gmail dot com
@ 2024-05-16 14:25 ` ssbssa at sourceware dot org
  5 siblings, 0 replies; 7+ messages in thread
From: ssbssa at sourceware dot org @ 2024-05-16 14:25 UTC (permalink / raw)
  To: gdb-prs

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

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> ---
Not a real solution, but `set print array on` does make the output more
readable:

(gdb) p -array -- v_cstr
$3 = std::vector of length 2, capacity 2 = {
  0x13f512000 '=' <repeats 35 times>, "  ", '=' <repeats 29 times>, "\n",
  0x13f512044 "abcdefghijklmnopqrstuvwxyz\n"
}
(gdb) p -array -- v_sv
$4 = std::vector of length 2, capacity 2 = {
  '=' <repeats 35 times>, "  ", '=' <repeats 29 times>, "\n",
  "abcdefghijklmnopqrstuvwxyz\n"
}

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

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

end of thread, other threads:[~2024-05-16 14:25 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-16  9:16 [Bug python/31743] New: <repeats N times> is confusing inside a python pretty printer jwakely.gcc at gmail dot com
2024-05-16  9:21 ` [Bug python/31743] " jwakely.gcc at gmail dot com
2024-05-16  9:21 ` jwakely.gcc at gmail dot com
2024-05-16  9:33 ` jwakely.gcc at gmail dot com
2024-05-16  9:34 ` [Bug python/31743] Strings containing <repeats N times> are " jwakely.gcc at gmail dot com
2024-05-16  9:37 ` drepper.fsp at gmail dot com
2024-05-16 14:25 ` 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).