From patchwork Thu Apr 27 18:12:20 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Fran=C3=A7ois_Dumont?= X-Patchwork-Id: 756100 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3wDQ6118SPz9sND for ; Fri, 28 Apr 2017 04:12:40 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="T1YxP2fE"; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=V/xuMWEeZAKMzzam38C+vgJlgMz4hsW/NojUkRue9OWjuDDO1V 2x6t0bx/MCya7x7NsL0mKH0kEOyBfcwRgfX0lcaSAYUz1aE3H+9YMi9fWd8K7eYH XciWTNSMBcdce4yI3ZfauQoTTa6RDN7WdWdp+gjnSLoTsbUSnybjBujF4= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; s= default; bh=CvRSCM3i2dpSY8PzDFz7IVNvHNY=; b=T1YxP2fE6pjUNVUlqs23 +Mug7J/h78dRRIGOualpH/A3EEQhYsfBE1cqho0nKt53gaYkBIQcKWnU0A3btygJ MtzX8Zemg7a+xXqqnV/heNyMGMfxlbefVIT6CbqVtefYdWOsT4jgM0PMjnsYklCC wkbVMjHJHPp8YRdfWBA8ARw= Received: (qmail 27314 invoked by alias); 27 Apr 2017 18:12:26 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 26721 invoked by uid 89); 27 Apr 2017 18:12:26 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-23.9 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy=Johnny, johnny, 5479 X-Spam-User: qpsmtpd, 2 recipients X-HELO: mail-wm0-f54.google.com Received: from mail-wm0-f54.google.com (HELO mail-wm0-f54.google.com) (74.125.82.54) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 27 Apr 2017 18:12:23 +0000 Received: by mail-wm0-f54.google.com with SMTP id w64so23918076wma.0; Thu, 27 Apr 2017 11:12:25 -0700 (PDT) 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; bh=N1bD8i1IidWfrms0XXLaCJXE8FfEM61qYEDIUywtmAo=; b=ecuKLT0Z0stsWQZCfEkuK6oa3vF24gWMxCVlIfyID9jGtKL0NqVqam7EEkrcveTFKK 0G2rPylCYas8o9Wy4rKzl/+647x1UxfnSeIL1iqqvkGTy/S0fH87mwuYBfDDw0IjfaIh Zhuttq2O9Jq6FgPiWnTD8fzL6DRDIRQfU2qkSjl4hRBEGwdVxmF+1dCPSEVjo995nkJc Z9gM8DMwYCxjqo1+TDOyEZ+Mq9R1EPdpuBRnyvCA9u9FxSTKrMQPhGoblW+i+yGnEQIT 2AQHVpJppqWg2DEryTfYHnHf6FjB0kZX9O6qXNJGOrKbrcewr+dLq5ZkZVILcss7AOQ/ 0Vxg== X-Gm-Message-State: AN3rC/6oJVJ/FfHENVkDyMBGlYVsd+jIqYXC1znw04ZBXcgoJxmiaohB tzvQkDhBXEWcigbs X-Received: by 10.28.37.193 with SMTP id l184mr1837124wml.70.1493316743153; Thu, 27 Apr 2017 11:12:23 -0700 (PDT) Received: from [192.168.0.23] (arf62-1-82-237-250-248.fbx.proxad.net. [82.237.250.248]) by smtp.googlemail.com with ESMTPSA id u66sm5988831wmd.24.2017.04.27.11.12.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 Apr 2017 11:12:21 -0700 (PDT) To: "libstdc++@gcc.gnu.org" , gcc-patches From: =?UTF-8?Q?Fran=c3=a7ois_Dumont?= Subject: Make pretty printers version namespace dependant Message-ID: <7e10edf1-2395-3a91-25cf-9382dbe73a0f@gmail.com> Date: Thu, 27 Apr 2017 20:12:20 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 Hi Here is the patch to registers Printers depending on activation of versioned namespace. 2017-04-27 François Dumont * python/Makefile.am [ENABLE_SYMVERS_GNU_NAMESPACE] (user_versioned_namespace): New. (gdb.py): Adapt target. * python/Makefile.in: Regenerate. * python/hook.in: Likewise. * python/libstdcxx/v6/printers.py (add_one_template_type_printer): Register only 1 Printer type depending on _versioned_namespace value. (add_one_type_printer): Likewise. (register_libstdcxx_printers): Add parameter use_versioned_namespace. Adapt _versioned_namespace value based on it. * testsuite/lib/gdb-test.exp (get_use_versioned_namespace): New. (note-test): Detect if version namespace is active and pass the information to register_libstdcxx_printers. * testsuite/libstdc++-prettyprinters/48362.cc: Replace a regexp-test by a note-test. Tested under Linux x86_64, with and without version namespace. Ok to commit to trunk ? Are we going to wait for gcc 7.1 before bumping version namespace ? François diff --git a/libstdc++-v3/python/Makefile.am b/libstdc++-v3/python/Makefile.am index 80790e2..5d19d3d 100644 --- a/libstdc++-v3/python/Makefile.am +++ b/libstdc++-v3/python/Makefile.am @@ -29,6 +29,12 @@ else pythondir = $(datadir)/gcc-$(gcc_version)/python endif +if ENABLE_SYMVERS_GNU_NAMESPACE +use_versioned_namespace = True +else +use_versioned_namespace = False +endif + all-local: gdb.py nobase_python_DATA = \ @@ -39,7 +45,9 @@ nobase_python_DATA = \ gdb.py: hook.in Makefile sed -e 's,@pythondir@,$(pythondir),' \ - -e 's,@toolexeclibdir@,$(toolexeclibdir),' < $(srcdir)/hook.in > $@ + -e 's,@toolexeclibdir@,$(toolexeclibdir),' \ + -e 's,@use_versioned_namespace@,$(use_versioned_namespace),' \ + < $(srcdir)/hook.in > $@ install-data-local: gdb.py @$(mkdir_p) $(DESTDIR)$(toolexeclibdir) diff --git a/libstdc++-v3/python/Makefile.in b/libstdc++-v3/python/Makefile.in index a8122aa..d852a3a 100644 --- a/libstdc++-v3/python/Makefile.in +++ b/libstdc++-v3/python/Makefile.in @@ -346,6 +346,8 @@ WARN_CXXFLAGS = \ AM_CPPFLAGS = $(GLIBCXX_INCLUDES) $(CPPFLAGS) @ENABLE_PYTHONDIR_FALSE@pythondir = $(datadir)/gcc-$(gcc_version)/python @ENABLE_PYTHONDIR_TRUE@pythondir = $(prefix)/$(python_mod_dir) +@ENABLE_SYMVERS_GNU_NAMESPACE_FALSE@use_versioned_namespace = False +@ENABLE_SYMVERS_GNU_NAMESPACE_TRUE@use_versioned_namespace = True nobase_python_DATA = \ libstdcxx/v6/printers.py \ libstdcxx/v6/xmethods.py \ @@ -545,7 +547,9 @@ all-local: gdb.py gdb.py: hook.in Makefile sed -e 's,@pythondir@,$(pythondir),' \ - -e 's,@toolexeclibdir@,$(toolexeclibdir),' < $(srcdir)/hook.in > $@ + -e 's,@toolexeclibdir@,$(toolexeclibdir),' \ + -e 's,@use_versioned_namespace@,$(use_versioned_namespace),' \ + < $(srcdir)/hook.in > $@ install-data-local: gdb.py @$(mkdir_p) $(DESTDIR)$(toolexeclibdir) diff --git a/libstdc++-v3/python/hook.in b/libstdc++-v3/python/hook.in index b82604a6c..1b3a577 100644 --- a/libstdc++-v3/python/hook.in +++ b/libstdc++-v3/python/hook.in @@ -58,4 +58,4 @@ if gdb.current_objfile () is not None: # Call a function as a plain import would not execute body of the included file # on repeated reloads of this object file. from libstdcxx.v6 import register_libstdcxx_printers -register_libstdcxx_printers(gdb.current_objfile()) +register_libstdcxx_printers(gdb.current_objfile(), @use_versioned_namespace@) diff --git a/libstdc++-v3/python/libstdcxx/v6/printers.py b/libstdc++-v3/python/libstdcxx/v6/printers.py index a67b27a..7370982 100644 --- a/libstdc++-v3/python/libstdcxx/v6/printers.py +++ b/libstdc++-v3/python/libstdcxx/v6/printers.py @@ -1223,7 +1223,7 @@ class Printer(object): self.subprinters.append(printer) self.lookup[name] = printer - # Add a name using _GLIBCXX_BEGIN_NAMESPACE_VERSION. + # Add a name using _GLIBCXX_BEGIN_NAMESPACE_VERSION if needed. def add_version(self, base, name, function): self.add(base + name, function) if _versioned_namespace: @@ -1319,14 +1319,12 @@ class TemplateTypePrinter(object): return self._recognizer(self.pattern, self.subst) def add_one_template_type_printer(obj, name, match, subst): + if _versioned_namespace: + # Add type printer in versioned namespace: + match = _versioned_namespace + match.replace('std::', 'std::' + _versioned_namespace) match = '^std::' + match + '$' printer = TemplateTypePrinter(name, match, 'std::' + subst) gdb.types.register_type_printer(obj, printer) - if _versioned_namespace: - # Add second type printer for same type in versioned namespace: - match = match.replace('std::', 'std::' + _versioned_namespace) - printer = TemplateTypePrinter(name, match, 'std::' + subst) - gdb.types.register_type_printer(obj, printer) class FilteringTypePrinter(object): def __init__(self, match, name): @@ -1360,11 +1358,11 @@ class FilteringTypePrinter(object): return self._recognizer(self.match, self.name) def add_one_type_printer(obj, match, name): - printer = FilteringTypePrinter(match, 'std::' + name) - gdb.types.register_type_printer(obj, printer) + namespace = 'std::' if _versioned_namespace: - printer = FilteringTypePrinter(match, 'std::' + _versioned_namespace + name) - gdb.types.register_type_printer(obj, printer) + namespace += _versioned_namespace + printer = FilteringTypePrinter(match, namespace + name) + gdb.types.register_type_printer(obj, printer) def register_type_printers(obj): global _use_type_printing @@ -1428,65 +1426,66 @@ def register_type_printers(obj): # Do not show defaulted template arguments in class templates add_one_template_type_printer(obj, 'unique_ptr', - 'unique_ptr<(.*), std::default_delete<\\1 ?> >', - 'unique_ptr<{1}>') + 'unique_ptr<(.*), std::default_delete<\\1 ?> >', + 'unique_ptr<{1}>') add_one_template_type_printer(obj, 'basic_string', - 'basic_string<((un)?signed char), std::char_traits<\\1 ?>, std::allocator<\\1 ?> >', - 'basic_string<{1}>') + 'basic_string<((un)?signed char), std::char_traits<\\1 ?>, std::allocator<\\1 ?> >', + 'basic_string<{1}>') add_one_template_type_printer(obj, 'deque', - 'deque<(.*), std::allocator<\\1 ?> >', - 'deque<{1}>') + 'deque<(.*), std::allocator<\\1 ?> >', + 'deque<{1}>') add_one_template_type_printer(obj, 'forward_list', - 'forward_list<(.*), std::allocator<\\1 ?> >', - 'forward_list<{1}>') + 'forward_list<(.*), std::allocator<\\1 ?> >', + 'forward_list<{1}>') add_one_template_type_printer(obj, 'list', - 'list<(.*), std::allocator<\\1 ?> >', - 'list<{1}>') + 'list<(.*), std::allocator<\\1 ?> >', + 'list<{1}>') add_one_template_type_printer(obj, 'vector', - 'vector<(.*), std::allocator<\\1 ?> >', - 'vector<{1}>') + 'vector<(.*), std::allocator<\\1 ?> >', + 'vector<{1}>') add_one_template_type_printer(obj, 'map', - 'map<(.*), (.*), std::less<\\1 ?>, std::allocator > >', - 'map<{1}, {2}>') + 'map<(.*), (.*), std::less<\\1 ?>, std::allocator > >', + 'map<{1}, {2}>') add_one_template_type_printer(obj, 'multimap', - 'multimap<(.*), (.*), std::less<\\1 ?>, std::allocator > >', - 'multimap<{1}, {2}>') + 'multimap<(.*), (.*), std::less<\\1 ?>, std::allocator > >', + 'multimap<{1}, {2}>') add_one_template_type_printer(obj, 'set', - 'set<(.*), std::less<\\1 ?>, std::allocator<\\1 ?> >', - 'set<{1}>') + 'set<(.*), std::less<\\1 ?>, std::allocator<\\1 ?> >', + 'set<{1}>') add_one_template_type_printer(obj, 'multiset', - 'multiset<(.*), std::less<\\1 ?>, std::allocator<\\1 ?> >', - 'multiset<{1}>') + 'multiset<(.*), std::less<\\1 ?>, std::allocator<\\1 ?> >', + 'multiset<{1}>') add_one_template_type_printer(obj, 'unordered_map', - 'unordered_map<(.*), (.*), std::hash<\\1 ?>, std::equal_to<\\1 ?>, std::allocator > >', - 'unordered_map<{1}, {2}>') + 'unordered_map<(.*), (.*), std::hash<\\1 ?>, std::equal_to<\\1 ?>, std::allocator > >', + 'unordered_map<{1}, {2}>') add_one_template_type_printer(obj, 'unordered_multimap', - 'unordered_multimap<(.*), (.*), std::hash<\\1 ?>, std::equal_to<\\1 ?>, std::allocator > >', - 'unordered_multimap<{1}, {2}>') + 'unordered_multimap<(.*), (.*), std::hash<\\1 ?>, std::equal_to<\\1 ?>, std::allocator > >', + 'unordered_multimap<{1}, {2}>') add_one_template_type_printer(obj, 'unordered_set', - 'unordered_set<(.*), std::hash<\\1 ?>, std::equal_to<\\1 ?>, std::allocator<\\1 ?> >', - 'unordered_set<{1}>') + 'unordered_set<(.*), std::hash<\\1 ?>, std::equal_to<\\1 ?>, std::allocator<\\1 ?> >', + 'unordered_set<{1}>') add_one_template_type_printer(obj, 'unordered_multiset', - 'unordered_multiset<(.*), std::hash<\\1 ?>, std::equal_to<\\1 ?>, std::allocator<\\1 ?> >', - 'unordered_multiset<{1}>') + 'unordered_multiset<(.*), std::hash<\\1 ?>, std::equal_to<\\1 ?>, std::allocator<\\1 ?> >', + 'unordered_multiset<{1}>') # strip the "fundamentals_v1" inline namespace from these types add_one_template_type_printer(obj, 'any', - 'experimental::fundamentals_v\d::any<(.*)>', - 'experimental::any<\\1>') + 'experimental::fundamentals_v\d::any<(.*)>', + 'experimental::any<\\1>') add_one_template_type_printer(obj, 'optional', - 'experimental::fundamentals_v\d::optional<(.*)>', - 'experimental::optional<\\1>') + 'experimental::fundamentals_v\d::optional<(.*)>', + 'experimental::optional<\\1>') add_one_template_type_printer(obj, 'basic_string_view', - 'experimental::fundamentals_v\d::basic_string_view<(.*), std::char_traits<\\1> >', - 'experimental::basic_string_view<\\1>') + 'experimental::fundamentals_v\d::basic_string_view<(.*), std::char_traits<\\1> >', + 'experimental::basic_string_view<\\1>') -def register_libstdcxx_printers (obj): +def register_libstdcxx_printers (obj, use_versioned_namespace = False): "Register libstdc++ pretty-printers with objfile Obj." global _use_gdb_pp + global _versioned_namespace global libstdcxx_printer if _use_gdb_pp: @@ -1496,6 +1495,9 @@ def register_libstdcxx_printers (obj): obj = gdb obj.pretty_printers.append(libstdcxx_printer) + if not use_versioned_namespace: + _versioned_namespace = None + register_type_printers(obj) def build_libstdcxx_dictionary (): diff --git a/libstdc++-v3/testsuite/lib/gdb-test.exp b/libstdc++-v3/testsuite/lib/gdb-test.exp index 0507837..5685161 100644 --- a/libstdc++-v3/testsuite/lib/gdb-test.exp +++ b/libstdc++-v3/testsuite/lib/gdb-test.exp @@ -50,6 +50,33 @@ proc get_line_number {filename marker} { return $gdb_markers($filename,$marker) } +# Detect either versioned namespace is active or not. +proc get_use_versioned_namespace { } { + # Set up and preprocess a C++ test program that depends + # on versioned namespace activation. + set src use_versioned_namespace[pid].cc + + set f [open $src "w"] + puts $f "#include " + puts $f "#if _GLIBCXX_INLINE_VERSION" + puts $f "# error Versioned namespace active" + puts $f "#endif" + close $f + + set lines [v3_target_compile $src /dev/null preprocess ""] + file delete $src + + if [string match "" $lines] { + # No error message, preprocessing succeeded, no versioned namespace. + set use_versioned_namespace False + } else { + set use_versioned_namespace True + } + + verbose "get_use_versioned_namespace: $use_versioned_namespace" 2 + return $use_versioned_namespace +} + # Make note of a gdb test. A test consists of a variable name and an # expected result. proc note-test {var result} { @@ -104,6 +131,7 @@ proc gdb-test { marker {selector {}} {load_xmethods 0} } { upvar 2 prog prog set line [get_line_number $prog $marker] + set use_versioned_namespace [get_use_versioned_namespace] set gdb_name $::env(GUALITY_GDB_NAME) set testname "$testcase" @@ -123,7 +151,7 @@ proc gdb-test { marker {selector {}} {load_xmethods 0} } { puts $fd "file ./$output_file" # Load & register *our* copy of the pretty-printers puts $fd "source $printer_code" - puts $fd "python register_libstdcxx_printers(None)" + puts $fd "python register_libstdcxx_printers(None, $use_versioned_namespace)" if { $load_xmethods } { # Load a& register xmethods. puts $fd "source $xmethod_code" diff --git a/libstdc++-v3/testsuite/libstdc++-prettyprinters/48362.cc b/libstdc++-v3/testsuite/libstdc++-prettyprinters/48362.cc index 998b6d5..db9fd9a 100644 --- a/libstdc++-v3/testsuite/libstdc++-prettyprinters/48362.cc +++ b/libstdc++-v3/testsuite/libstdc++-prettyprinters/48362.cc @@ -26,7 +26,7 @@ int main() { std::tuple<> t1; -// { dg-final { regexp-test t1 {empty std::tuple} } } +// { dg-final { note-test t1 {empty std::tuple} } } std::tuple> t2{ "Johnny", 5, {} }; // { dg-final { regexp-test t2 {std::tuple containing = {\[1\] = "Johnny", \[2\] = 5, \[3\] = {> = empty std::tuple, }}} } }