From patchwork Sun Sep 4 18:47:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philipp Fent X-Patchwork-Id: 955 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:ecc5:0:0:0:0:0 with SMTP id s5csp1646036wro; Sun, 4 Sep 2022 11:49:39 -0700 (PDT) X-Google-Smtp-Source: AA6agR62WtMxK/kzS8qMeVKQlI/Nzk7gjAFLINg2T5JtPguuotKTFrU+M4xSqusRIQAmboUN5Lur X-Received: by 2002:a17:907:2d86:b0:741:662f:f1f7 with SMTP id gt6-20020a1709072d8600b00741662ff1f7mr25211712ejc.34.1662317379744; Sun, 04 Sep 2022 11:49:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662317379; cv=none; d=google.com; s=arc-20160816; b=oJiS18ovTB3CnSsRw56bmCOvScZdET1co6k+4LG4VCKlgic0bofnO8pKaqQVWU5WJo u701EKcfAN2bFTHTexrROl5JQ57Ml1lZ9+Aadhy7yuYgeAW48X3ceohqLTVyDK17NSUO lG4Ds64s5U1DFtMdsZ+Yul/Xcq7h6EanDUriG62I0Gl4HMQm32WbzP96eg047PHS+Hrb 5/7O7+VnSU67pbqgBsEwml1WF4ckjesECqe/kNblrByggI/Xc6FqA69mNwwML3Ure+re yaDq+Uby/gl++S+KCtmg1VQi4qBV8n51CWSSHSpVYR7/Gtjt8qYBhqhSQvWSJEYQsvR8 XQdA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:reply-to:from:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=FO65aQJ6VjbqPu87JNmANcNDLrvTCWtIsMdtmXbsaxg=; b=CvKdIhgMllR2cbXQ/0Dzo4g5ZAoKzx3FddIzbjYtEmu4IZqo+aKjowM2xJdv+EGOES OMtMfhUoRO5JQrqTfBV6rJm/xhZ+veZ1TqwulkwCKgfVGFPefxbUEHJCbaFnG5K1sIqp bqTsz7WXAF4WscPkJrvs/IdQ4I2gQY5c3DwFlFVF/NE7nvYIdw3q4xCWunPhfVdyKg5y FbeKU/cQSQty0mZyi6KsuWAi1+y5Xma7AMShnGz3kemByxYnnmZI+4wogNX9rmt+i0Z/ 6kYSfP1DnhNCqXplKUfRIt58frHuCExS7wLsZlfQ865bqzdfnK+DTrTJWqdxi4bkGFIe A6Wg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=bNoCUltE; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id h4-20020a0564020e8400b0044dbb9afe1fsi2795485eda.467.2022.09.04.11.49.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 04 Sep 2022 11:49:39 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=bNoCUltE; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 522373854169 for ; Sun, 4 Sep 2022 18:48:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 522373854169 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1662317328; bh=FO65aQJ6VjbqPu87JNmANcNDLrvTCWtIsMdtmXbsaxg=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=bNoCUltE44C5VDtjMIoSeEIS4jaDf7Alo0sI/m2oRWj73++cgv3q2yQCjtK/37vT1 26o7mu2dsUhmIXF5gYw93dxzluu7/HZk6NLPDxXqvHqd7Uo8TpAp3ulcivcgxMXESd vc28dtqEoDeK2vyXh/0GvLR5XPKQEVQcGQrJ/Sr8= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mailout1.rbg.tum.de (mailout1.rbg.tum.de [131.159.0.201]) by sourceware.org (Postfix) with ESMTPS id 75FCA3856962; Sun, 4 Sep 2022 18:48:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 75FCA3856962 Received: from mailrelay1.rbg.tum.de (mailrelay1.in.tum.de [131.159.254.14]) by mailout1.rbg.tum.de (Postfix) with ESMTPS id 9870690; Sun, 4 Sep 2022 20:48:03 +0200 (CEST) Received: by mailrelay1.rbg.tum.de (Postfix, from userid 112) id 95B251AFE; Sun, 4 Sep 2022 20:48:03 +0200 (CEST) Received: from mailrelay1.rbg.tum.de (localhost [127.0.0.1]) by mailrelay1.rbg.tum.de (Postfix) with ESMTP id 753BE1AFD; Sun, 4 Sep 2022 20:48:03 +0200 (CEST) Received: from mail.in.tum.de (vmrbg426.in.tum.de [131.159.0.73]) by mailrelay1.rbg.tum.de (Postfix) with ESMTPS id 739541AFC; Sun, 4 Sep 2022 20:48:03 +0200 (CEST) Received: by mail.in.tum.de (Postfix, from userid 112) id 70CA34A04C4; Sun, 4 Sep 2022 20:48:03 +0200 (CEST) Received: (Authenticated sender: fent) by mail.in.tum.de (Postfix) with ESMTPSA id E455A4A0321; Sun, 4 Sep 2022 20:48:02 +0200 (CEST) (Extended-Queue-bit xtech_to@fff.in.tum.de) To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [PATCH 2/2] libstdc++: Add pretty printer for std::stringstream Date: Sun, 4 Sep 2022 20:47:35 +0200 Message-Id: <20220904184735.177348-2-fent@in.tum.de> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220904184735.177348-1-fent@in.tum.de> References: <20220904184735.177348-1-fent@in.tum.de> MIME-Version: 1.0 X-Spam-Status: No, score=-13.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Philipp Fent via Gcc-patches From: Philipp Fent Reply-To: Philipp Fent Cc: Philipp Fent Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1743066109020009492?= X-GMAIL-MSGID: =?utf-8?q?1743066109020009492?= Signed-off-by: Philipp Fent --- 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 #include #include +#include #include #include @@ -110,6 +111,10 @@ main() __gnu_cxx::slist::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 #include #include +#include #include #include @@ -169,6 +170,10 @@ main() __gnu_cxx::slist::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 #include #include +#include #include #include @@ -162,6 +163,10 @@ main() __gnu_cxx::slist::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 }