libstdc++: Fix compatibility support in unique_ptr pretty printer
authorJonathan Wakely <jwakely@redhat.com>
Mon, 10 Aug 2020 17:44:06 +0000 (18:44 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Mon, 10 Aug 2020 17:47:06 +0000 (18:47 +0100)
The support for the old std::unique_ptr implementation was failing,
because it tried to work on a typedef instead of the underlying type.
The test supposed to verify the support worked wasn't using a typedef,
so didn't notice the problem.

libstdc++-v3/ChangeLog:

* python/libstdcxx/v6/printers.py (UniquePointerPrinter.__init__):
Use gdb.Type.strip_typedefs().
* testsuite/libstdc++-prettyprinters/compat.cc: Use a typedef in
the emulated old type.

libstdc++-v3/python/libstdcxx/v6/printers.py
libstdc++-v3/testsuite/libstdc++-prettyprinters/compat.cc

index 0bf307b8e5f78c29feb028cc96f0c45bdbe9c0b5..c0f061f79c1f03715d10091f8b2955d86bca9ad2 100644 (file)
@@ -245,7 +245,7 @@ class UniquePointerPrinter:
 
     def __init__ (self, typename, val):
         self.val = val
-        impl_type = val.type.fields()[0].type.tag
+        impl_type = val.type.fields()[0].type.strip_typedefs()
         # Check for new implementations first:
         if is_specialization_of(impl_type, '__uniq_ptr_data') \
             or is_specialization_of(impl_type, '__uniq_ptr_impl'):
@@ -253,7 +253,7 @@ class UniquePointerPrinter:
         elif is_specialization_of(impl_type, 'tuple'):
             tuple_member = val['_M_t']
         else:
-            raise ValueError("Unsupported implementation for unique_ptr: %s" % impl_type)
+            raise ValueError("Unsupported implementation for unique_ptr: %s" % str(impl_type))
         tuple_impl_type = tuple_member.type.fields()[0].type # _Tuple_impl
         tuple_head_type = tuple_impl_type.fields()[1].type   # _Head_base
         head_field = tuple_head_type.fields()[0]
@@ -262,7 +262,7 @@ class UniquePointerPrinter:
         elif head_field.is_base_class:
             self.pointer = tuple_member.cast(head_field.type)
         else:
-            raise ValueError("Unsupported implementation for tuple in unique_ptr: %s" % impl_type)
+            raise ValueError("Unsupported implementation for tuple in unique_ptr: %s" % str(impl_type))
 
     def children (self):
         return SmartPtrIterator(self.pointer)
index f1c3b599634af2eb0a5a0889c528d9de2d21aacd..c681becf8b985b42fe61f44f71dc4a791620208f 100644 (file)
@@ -53,7 +53,9 @@ namespace std
     {
       unique_ptr(T* p) { _M_t._M_head_impl = p; }
 
-      tuple<T*, D> _M_t;
+      using __tuple_type = tuple<T*, D>;
+
+      __tuple_type _M_t;
     };
 
   // Old representation of std::optional, before GCC 9