Pretty printers for versioned namespace

Jonathan Wakely jwakely@redhat.com
Thu Jan 19 21:22:00 GMT 2017


On 19/01/17 22:01 +0100, François Dumont wrote:
>On 10/01/2017 13:39, Jonathan Wakely wrote:
>>I've committed the attached patch, which passes the tests for the
>>default configuration and the versioned namespace configuration.
>>
>>I added another helper function, strip_versioned_namespace, which is
>>more expressive than doing typename.replace(vers_nsp, '') everywhere.
>>I've also renamed vers_nsp to _versioned_namespace (using the naming
>>convention for global variables private to the module). I've added
>>checks so that if that variable is None then the extra printers and
>>special cases for the versioned namespace are skipped. That's not
>>currently used, but it would allow us to optimise things later if
>>needed.
>
>Very nice feature indeed, see below.
>
>>
>>I also needed to update the new SharedPtrMethodsMatcher to add
>>"(__\d+)?" to the regular expression.
>>
>>
>>>@@ -1392,47 +1406,54 @@ def register_type_printers(obj):
>>>    add_one_type_printer(obj, 'discard_block_engine', 'ranlux48')
>>>    add_one_type_printer(obj, 'shuffle_order_engine', 'knuth_b')
>>>
>>>+    # Consider optional versioned namespace
>>>+    opt_nsp = '(' + vers_nsp + ')?'
>>>+
>>>    # 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}>')
>>>+        '{0}unique_ptr<(.*), std::{0}default_delete<\\2 ?> 
>>>>'.format(opt_nsp),
>>>+        'unique_ptr<{2}>')
>>
>>This is ugly. Mixing python string formatting with regular expressions
>>makes it harder to read, and is inconsistent with how the versioned
>>namespace is handled elsewhere. In Printer.add_version and
>>add_one_type_printer we just register two names, one using std:: and
>>one using std::__7::. We can do the same for the template type
>>printers.
>
>    Yes, your approach is much nicer even if it results in more type 
>printer registered.
>
>    My plan was to submit the attached patch but this doesn't work as 
>the python module seems to be loaded before libstdc++.so. If you know 
>a way to test for versioned namespace before starting registering 
>printers this patch might still be useful. Otherwise I will just 
>forget it.

See the attached patch, which decides at configure-time whether to
enable the versioned namespace printers or not. This is what I had in
mind.



-------------- next part --------------
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/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 36dd81d..4a7d117 100644
--- a/libstdc++-v3/python/libstdcxx/v6/printers.py
+++ b/libstdc++-v3/python/libstdcxx/v6/printers.py
@@ -1482,7 +1482,7 @@ def register_type_printers(obj):
             '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
@@ -1495,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 ():


More information about the Libstdc++ mailing list