[RFC] libstdc++: Fix pretty-printing old implementations of std::unique_ptr

Andres Rodriguez andresx7@gmail.com
Tue Aug 4 14:51:23 GMT 2020

On binaries compiled against gcc5 the impl_type parameter is None,
which results in an exception being raised by is_specialization_of()

These versions of std::unique_ptr have the tuple as a root element.


I ran into this issue when debugging a binary built using gcc5.

I'm not very familiar with python or the gcc codebase, so this might be
the wrong way to address this problem. But a patch seemed like a good
way to start the conversation.

Thanks for taking a look.


P.S.: This is a resend of the patch. I joined the mailing list after
sending this patch so I'm guessing the original email got stuck in a
moderation queue.

 libstdc++-v3/python/libstdcxx/v6/printers.py | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/libstdc++-v3/python/libstdcxx/v6/printers.py b/libstdc++-v3/python/libstdcxx/v6/printers.py
index e4da8dfe5b6..3154a2a6f9d 100644
--- a/libstdc++-v3/python/libstdcxx/v6/printers.py
+++ b/libstdc++-v3/python/libstdcxx/v6/printers.py
@@ -247,7 +247,9 @@ class UniquePointerPrinter:
         self.val = val
         impl_type = val.type.fields()[0].type.tag
         # Check for new implementations first:
-        if is_specialization_of(impl_type, '__uniq_ptr_data') \
+        if impl_type is None:
+            tuple_member = val['_M_t']
+        elif is_specialization_of(impl_type, '__uniq_ptr_data') \
             or is_specialization_of(impl_type, '__uniq_ptr_impl'):
             tuple_member = val['_M_t']['_M_t']
         elif is_specialization_of(impl_type, 'tuple'):

More information about the Gcc-patches mailing list