Re: [patch] Add libstdc++ pretty printers for Library Fundamentals TS types

2014-07-26 Thread Paolo Carlini

Hi,

On 07/23/2014 12:45 PM, Jonathan Wakely wrote:

On 15/07/14 13:03 +0100, Jonathan Wakely wrote:

On 14/07/14 20:31 +0100, Jonathan Wakely wrote:

This adds printers for the types in the std::experimental namespace.


This should fix the test failures that Paolo and HJ are seeing, older
versions of GDB didn't have the gdb.Type.name attribute.

Confirmed fixed, by the way.

Thanks!
Paolo.


Re: [patch] Add libstdc++ pretty printers for Library Fundamentals TS types

2014-07-23 Thread Jonathan Wakely

On 15/07/14 13:03 +0100, Jonathan Wakely wrote:

On 14/07/14 20:31 +0100, Jonathan Wakely wrote:

This adds printers for the types in the std::experimental namespace.


This should fix the test failures that Paolo and HJ are seeing, older
versions of GDB didn't have the gdb.Type.name attribute.

(I suppose I could have just put the full basic_stringchar, ... name
in explicitly instead of using lookup_type, but I'll just make this
fix for now.)

Committed to trunk.
commit 827e07f7e08bc993a284996f7772b04f82ee7fc9
Author: Jonathan Wakely jwak...@redhat.com
Date:   Wed Jul 23 11:40:02 2014 +0100

	* python/libstdcxx/v6/printers.py (StdExpAnyPrinter): Convert type
	to string instead of using gdb.Type.name attribute.

diff --git a/libstdc++-v3/python/libstdcxx/v6/printers.py b/libstdc++-v3/python/libstdcxx/v6/printers.py
index 625396b..15d7a88 100644
--- a/libstdc++-v3/python/libstdcxx/v6/printers.py
+++ b/libstdc++-v3/python/libstdcxx/v6/printers.py
@@ -899,7 +899,7 @@ class StdExpAnyPrinter(SingleObjContainerPrinter):
 raise ValueError(Unknown manager function in std::experimental::any)
 
 # FIXME need to expand 'std::string' so that gdb.lookup_type works
-mgrname = re.sub(std::string(?!\w), gdb.lookup_type('std::string').strip_typedefs().name, m.group(1))
+mgrname = re.sub(std::string(?!\w), str(gdb.lookup_type('std::string').strip_typedefs()), m.group(1))
 mgrtype = gdb.lookup_type(mgrname)
 self.contained_type = mgrtype.template_argument(0)
 valptr = None


Re: [patch] Add libstdc++ pretty printers for Library Fundamentals TS types

2014-07-15 Thread Jonathan Wakely

On 14/07/14 20:31 +0100, Jonathan Wakely wrote:

This adds printers for the types in the std::experimental namespace.


I've committed this slightly improved patch, which removes the
duplicate _contained method from StdExpOptionalPrinter (it was meant
to be using the base class version) and fixes some conditions to
compare to None, so that integers, booleans and pointers with zero
values don't get interpreted as no value.


commit f29d6b5d809df660a989dd19b8afe68d08934d9f
Author: redi redi@138bc75d-0d04-0410-961f-82ee72b054a4
Date:   Tue Jul 15 12:00:18 2014 +

	* python/libstdcxx/v6/printers.py (SingleObjContainerPrinter): New
	base class for experimental::any and experimental::optional printers.
	(StdExpAnyPrinter, StdExpOptionalPrinter, StdExpStringViewPrinter):
	New printers for Fundamentals TS types.
	* testsuite/libstdc++-prettyprinters/libfundts.cc: New.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@212556 138bc75d-0d04-0410-961f-82ee72b054a4

diff --git a/libstdc++-v3/python/libstdcxx/v6/printers.py b/libstdc++-v3/python/libstdcxx/v6/printers.py
index ea34f22..af41f1f 100644
--- a/libstdc++-v3/python/libstdcxx/v6/printers.py
+++ b/libstdc++-v3/python/libstdcxx/v6/printers.py
@@ -836,6 +836,126 @@ class StdForwardListPrinter:
 return 'empty %s' % (self.typename)
 return '%s' % (self.typename)
 
+class SingleObjContainerPrinter(object):
+Base class for printers of containers of single objects
+
+def __init__ (self, val, viz):
+self.contained_value = val
+self.visualizer = viz
+
+def _recognize(self, type):
+Return TYPE as a string after applying type printers
+return gdb.types.apply_type_recognizers(gdb.types.get_type_recognizers(),
+type) or str(type)
+
+class _contained:
+def __init__ (self, val):
+self.val = val
+
+def __iter__ (self):
+return self
+
+def next (self):
+if self.val is None:
+raise StopIteration
+retval = self.val
+self.val = None
+return ('[contained value]', retval)
+
+def children (self):
+if self.contained_value is None:
+return self._contained (None)
+if hasattr (self.visualizer, 'children'):
+return self.visualizer.children ()
+return self._contained (self.contained_value)
+
+def display_hint (self):
+# if contained value is a map we want to display in the same way
+if hasattr (self.visualizer, 'children') and hasattr (self.visualizer, 'display_hint'):
+return self.visualizer.display_hint ()
+return None
+
+
+class StdExpAnyPrinter(SingleObjContainerPrinter):
+Print a std::experimental::any
+
+def __init__ (self, typename, val):
+self.typename = 'std::experimental::any'
+self.val = val
+self.contained_type = None
+contained_value = None
+visualizer = None
+mgr = self.val['_M_manager']
+if mgr != 0:
+func = gdb.block_for_pc(int(mgr.cast(gdb.lookup_type('intptr_t'
+if not func:
+raise ValueError(Invalid function pointer in std::experimental::any)
+rx = r({0}::_Manager_\w+.*)::_S_manage\({0}::_Op, {0} const\*, {0}::_Arg\*\).format(typename)
+m = re.match(rx, func.function.name)
+if not m:
+raise ValueError(Unknown manager function in std::experimental::any)
+
+# FIXME need to expand 'std::string' so that gdb.lookup_type works
+mgrname = re.sub(std::string(?!\w), gdb.lookup_type('std::string').strip_typedefs().name, m.group(1))
+mgrtype = gdb.lookup_type(mgrname)
+self.contained_type = mgrtype.template_argument(0)
+valptr = None
+if '::_Manager_internal' in mgrname:
+valptr = self.val['_M_storage']['_M_buffer'].address
+elif '::_Manager_external' in mgrname:
+valptr = self.val['_M_storage']['_M_ptr']
+elif '::_Manager_alloc' in mgrname:
+datatype = gdb.lookup_type(mgrname + '::_Data')
+valptr = self.val['_M_storage']['_M_ptr'].cast(datatype.pointer())
+valptr = valptr.dereference()['_M_data'].address
+else:
+raise ValueError(Unknown manager function in std::experimental::any)
+contained_value = valptr.cast(self.contained_type.pointer()).dereference()
+visualizer = gdb.default_visualizer(contained_value)
+super(StdExpAnyPrinter, self).__init__ (contained_value, visualizer)
+
+def to_string (self):
+if self.contained_type is None:
+return '%s [no contained value]' % self.typename
+desc = %s containing  % self.typename
+if hasattr (self.visualizer, 'children'):
+return desc +