public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] libstdc++: Add pretty printer for std::span
@ 2022-04-04 10:52 Philipp Fent
  2022-04-04 11:39 ` Jonathan Wakely
  2022-04-14 15:49 ` Jonathan Wakely
  0 siblings, 2 replies; 7+ messages in thread
From: Philipp Fent @ 2022-04-04 10:52 UTC (permalink / raw)
  To: libstdc++, gcc-patches; +Cc: Philipp Fent

This improves the debug output for C++20 spans.
Before:
{static extent = 18446744073709551615, _M_ptr = 0x7fffffffb9a8,
_M_extent = {_M_extent_value = 2}}
Now with StdSpanPrinter:
std::span of length 2 = {1, 2}
---
 libstdc++-v3/python/libstdcxx/v6/printers.py  | 38 +++++++++++++++++++
 .../libstdc++-prettyprinters/cxx20.cc         | 11 ++++++
 2 files changed, 49 insertions(+)

diff --git a/libstdc++-v3/python/libstdcxx/v6/printers.py b/libstdc++-v3/python/libstdcxx/v6/printers.py
index f7a7f9961..6d8b765f2 100644
--- a/libstdc++-v3/python/libstdcxx/v6/printers.py
+++ b/libstdc++-v3/python/libstdcxx/v6/printers.py
@@ -1654,6 +1654,43 @@ class StdRegexStatePrinter:
             s = "{}, {}={}".format(s, v, self.val['_M_' + v])
         return "{%s}" % (s)
 
+class StdSpanPrinter:
+    "Print a std::span"
+
+    class _iterator(Iterator):
+        def __init__(self, begin, size):
+            self.count = 0
+            self.begin = begin
+            self.size = size
+
+        def __iter__ (self):
+            return self
+
+        def __next__ (self):
+            if self.count == self.size:
+                raise StopIteration
+
+            count = self.count
+            self.count = self.count + 1
+            return '[%d]' % count, (self.begin + count).dereference()
+
+    def __init__(self, typename, val):
+        self.typename = typename
+        self.val = val
+        if val.type.template_argument(1) == gdb.parse_and_eval('static_cast<std::size_t>(-1)'):
+            self.size = val['_M_extent']['_M_extent_value']
+        else:
+            self.size = val.type.template_argument(1)
+
+    def to_string(self):
+        return '%s of length %d' % (self.typename, self.size)
+
+    def children(self):
+        return self._iterator(self.val['_M_ptr'], self.size)
+
+    def display_hint(self):
+        return 'array'
+
 # A "regular expression" printer which conforms to the
 # "SubPrettyPrinter" protocol from gdb.printing.
 class RxPrinter(object):
@@ -2170,6 +2207,7 @@ def build_libstdcxx_dictionary ():
     libstdcxx_printer.add_version('std::', 'partial_ordering', StdCmpCatPrinter)
     libstdcxx_printer.add_version('std::', 'weak_ordering', StdCmpCatPrinter)
     libstdcxx_printer.add_version('std::', 'strong_ordering', StdCmpCatPrinter)
+    libstdcxx_printer.add_version('std::', 'span', StdSpanPrinter)
 
     # Extensions.
     libstdcxx_printer.add_version('__gnu_cxx::', 'slist', StdSlistPrinter)
diff --git a/libstdc++-v3/testsuite/libstdc++-prettyprinters/cxx20.cc b/libstdc++-v3/testsuite/libstdc++-prettyprinters/cxx20.cc
index b0de25c27..76023df93 100644
--- a/libstdc++-v3/testsuite/libstdc++-prettyprinters/cxx20.cc
+++ b/libstdc++-v3/testsuite/libstdc++-prettyprinters/cxx20.cc
@@ -18,8 +18,10 @@
 // with this library; see the file COPYING3.  If not see
 // <http://www.gnu.org/licenses/>.
 
+#include <array>
 #include <compare>
 #include <iostream>
+#include <span>
 
 struct X
 {
@@ -54,6 +56,15 @@ main()
   auto c10 = 0.0 <=> __builtin_nan("");
 // { dg-final { note-test c10 "std::partial_ordering::unordered" } }
 
+  auto il = {1, 2};
+  auto s1 = std::span(il);
+  static_assert(s1.extent == std::size_t(-1));
+// { dg-final { note-test s1 {std::span of length 2 = {1, 2}} } }
+  auto a = std::array{3, 4};
+  auto s2 = std::span(a);
+  static_assert(s2.extent == std::size_t(2));
+// { dg-final { note-test s2 {std::span of length 2 = {3, 4}} } }
+
   std::cout << "\n";
   return 0;			// Mark SPOT
 }
-- 
2.35.1


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

* Re: [PATCH] libstdc++: Add pretty printer for std::span
  2022-04-04 10:52 [PATCH] libstdc++: Add pretty printer for std::span Philipp Fent
@ 2022-04-04 11:39 ` Jonathan Wakely
  2022-04-19  9:34   ` Philipp Fent
  2022-04-14 15:49 ` Jonathan Wakely
  1 sibling, 1 reply; 7+ messages in thread
From: Jonathan Wakely @ 2022-04-04 11:39 UTC (permalink / raw)
  To: Philipp Fent; +Cc: libstdc++, gcc-patches

On Mon, 4 Apr 2022 at 11:54, Philipp Fent via Libstdc++
<libstdc++@gcc.gnu.org> wrote:
>
> This improves the debug output for C++20 spans.
> Before:
> {static extent = 18446744073709551615, _M_ptr = 0x7fffffffb9a8,
> _M_extent = {_M_extent_value = 2}}
> Now with StdSpanPrinter:
> std::span of length 2 = {1, 2}

Nice, thanks. I'll get this committed in time for GCC 12 (and backport
it to release branches too).


> ---
>  libstdc++-v3/python/libstdcxx/v6/printers.py  | 38 +++++++++++++++++++
>  .../libstdc++-prettyprinters/cxx20.cc         | 11 ++++++
>  2 files changed, 49 insertions(+)
>
> diff --git a/libstdc++-v3/python/libstdcxx/v6/printers.py b/libstdc++-v3/python/libstdcxx/v6/printers.py
> index f7a7f9961..6d8b765f2 100644
> --- a/libstdc++-v3/python/libstdcxx/v6/printers.py
> +++ b/libstdc++-v3/python/libstdcxx/v6/printers.py
> @@ -1654,6 +1654,43 @@ class StdRegexStatePrinter:
>              s = "{}, {}={}".format(s, v, self.val['_M_' + v])
>          return "{%s}" % (s)
>
> +class StdSpanPrinter:
> +    "Print a std::span"
> +
> +    class _iterator(Iterator):
> +        def __init__(self, begin, size):
> +            self.count = 0
> +            self.begin = begin
> +            self.size = size
> +
> +        def __iter__ (self):
> +            return self
> +
> +        def __next__ (self):
> +            if self.count == self.size:
> +                raise StopIteration
> +
> +            count = self.count
> +            self.count = self.count + 1
> +            return '[%d]' % count, (self.begin + count).dereference()
> +
> +    def __init__(self, typename, val):
> +        self.typename = typename
> +        self.val = val
> +        if val.type.template_argument(1) == gdb.parse_and_eval('static_cast<std::size_t>(-1)'):
> +            self.size = val['_M_extent']['_M_extent_value']
> +        else:
> +            self.size = val.type.template_argument(1)
> +
> +    def to_string(self):
> +        return '%s of length %d' % (self.typename, self.size)
> +
> +    def children(self):
> +        return self._iterator(self.val['_M_ptr'], self.size)
> +
> +    def display_hint(self):
> +        return 'array'
> +
>  # A "regular expression" printer which conforms to the
>  # "SubPrettyPrinter" protocol from gdb.printing.
>  class RxPrinter(object):
> @@ -2170,6 +2207,7 @@ def build_libstdcxx_dictionary ():
>      libstdcxx_printer.add_version('std::', 'partial_ordering', StdCmpCatPrinter)
>      libstdcxx_printer.add_version('std::', 'weak_ordering', StdCmpCatPrinter)
>      libstdcxx_printer.add_version('std::', 'strong_ordering', StdCmpCatPrinter)
> +    libstdcxx_printer.add_version('std::', 'span', StdSpanPrinter)
>
>      # Extensions.
>      libstdcxx_printer.add_version('__gnu_cxx::', 'slist', StdSlistPrinter)
> diff --git a/libstdc++-v3/testsuite/libstdc++-prettyprinters/cxx20.cc b/libstdc++-v3/testsuite/libstdc++-prettyprinters/cxx20.cc
> index b0de25c27..76023df93 100644
> --- a/libstdc++-v3/testsuite/libstdc++-prettyprinters/cxx20.cc
> +++ b/libstdc++-v3/testsuite/libstdc++-prettyprinters/cxx20.cc
> @@ -18,8 +18,10 @@
>  // with this library; see the file COPYING3.  If not see
>  // <http://www.gnu.org/licenses/>.
>
> +#include <array>
>  #include <compare>
>  #include <iostream>
> +#include <span>
>
>  struct X
>  {
> @@ -54,6 +56,15 @@ main()
>    auto c10 = 0.0 <=> __builtin_nan("");
>  // { dg-final { note-test c10 "std::partial_ordering::unordered" } }
>
> +  auto il = {1, 2};
> +  auto s1 = std::span(il);
> +  static_assert(s1.extent == std::size_t(-1));
> +// { dg-final { note-test s1 {std::span of length 2 = {1, 2}} } }
> +  auto a = std::array{3, 4};
> +  auto s2 = std::span(a);
> +  static_assert(s2.extent == std::size_t(2));
> +// { dg-final { note-test s2 {std::span of length 2 = {3, 4}} } }
> +
>    std::cout << "\n";
>    return 0;                    // Mark SPOT
>  }
> --
> 2.35.1
>

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

* Re: [PATCH] libstdc++: Add pretty printer for std::span
  2022-04-04 10:52 [PATCH] libstdc++: Add pretty printer for std::span Philipp Fent
  2022-04-04 11:39 ` Jonathan Wakely
@ 2022-04-14 15:49 ` Jonathan Wakely
  1 sibling, 0 replies; 7+ messages in thread
From: Jonathan Wakely @ 2022-04-14 15:49 UTC (permalink / raw)
  To: Philipp Fent; +Cc: libstdc++, gcc Patches

On Mon, 4 Apr 2022 at 11:54, Philipp Fent via Libstdc++
<libstdc++@gcc.gnu.org> wrote:
>
> This improves the debug output for C++20 spans.
> Before:
> {static extent = 18446744073709551615, _M_ptr = 0x7fffffffb9a8,
> _M_extent = {_M_extent_value = 2}}
> Now with StdSpanPrinter:
> std::span of length 2 = {1, 2}


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

* Re: [PATCH] libstdc++: Add pretty printer for std::span
  2022-04-04 11:39 ` Jonathan Wakely
@ 2022-04-19  9:34   ` Philipp Fent
  2022-04-19 10:28     ` Jonathan Wakely
  0 siblings, 1 reply; 7+ messages in thread
From: Philipp Fent @ 2022-04-19  9:34 UTC (permalink / raw)
  To: Jonathan Wakely; +Cc: libstdc++, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 389 bytes --]

On 04.04.22 13:39, Jonathan Wakely wrote:
> Nice, thanks. I'll get this committed in time for GCC 12 (and backport
> it to release branches too).

I've attached a rebased patch for trunk and tested it on x86_64-linux.
I also backported it for the release branches, gcc-11 tests also pass, 
on gcc-10 the prettyprinters testsuite reports "unsupported", and gcc-9 
didn't have std::span yet.

[-- Attachment #2: gcc-10-libstdc-Add-pretty-printer-for-std-span.patch --]
[-- Type: text/x-patch, Size: 3705 bytes --]

From 0f4ae81980ea1181aca4deca0508628f9f30e72b Mon Sep 17 00:00:00 2001
From: Philipp Fent <fent@in.tum.de>
Date: Mon, 4 Apr 2022 12:52:57 +0200
Subject: [PATCH] libstdc++: Add pretty printer for std::span

This improves the debug output for C++20 spans.
Before:
{static extent = 18446744073709551615, _M_ptr = 0x7fffffffb9a8,
_M_extent = {_M_extent_value = 2}}
Now with StdSpanPrinter:
std::span of length 2 = {1, 2}
---
 libstdc++-v3/python/libstdcxx/v6/printers.py  | 38 +++++++++++++++++++
 .../libstdc++-prettyprinters/cxx20.cc         | 11 ++++++
 2 files changed, 49 insertions(+)

diff --git a/libstdc++-v3/python/libstdcxx/v6/printers.py b/libstdc++-v3/python/libstdcxx/v6/printers.py
index 74c629a710c..790d83fecff 100644
--- a/libstdc++-v3/python/libstdcxx/v6/printers.py
+++ b/libstdc++-v3/python/libstdcxx/v6/printers.py
@@ -1535,6 +1535,43 @@ class StdErrorCodePrinter:
                 pass
         return '%s = {"%s": %s}' % (self.typename, category, strval)
 
+class StdSpanPrinter:
+    "Print a std::span"
+
+    class _iterator(Iterator):
+        def __init__(self, begin, size):
+            self.count = 0
+            self.begin = begin
+            self.size = size
+
+        def __iter__ (self):
+            return self
+
+        def __next__ (self):
+            if self.count == self.size:
+                raise StopIteration
+
+            count = self.count
+            self.count = self.count + 1
+            return '[%d]' % count, (self.begin + count).dereference()
+
+    def __init__(self, typename, val):
+        self.typename = typename
+        self.val = val
+        if val.type.template_argument(1) == gdb.parse_and_eval('static_cast<std::size_t>(-1)'):
+            self.size = val['_M_extent']['_M_extent_value']
+        else:
+            self.size = val.type.template_argument(1)
+
+    def to_string(self):
+        return '%s of length %d' % (self.typename, self.size)
+
+    def children(self):
+        return self._iterator(self.val['_M_ptr'], self.size)
+
+    def display_hint(self):
+        return 'array'
+
 # A "regular expression" printer which conforms to the
 # "SubPrettyPrinter" protocol from gdb.printing.
 class RxPrinter(object):
@@ -2043,6 +2080,7 @@ def build_libstdcxx_dictionary ():
     libstdcxx_printer.add_version('std::', 'partial_ordering', StdCmpCatPrinter)
     libstdcxx_printer.add_version('std::', 'weak_ordering', StdCmpCatPrinter)
     libstdcxx_printer.add_version('std::', 'strong_ordering', StdCmpCatPrinter)
+    libstdcxx_printer.add_version('std::', 'span', StdSpanPrinter)
 
     # Extensions.
     libstdcxx_printer.add_version('__gnu_cxx::', 'slist', StdSlistPrinter)
diff --git a/libstdc++-v3/testsuite/libstdc++-prettyprinters/cxx20.cc b/libstdc++-v3/testsuite/libstdc++-prettyprinters/cxx20.cc
index 9a868c4baf7..0887f1868f2 100644
--- a/libstdc++-v3/testsuite/libstdc++-prettyprinters/cxx20.cc
+++ b/libstdc++-v3/testsuite/libstdc++-prettyprinters/cxx20.cc
@@ -18,8 +18,10 @@
 // with this library; see the file COPYING3.  If not see
 // <http://www.gnu.org/licenses/>.
 
+#include <array>
 #include <compare>
 #include <iostream>
+#include <span>
 
 struct X
 {
@@ -54,6 +56,15 @@ main()
   auto c10 = 0.0 <=> __builtin_nan("");
 // { dg-final { note-test c10 "std::partial_ordering::unordered" } }
 
+  auto il = {1, 2};
+  auto s1 = std::span(il);
+  static_assert(s1.extent == std::size_t(-1));
+// { dg-final { note-test s1 {std::span of length 2 = {1, 2}} } }
+  auto a = std::array{3, 4};
+  auto s2 = std::span(a);
+  static_assert(s2.extent == std::size_t(2));
+// { dg-final { note-test s2 {std::span of length 2 = {3, 4}} } }
+
   std::cout << "\n";
   return 0;			// Mark SPOT
 }
-- 
2.35.3


[-- Attachment #3: trunk-libstdc-Add-pretty-printer-for-std-span.patch --]
[-- Type: text/x-patch, Size: 3706 bytes --]

From c4331b7532dc2825429e82e46fda1a04dd943bd4 Mon Sep 17 00:00:00 2001
From: Philipp Fent <fent@in.tum.de>
Date: Mon, 4 Apr 2022 12:52:57 +0200
Subject: [PATCH] libstdc++: Add pretty printer for std::span

This improves the debug output for C++20 spans.
Before:
{static extent = 18446744073709551615, _M_ptr = 0x7fffffffb9a8,
_M_extent = {_M_extent_value = 2}}
Now with StdSpanPrinter:
std::span of length 2 = {1, 2}
---
 libstdc++-v3/python/libstdcxx/v6/printers.py  | 38 +++++++++++++++++++
 .../libstdc++-prettyprinters/cxx20.cc         | 11 ++++++
 2 files changed, 49 insertions(+)

diff --git a/libstdc++-v3/python/libstdcxx/v6/printers.py b/libstdc++-v3/python/libstdcxx/v6/printers.py
index f7a7f9961a7..6d8b765f2da 100644
--- a/libstdc++-v3/python/libstdcxx/v6/printers.py
+++ b/libstdc++-v3/python/libstdcxx/v6/printers.py
@@ -1654,6 +1654,43 @@ class StdRegexStatePrinter:
             s = "{}, {}={}".format(s, v, self.val['_M_' + v])
         return "{%s}" % (s)
 
+class StdSpanPrinter:
+    "Print a std::span"
+
+    class _iterator(Iterator):
+        def __init__(self, begin, size):
+            self.count = 0
+            self.begin = begin
+            self.size = size
+
+        def __iter__ (self):
+            return self
+
+        def __next__ (self):
+            if self.count == self.size:
+                raise StopIteration
+
+            count = self.count
+            self.count = self.count + 1
+            return '[%d]' % count, (self.begin + count).dereference()
+
+    def __init__(self, typename, val):
+        self.typename = typename
+        self.val = val
+        if val.type.template_argument(1) == gdb.parse_and_eval('static_cast<std::size_t>(-1)'):
+            self.size = val['_M_extent']['_M_extent_value']
+        else:
+            self.size = val.type.template_argument(1)
+
+    def to_string(self):
+        return '%s of length %d' % (self.typename, self.size)
+
+    def children(self):
+        return self._iterator(self.val['_M_ptr'], self.size)
+
+    def display_hint(self):
+        return 'array'
+
 # A "regular expression" printer which conforms to the
 # "SubPrettyPrinter" protocol from gdb.printing.
 class RxPrinter(object):
@@ -2170,6 +2207,7 @@ def build_libstdcxx_dictionary ():
     libstdcxx_printer.add_version('std::', 'partial_ordering', StdCmpCatPrinter)
     libstdcxx_printer.add_version('std::', 'weak_ordering', StdCmpCatPrinter)
     libstdcxx_printer.add_version('std::', 'strong_ordering', StdCmpCatPrinter)
+    libstdcxx_printer.add_version('std::', 'span', StdSpanPrinter)
 
     # Extensions.
     libstdcxx_printer.add_version('__gnu_cxx::', 'slist', StdSlistPrinter)
diff --git a/libstdc++-v3/testsuite/libstdc++-prettyprinters/cxx20.cc b/libstdc++-v3/testsuite/libstdc++-prettyprinters/cxx20.cc
index b0de25c27ec..76023df93fa 100644
--- a/libstdc++-v3/testsuite/libstdc++-prettyprinters/cxx20.cc
+++ b/libstdc++-v3/testsuite/libstdc++-prettyprinters/cxx20.cc
@@ -18,8 +18,10 @@
 // with this library; see the file COPYING3.  If not see
 // <http://www.gnu.org/licenses/>.
 
+#include <array>
 #include <compare>
 #include <iostream>
+#include <span>
 
 struct X
 {
@@ -54,6 +56,15 @@ main()
   auto c10 = 0.0 <=> __builtin_nan("");
 // { dg-final { note-test c10 "std::partial_ordering::unordered" } }
 
+  auto il = {1, 2};
+  auto s1 = std::span(il);
+  static_assert(s1.extent == std::size_t(-1));
+// { dg-final { note-test s1 {std::span of length 2 = {1, 2}} } }
+  auto a = std::array{3, 4};
+  auto s2 = std::span(a);
+  static_assert(s2.extent == std::size_t(2));
+// { dg-final { note-test s2 {std::span of length 2 = {3, 4}} } }
+
   std::cout << "\n";
   return 0;			// Mark SPOT
 }
-- 
2.35.3


[-- Attachment #4: gcc-11-libstdc-Add-pretty-printer-for-std-span.patch --]
[-- Type: text/x-patch, Size: 3680 bytes --]

From 46f06331e14922a8d704b38a47e8b82e2a2dc8c5 Mon Sep 17 00:00:00 2001
From: Philipp Fent <fent@in.tum.de>
Date: Mon, 4 Apr 2022 12:52:57 +0200
Subject: [PATCH] libstdc++: Add pretty printer for std::span

This improves the debug output for C++20 spans.
Before:
{static extent = 18446744073709551615, _M_ptr = 0x7fffffffb9a8,
_M_extent = {_M_extent_value = 2}}
Now with StdSpanPrinter:
std::span of length 2 = {1, 2}
---
 libstdc++-v3/python/libstdcxx/v6/printers.py  | 37 +++++++++++++++++++
 .../libstdc++-prettyprinters/cxx20.cc         | 11 ++++++
 2 files changed, 48 insertions(+)

diff --git a/libstdc++-v3/python/libstdcxx/v6/printers.py b/libstdc++-v3/python/libstdcxx/v6/printers.py
index b5b523c4b5a..4ae5d8d3029 100644
--- a/libstdc++-v3/python/libstdcxx/v6/printers.py
+++ b/libstdc++-v3/python/libstdcxx/v6/printers.py
@@ -1625,6 +1625,42 @@ class StdErrorCodePrinter:
             name = alt_name
         return '%s = {%s: %s}' % (self.typename, name, strval)
 
+class StdSpanPrinter:
+    "Print a std::span"
+
+    class _iterator(Iterator):
+        def __init__(self, begin, size):
+            self.count = 0
+            self.begin = begin
+            self.size = size
+
+        def __iter__ (self):
+            return self
+
+        def __next__ (self):
+            if self.count == self.size:
+                raise StopIteration
+
+            count = self.count
+            self.count = self.count + 1
+            return '[%d]' % count, (self.begin + count).dereference()
+
+    def __init__(self, typename, val):
+        self.typename = typename
+        self.val = val
+        if val.type.template_argument(1) == gdb.parse_and_eval('static_cast<std::size_t>(-1)'):
+            self.size = val['_M_extent']['_M_extent_value']
+        else:
+            self.size = val.type.template_argument(1)
+
+    def to_string(self):
+        return '%s of length %d' % (self.typename, self.size)
+
+    def children(self):
+        return self._iterator(self.val['_M_ptr'], self.size)
+
+    def display_hint(self):
+        return 'array'
 
 # A "regular expression" printer which conforms to the
 # "SubPrettyPrinter" protocol from gdb.printing.
@@ -2138,6 +2174,7 @@ def build_libstdcxx_dictionary ():
     libstdcxx_printer.add_version('std::', 'partial_ordering', StdCmpCatPrinter)
     libstdcxx_printer.add_version('std::', 'weak_ordering', StdCmpCatPrinter)
     libstdcxx_printer.add_version('std::', 'strong_ordering', StdCmpCatPrinter)
+    libstdcxx_printer.add_version('std::', 'span', StdSpanPrinter)
 
     # Extensions.
     libstdcxx_printer.add_version('__gnu_cxx::', 'slist', StdSlistPrinter)
diff --git a/libstdc++-v3/testsuite/libstdc++-prettyprinters/cxx20.cc b/libstdc++-v3/testsuite/libstdc++-prettyprinters/cxx20.cc
index d9b47114d57..c0eded2302a 100644
--- a/libstdc++-v3/testsuite/libstdc++-prettyprinters/cxx20.cc
+++ b/libstdc++-v3/testsuite/libstdc++-prettyprinters/cxx20.cc
@@ -18,8 +18,10 @@
 // with this library; see the file COPYING3.  If not see
 // <http://www.gnu.org/licenses/>.
 
+#include <array>
 #include <compare>
 #include <iostream>
+#include <span>
 
 struct X
 {
@@ -54,6 +56,15 @@ main()
   auto c10 = 0.0 <=> __builtin_nan("");
 // { dg-final { note-test c10 "std::partial_ordering::unordered" } }
 
+  auto il = {1, 2};
+  auto s1 = std::span(il);
+  static_assert(s1.extent == std::size_t(-1));
+// { dg-final { note-test s1 {std::span of length 2 = {1, 2}} } }
+  auto a = std::array{3, 4};
+  auto s2 = std::span(a);
+  static_assert(s2.extent == std::size_t(2));
+// { dg-final { note-test s2 {std::span of length 2 = {3, 4}} } }
+
   std::cout << "\n";
   return 0;			// Mark SPOT
 }
-- 
2.35.3


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

* Re: [PATCH] libstdc++: Add pretty printer for std::span
  2022-04-19  9:34   ` Philipp Fent
@ 2022-04-19 10:28     ` Jonathan Wakely
  2022-04-19 11:32       ` Philipp Fent
  0 siblings, 1 reply; 7+ messages in thread
From: Jonathan Wakely @ 2022-04-19 10:28 UTC (permalink / raw)
  To: Philipp Fent; +Cc: libstdc++, gcc-patches

On Tue, 19 Apr 2022 at 10:34, Philipp Fent wrote:
>
> On 04.04.22 13:39, Jonathan Wakely wrote:
> > Nice, thanks. I'll get this committed in time for GCC 12 (and backport
> > it to release branches too).
>
> I've attached a rebased patch for trunk and tested it on x86_64-linux.
> I also backported it for the release branches, gcc-11 tests also pass,
> on gcc-10 the prettyprinters testsuite reports "unsupported", and gcc-9
> didn't have std::span yet.

Thanks, but we still need the DCO sign-off as I mailed about last week.

There's no need for you to provide the backported patches, I will take
care of that.

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

* Re: [PATCH] libstdc++: Add pretty printer for std::span
  2022-04-19 10:28     ` Jonathan Wakely
@ 2022-04-19 11:32       ` Philipp Fent
  2022-04-19 11:36         ` Jonathan Wakely
  0 siblings, 1 reply; 7+ messages in thread
From: Philipp Fent @ 2022-04-19 11:32 UTC (permalink / raw)
  To: Jonathan Wakely; +Cc: libstdc++, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 273 bytes --]

On 19.04.22 12:28, Jonathan Wakely wrote:
> Thanks, but we still need the DCO sign-off as I mailed about last week.

Thanks for the clarification, your last mail didn't appear to have 
content, so I might have missed that part. I've now added my DCO sign-off.

Best
Philipp

[-- Attachment #2: libstdc-Add-pretty-printer-for-std-span.patch --]
[-- Type: text/x-patch, Size: 3752 bytes --]

From 64b6779c2694f57981e15b9c1dfa59b192e99a16 Mon Sep 17 00:00:00 2001
From: Philipp Fent <fent@in.tum.de>
Date: Mon, 4 Apr 2022 12:52:57 +0200
Subject: [PATCH] libstdc++: Add pretty printer for std::span

This improves the debug output for C++20 spans.
Before:
{static extent = 18446744073709551615, _M_ptr = 0x7fffffffb9a8,
_M_extent = {_M_extent_value = 2}}
Now with StdSpanPrinter:
std::span of length 2 = {1, 2}

Signed-off-by: Philipp Fent <fent@in.tum.de>
---
 libstdc++-v3/python/libstdcxx/v6/printers.py  | 38 +++++++++++++++++++
 .../libstdc++-prettyprinters/cxx20.cc         | 11 ++++++
 2 files changed, 49 insertions(+)

diff --git a/libstdc++-v3/python/libstdcxx/v6/printers.py b/libstdc++-v3/python/libstdcxx/v6/printers.py
index f7a7f9961a7..6d8b765f2da 100644
--- a/libstdc++-v3/python/libstdcxx/v6/printers.py
+++ b/libstdc++-v3/python/libstdcxx/v6/printers.py
@@ -1654,6 +1654,43 @@ class StdRegexStatePrinter:
             s = "{}, {}={}".format(s, v, self.val['_M_' + v])
         return "{%s}" % (s)
 
+class StdSpanPrinter:
+    "Print a std::span"
+
+    class _iterator(Iterator):
+        def __init__(self, begin, size):
+            self.count = 0
+            self.begin = begin
+            self.size = size
+
+        def __iter__ (self):
+            return self
+
+        def __next__ (self):
+            if self.count == self.size:
+                raise StopIteration
+
+            count = self.count
+            self.count = self.count + 1
+            return '[%d]' % count, (self.begin + count).dereference()
+
+    def __init__(self, typename, val):
+        self.typename = typename
+        self.val = val
+        if val.type.template_argument(1) == gdb.parse_and_eval('static_cast<std::size_t>(-1)'):
+            self.size = val['_M_extent']['_M_extent_value']
+        else:
+            self.size = val.type.template_argument(1)
+
+    def to_string(self):
+        return '%s of length %d' % (self.typename, self.size)
+
+    def children(self):
+        return self._iterator(self.val['_M_ptr'], self.size)
+
+    def display_hint(self):
+        return 'array'
+
 # A "regular expression" printer which conforms to the
 # "SubPrettyPrinter" protocol from gdb.printing.
 class RxPrinter(object):
@@ -2170,6 +2207,7 @@ def build_libstdcxx_dictionary ():
     libstdcxx_printer.add_version('std::', 'partial_ordering', StdCmpCatPrinter)
     libstdcxx_printer.add_version('std::', 'weak_ordering', StdCmpCatPrinter)
     libstdcxx_printer.add_version('std::', 'strong_ordering', StdCmpCatPrinter)
+    libstdcxx_printer.add_version('std::', 'span', StdSpanPrinter)
 
     # Extensions.
     libstdcxx_printer.add_version('__gnu_cxx::', 'slist', StdSlistPrinter)
diff --git a/libstdc++-v3/testsuite/libstdc++-prettyprinters/cxx20.cc b/libstdc++-v3/testsuite/libstdc++-prettyprinters/cxx20.cc
index b0de25c27ec..76023df93fa 100644
--- a/libstdc++-v3/testsuite/libstdc++-prettyprinters/cxx20.cc
+++ b/libstdc++-v3/testsuite/libstdc++-prettyprinters/cxx20.cc
@@ -18,8 +18,10 @@
 // with this library; see the file COPYING3.  If not see
 // <http://www.gnu.org/licenses/>.
 
+#include <array>
 #include <compare>
 #include <iostream>
+#include <span>
 
 struct X
 {
@@ -54,6 +56,15 @@ main()
   auto c10 = 0.0 <=> __builtin_nan("");
 // { dg-final { note-test c10 "std::partial_ordering::unordered" } }
 
+  auto il = {1, 2};
+  auto s1 = std::span(il);
+  static_assert(s1.extent == std::size_t(-1));
+// { dg-final { note-test s1 {std::span of length 2 = {1, 2}} } }
+  auto a = std::array{3, 4};
+  auto s2 = std::span(a);
+  static_assert(s2.extent == std::size_t(2));
+// { dg-final { note-test s2 {std::span of length 2 = {3, 4}} } }
+
   std::cout << "\n";
   return 0;			// Mark SPOT
 }
-- 
2.35.3


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

* Re: [PATCH] libstdc++: Add pretty printer for std::span
  2022-04-19 11:32       ` Philipp Fent
@ 2022-04-19 11:36         ` Jonathan Wakely
  0 siblings, 0 replies; 7+ messages in thread
From: Jonathan Wakely @ 2022-04-19 11:36 UTC (permalink / raw)
  To: Philipp Fent; +Cc: Jonathan Wakely, libstdc++, gcc-patches

On Tue, 19 Apr 2022 at 12:33, Philipp Fent via Libstdc++
<libstdc++@gcc.gnu.org> wrote:
>
> On 19.04.22 12:28, Jonathan Wakely wrote:
> > Thanks, but we still need the DCO sign-off as I mailed about last week.
>
> Thanks for the clarification, your last mail didn't appear to have
> content, so I might have missed that part. I've now added my DCO sign-off.

Huh, I see no content in my sent copy either. Weird. I distinctly
remember pasting the https://gcc.gnu.org/dco.html link into the email,
but gmail must have had other ideas. Sorry about that!

Thanks for the sign-off, I'll get this committed today.

The GCC 11 backport will have to wait a few days because the branch is
currently frozen for the 11.3 release.


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

end of thread, other threads:[~2022-04-19 11:36 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-04 10:52 [PATCH] libstdc++: Add pretty printer for std::span Philipp Fent
2022-04-04 11:39 ` Jonathan Wakely
2022-04-19  9:34   ` Philipp Fent
2022-04-19 10:28     ` Jonathan Wakely
2022-04-19 11:32       ` Philipp Fent
2022-04-19 11:36         ` Jonathan Wakely
2022-04-14 15:49 ` Jonathan Wakely

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