This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Make pretty printers version namespace dependant


Hi

Here is the patch to registers Printers depending on activation of versioned namespace.

2017-04-27  François Dumont  <fdumont@gcc.gnu.org>

    * 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<T>',
-            '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<T>',
-            '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<T>',
-            'deque<(.*), std::allocator<\\1 ?> >',
-            'deque<{1}>')
+        'deque<(.*), std::allocator<\\1 ?> >',
+        'deque<{1}>')
     add_one_template_type_printer(obj, 'forward_list<T>',
-            'forward_list<(.*), std::allocator<\\1 ?> >',
-            'forward_list<{1}>')
+        'forward_list<(.*), std::allocator<\\1 ?> >',
+        'forward_list<{1}>')
     add_one_template_type_printer(obj, 'list<T>',
-            'list<(.*), std::allocator<\\1 ?> >',
-            'list<{1}>')
+        'list<(.*), std::allocator<\\1 ?> >',
+        'list<{1}>')
     add_one_template_type_printer(obj, 'vector<T>',
-            'vector<(.*), std::allocator<\\1 ?> >',
-            'vector<{1}>')
+        'vector<(.*), std::allocator<\\1 ?> >',
+        'vector<{1}>')
     add_one_template_type_printer(obj, 'map<Key, T>',
-            'map<(.*), (.*), std::less<\\1 ?>, std::allocator<std::pair<\\1 const, \\2 ?> > >',
-            'map<{1}, {2}>')
+        'map<(.*), (.*), std::less<\\1 ?>, std::allocator<std::pair<\\1 const, \\2 ?> > >',
+        'map<{1}, {2}>')
     add_one_template_type_printer(obj, 'multimap<Key, T>',
-            'multimap<(.*), (.*), std::less<\\1 ?>, std::allocator<std::pair<\\1 const, \\2 ?> > >',
-            'multimap<{1}, {2}>')
+        'multimap<(.*), (.*), std::less<\\1 ?>, std::allocator<std::pair<\\1 const, \\2 ?> > >',
+        'multimap<{1}, {2}>')
     add_one_template_type_printer(obj, 'set<T>',
-            '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<T>',
-            '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<Key, T>',
-            'unordered_map<(.*), (.*), std::hash<\\1 ?>, std::equal_to<\\1 ?>, std::allocator<std::pair<\\1 const, \\2 ?> > >',
-            'unordered_map<{1}, {2}>')
+        'unordered_map<(.*), (.*), std::hash<\\1 ?>, std::equal_to<\\1 ?>, std::allocator<std::pair<\\1 const, \\2 ?> > >',
+        'unordered_map<{1}, {2}>')
     add_one_template_type_printer(obj, 'unordered_multimap<Key, T>',
-            'unordered_multimap<(.*), (.*), std::hash<\\1 ?>, std::equal_to<\\1 ?>, std::allocator<std::pair<\\1 const, \\2 ?> > >',
-            'unordered_multimap<{1}, {2}>')
+        'unordered_multimap<(.*), (.*), std::hash<\\1 ?>, std::equal_to<\\1 ?>, std::allocator<std::pair<\\1 const, \\2 ?> > >',
+        'unordered_multimap<{1}, {2}>')
     add_one_template_type_printer(obj, 'unordered_set<T>',
-            '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<T>',
-            '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<T>',
-            'experimental::fundamentals_v\d::any<(.*)>',
-            'experimental::any<\\1>')
+        'experimental::fundamentals_v\d::any<(.*)>',
+        'experimental::any<\\1>')
     add_one_template_type_printer(obj, 'optional<T>',
-            '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<C>',
-            '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 <bits/c++config.h>"
+    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<std::string, int, std::tuple<>> t2{ "Johnny", 5, {} };
 // { dg-final { regexp-test t2 {std::tuple containing = {\[1\] = "Johnny", \[2\] = 5, \[3\] = {<std::(__7::)?tuple<>> = empty std::tuple, <No data fields>}}} } }

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]