public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
From: Philipp Fent <fent@in.tum.de>
To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org
Cc: Philipp Fent <fent@in.tum.de>
Subject: [PATCH 2/2] libstdc++: Add pretty printer for std::stringstream
Date: Sun,  4 Sep 2022 20:47:35 +0200	[thread overview]
Message-ID: <20220904184735.177348-2-fent@in.tum.de> (raw)
In-Reply-To: <20220904184735.177348-1-fent@in.tum.de>

Signed-off-by: Philipp Fent <fent@in.tum.de>
---
 libstdc++-v3/python/libstdcxx/v6/printers.py  | 37 +++++++++++++++++++
 .../libstdc++-prettyprinters/debug.cc         |  5 +++
 .../libstdc++-prettyprinters/simple.cc        |  5 +++
 .../libstdc++-prettyprinters/simple11.cc      |  5 +++
 4 files changed, 52 insertions(+)

diff --git a/libstdc++-v3/python/libstdcxx/v6/printers.py b/libstdc++-v3/python/libstdcxx/v6/printers.py
index d70c8d5d616..5083f693387 100644
--- a/libstdc++-v3/python/libstdcxx/v6/printers.py
+++ b/libstdc++-v3/python/libstdcxx/v6/printers.py
@@ -969,6 +969,39 @@ class StdStringPrinter:
     def display_hint (self):
         return 'string'
 
+class StdStringBufPrinter:
+    "Print a std::basic_stringbuf"
+
+    def __init__(self, _, val):
+        self.val = val
+
+    def to_string(self):
+        pbase = self.val['_M_out_beg']
+        pptr = self.val['_M_out_cur']
+        egptr = self.val['_M_in_end']
+        # Logic from basic_stringbuf::_M_high_mark()
+        if pptr:
+            if not egptr or pptr > egptr:
+                return pbase.string(length = pptr - pbase)
+            else:
+                return pbase.string(length = pptr - egptr)
+        return self.val['_M_string']
+
+    def display_hint(self):
+        return 'string'
+
+class StdStringStreamPrinter:
+    "Print a std::basic_stringstream"
+
+    def __init__(self, _, val):
+        self.val = val
+
+    def to_string(self):
+        return self.val['_M_stringbuf']
+
+    def display_hint(self):
+        return 'string'
+
 class Tr1HashtableIterator(Iterator):
     def __init__ (self, hashtable):
         self.buckets = hashtable['_M_buckets']
@@ -2232,6 +2265,10 @@ def build_libstdcxx_dictionary ():
     libstdcxx_printer.add_version('std::', 'initializer_list',
                                   StdInitializerListPrinter)
     libstdcxx_printer.add_version('std::', 'atomic', StdAtomicPrinter)
+    libstdcxx_printer.add_version('std::', 'basic_stringbuf', StdStringBufPrinter)
+    libstdcxx_printer.add_version('std::__cxx11::', 'basic_stringbuf', StdStringBufPrinter)
+    libstdcxx_printer.add_version('std::', 'basic_stringstream', StdStringStreamPrinter)
+    libstdcxx_printer.add_version('std::__cxx11::', 'basic_stringstream', StdStringStreamPrinter)
 
     # std::regex components
     libstdcxx_printer.add_version('std::__detail::', '_State',
diff --git a/libstdc++-v3/testsuite/libstdc++-prettyprinters/debug.cc b/libstdc++-v3/testsuite/libstdc++-prettyprinters/debug.cc
index 98bbc182551..7efec6d0f8b 100644
--- a/libstdc++-v3/testsuite/libstdc++-prettyprinters/debug.cc
+++ b/libstdc++-v3/testsuite/libstdc++-prettyprinters/debug.cc
@@ -29,6 +29,7 @@
 #include <list>
 #include <map>
 #include <set>
+#include <sstream>
 #include <vector>
 #include <ext/slist>
 
@@ -110,6 +111,10 @@ main()
   __gnu_cxx::slist<int>::iterator slliter = sll.begin();
 // { dg-final { note-test slliter {47} } }
 
+  std::stringstream sstream;
+  sstream << "abc";
+// { dg-final { note-test sstream "\"abc\"" } }
+
   std::cout << "\n";
   return 0;			// Mark SPOT
 }
diff --git a/libstdc++-v3/testsuite/libstdc++-prettyprinters/simple.cc b/libstdc++-v3/testsuite/libstdc++-prettyprinters/simple.cc
index 1f85775bff0..584989ce09f 100644
--- a/libstdc++-v3/testsuite/libstdc++-prettyprinters/simple.cc
+++ b/libstdc++-v3/testsuite/libstdc++-prettyprinters/simple.cc
@@ -30,6 +30,7 @@
 #include <list>
 #include <map>
 #include <set>
+#include <sstream>
 #include <vector>
 #include <ext/slist>
 
@@ -169,6 +170,10 @@ main()
   __gnu_cxx::slist<int>::iterator slliter0;
 // { dg-final { note-test slliter0 {non-dereferenceable iterator for __gnu_cxx::slist} } }
 
+  std::stringstream sstream;
+  sstream << "abc";
+// { dg-final { note-test sstream "\"abc\"" } }
+
   std::cout << "\n";
   return 0;			// Mark SPOT
 }
diff --git a/libstdc++-v3/testsuite/libstdc++-prettyprinters/simple11.cc b/libstdc++-v3/testsuite/libstdc++-prettyprinters/simple11.cc
index 6f21675cf41..6edd7e929fe 100644
--- a/libstdc++-v3/testsuite/libstdc++-prettyprinters/simple11.cc
+++ b/libstdc++-v3/testsuite/libstdc++-prettyprinters/simple11.cc
@@ -30,6 +30,7 @@
 #include <list>
 #include <map>
 #include <set>
+#include <sstream>
 #include <vector>
 #include <ext/slist>
 
@@ -162,6 +163,10 @@ main()
   __gnu_cxx::slist<int>::iterator slliter0;
 // { dg-final { note-test slliter0 {non-dereferenceable iterator for __gnu_cxx::slist} } }
 
+  std::stringstream sstream;
+  sstream << "abc";
+// { dg-final { note-test sstream "\"abc\"" } }
+
   std::cout << "\n";
   return 0;			// Mark SPOT
 }
-- 
2.37.3


  reply	other threads:[~2022-09-04 18:48 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-04 18:47 [PATCH 1/2] libstdc++: Fix pretty printer tests of tuple indexes Philipp Fent
2022-09-04 18:47 ` Philipp Fent [this message]
2022-09-06 11:27   ` [PATCH 2/2] libstdc++: Add pretty printer for std::stringstream Jonathan Wakely
2022-09-06 21:24     ` [PATCH v2] libstdc++: Add pretty printer for std::stringstreams Philipp Fent
2022-09-14 12:45       ` Jonathan Wakely
2022-09-12  8:37     ` [PATCH 2/2] libstdc++: Add pretty printer for std::stringstream Philipp Fent
2022-09-06  1:06 ` [PATCH 1/2] libstdc++: Fix pretty printer tests of tuple indexes Will Hawkins
2022-09-06 11:12   ` Jonathan Wakely

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220904184735.177348-2-fent@in.tum.de \
    --to=fent@in.tum.de \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=libstdc++@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).