From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 58316 invoked by alias); 5 Feb 2018 06:49:49 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 58296 invoked by uid 89); 5 Feb 2018 06:49:48 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,KAM_SHORT,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.2 spammy=debug.cc, debugcc, UD:debug.cc X-Spam-User: qpsmtpd, 2 recipients X-HELO: mail-wm0-f48.google.com Received: from mail-wm0-f48.google.com (HELO mail-wm0-f48.google.com) (74.125.82.48) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 05 Feb 2018 06:49:38 +0000 Received: by mail-wm0-f48.google.com with SMTP id f3so23598374wmc.1; Sun, 04 Feb 2018 22:49:38 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:from:subject:message-id:date:user-agent :mime-version:content-language; bh=CBGoNnGVClZx8GZfAIU6dqaf8aSZsuJHURaDA0bCRY0=; b=GiPulFuW0nkl+aiqV/eR1VuSDWlgp423ifQC7WBWysB3Pyn+OOsGYZOQOVtnIINM6J qh6U3W53Ad/5ULokgno4na7Jm749qWfHFkZflNYxLyactD9pIIKb3xUaaLSE6Zy9jEA2 nB7II37txvFHFGy9mttgPKxCFUDRILqfER3qTS0QzuvqCHtZVLj8f1cGOD4ctb2PtLDu MJDgCDyizjKLQIGaVQJZpBtAIY/dg1GIfUXFQniqmZ/Htx6rl4Cg6VwOLBFA5udRLAkI PP19ry5caYYBQJ/emeVqdjKy+DrMn3Xr07WBd0eD0U1ZrILhPtUGh4pE+P9qB8TfIOxz P0kg== X-Gm-Message-State: AKwxytd2Mv0ysZF4v0tn4FhauIfKdVVdG7FqhADVy2q8BdK7X3wKT89k UuWkrMLxrXSdUfEi1lUg6jniGw== X-Google-Smtp-Source: AH8x226S1klZAGgMifBeFNCYRMcs+6HshtwNB91FemajA8NmYeeB0sWp+umHquGReZc3TDa0iM38qw== X-Received: by 10.80.195.75 with SMTP id q11mr78478226edb.254.1517813376217; Sun, 04 Feb 2018 22:49:36 -0800 (PST) Received: from [10.25.8.100] ([109.190.253.11]) by smtp.googlemail.com with ESMTPSA id g30sm6662919edb.48.2018.02.04.22.49.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 04 Feb 2018 22:49:35 -0800 (PST) To: "libstdc++@gcc.gnu.org" , gcc-patches From: =?UTF-8?Q?Fran=c3=a7ois_Dumont?= Subject: Fix some _GLIBCXX_DEBUG pretty printer errors Message-ID: <62558510-8551-9275-d4dd-94acbd8914e0@gmail.com> Date: Mon, 05 Feb 2018 06:49:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------1C89F6E9D96F04255D59484C" X-SW-Source: 2018-02/txt/msg00162.txt.bz2 This is a multi-part message in MIME format. --------------1C89F6E9D96F04255D59484C Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-length: 529 Hi     Here is a patch to fix some pretty printer check errors when running those tests with _GLIBCXX_DEBUG.     I introduced a special rendered for the std::forward_list iterator which is similar to the one used for the std::list and so used inheritance, I hope it is not a problem for Python 2/3 compatibility.     I prefer to just rely on normal iterator rendered when we detect that iterator hasn't been initialized so that normal or debug modes give the same result.     Ok to commit ? François --------------1C89F6E9D96F04255D59484C Content-Type: text/x-patch; name="debug_pretty_printer.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="debug_pretty_printer.patch" Content-length: 5613 diff --git a/libstdc++-v3/python/libstdcxx/v6/printers.py b/libstdc++-v3/python/libstdcxx/v6/printers.py index d42d72c..f1cde11 100644 --- a/libstdc++-v3/python/libstdcxx/v6/printers.py +++ b/libstdc++-v3/python/libstdcxx/v6/printers.py @@ -249,21 +249,32 @@ class StdListPrinter: return 'empty %s' % (self.typename) return '%s' % (self.typename) -class StdListIteratorPrinter: - "Print std::list::iterator" - - def __init__(self, typename, val): +class NodeIteratorPrinter: + def __init__(self, typename, val, contname): self.val = val self.typename = typename + self.contname = contname def to_string(self): if not self.val['_M_node']: - return 'non-dereferenceable iterator for std::list' + return 'non-dereferenceable iterator for std::%s' % (self.contname) nodetype = find_type(self.val.type, '_Node') nodetype = nodetype.strip_typedefs().pointer() node = self.val['_M_node'].cast(nodetype).dereference() return str(get_value_from_list_node(node)) +class StdListIteratorPrinter(NodeIteratorPrinter): + "Print std::list::iterator" + + def __init__(self, typename, val): + NodeIteratorPrinter.__init__(self, typename, val, 'list') + +class StdFwdListIteratorPrinter(NodeIteratorPrinter): + "Print std::forward_list::iterator" + + def __init__(self, typename, val): + NodeIteratorPrinter.__init__(self, typename, val, 'forward_list') + class StdSlistPrinter: "Print a __gnu_cxx::slist" @@ -575,10 +586,12 @@ class StdDebugIteratorPrinter: # and return the wrapped iterator value. def to_string (self): base_type = gdb.lookup_type('__gnu_debug::_Safe_iterator_base') + itype = self.val.type.template_argument(0) safe_seq = self.val.cast(base_type)['_M_sequence'] - if not safe_seq or self.val['_M_version'] != safe_seq['_M_version']: + if not safe_seq: + return str(self.val.cast(itype)) + if self.val['_M_version'] != safe_seq['_M_version']: return "invalid iterator" - itype = self.val.type.template_argument(0) return str(self.val.cast(itype)) def num_elements(num): @@ -1731,21 +1744,14 @@ def build_libstdcxx_dictionary (): StdVectorIteratorPrinter) libstdcxx_printer.add_version('__gnu_cxx::', '_Slist_iterator', StdSlistIteratorPrinter) + libstdcxx_printer.add_version('__gnu_cxx::', '_Fwd_list_iterator', + StdFwdListIteratorPrinter) + libstdcxx_printer.add_version('__gnu_cxx::', '_Fwd_list_const_iterator', + StdFwdListIteratorPrinter) # Debug (compiled with -D_GLIBCXX_DEBUG) printer - # registrations. The Rb_tree debug iterator when unwrapped - # from the encapsulating __gnu_debug::_Safe_iterator does not - # have the __norm namespace. Just use the existing printer - # registration for that. + # registrations. libstdcxx_printer.add('__gnu_debug::_Safe_iterator', StdDebugIteratorPrinter) - libstdcxx_printer.add('std::__norm::_List_iterator', - StdListIteratorPrinter) - libstdcxx_printer.add('std::__norm::_List_const_iterator', - StdListIteratorPrinter) - libstdcxx_printer.add('std::__norm::_Deque_const_iterator', - StdDequeIteratorPrinter) - libstdcxx_printer.add('std::__norm::_Deque_iterator', - StdDequeIteratorPrinter) build_libstdcxx_dictionary () diff --git a/libstdc++-v3/testsuite/libstdc++-prettyprinters/debug.cc b/libstdc++-v3/testsuite/libstdc++-prettyprinters/debug.cc index 72b2eeb..9f7f763 100644 --- a/libstdc++-v3/testsuite/libstdc++-prettyprinters/debug.cc +++ b/libstdc++-v3/testsuite/libstdc++-prettyprinters/debug.cc @@ -19,7 +19,9 @@ // with this library; see the file COPYING3. If not see // . -#define _GLIBCXX_DEBUG +#ifndef _GLIBCXX_DEBUG +# define _GLIBCXX_DEBUG +#endif #include #include @@ -96,7 +98,7 @@ main() v.push_back(1); v.push_back(2); std::vector::iterator viter0; -// { dg-final { note-test viter0 {invalid iterator} } } +// { dg-final { note-test viter0 {non-dereferenceable iterator for std::vector} } } std::vector::iterator viter1 = v.begin(); std::vector::iterator viter2 = viter1 + 1; v.erase(viter1); diff --git a/libstdc++-v3/testsuite/libstdc++-prettyprinters/debug_cxx11.cc b/libstdc++-v3/testsuite/libstdc++-prettyprinters/debug_cxx11.cc index 5d98350..1990084 100644 --- a/libstdc++-v3/testsuite/libstdc++-prettyprinters/debug_cxx11.cc +++ b/libstdc++-v3/testsuite/libstdc++-prettyprinters/debug_cxx11.cc @@ -19,7 +19,9 @@ // with this library; see the file COPYING3. If not see // . -#define _GLIBCXX_DEBUG +#ifndef _GLIBCXX_DEBUG +# define _GLIBCXX_DEBUG +#endif #include #include @@ -31,7 +33,7 @@ main() { std::forward_list flst; std::forward_list::iterator flstiter0; -// { dg-final { note-test flstiter0 {invalid iterator}} } +// { dg-final { note-test flstiter0 {non-dereferenceable iterator for std::forward_list}} } flst.push_front("dum"); std::forward_list::iterator flstiter1 = flst.begin(); // { dg-final { note-test *flstiter1 {"dum"}} } --------------1C89F6E9D96F04255D59484C--