diff --git a/libstdc++-v3/python/libstdcxx/v6/xmethods.py b/libstdc++-v3/python/libstdcxx/v6/xmethods.py index 130a658758b..c5e2e6f9363 100644 --- a/libstdc++-v3/python/libstdcxx/v6/xmethods.py +++ b/libstdc++-v3/python/libstdcxx/v6/xmethods.py @@ -19,6 +19,8 @@ import gdb import gdb.xmethod import re +import accessors + matcher_name_prefix = 'libstdc++::' def get_bool_type(): @@ -585,22 +587,9 @@ class UniquePtrGetWorker(gdb.xmethod.XMethodWorker): return method_name == 'get' or not self._is_array def __call__(self, obj): - impl_type = obj.dereference().type.fields()[0].type.tag - # Check for new implementations first: - if re.match('^std::(__\d+::)?__uniq_ptr_(data|impl)<.*>$', impl_type): - tuple_member = obj['_M_t']['_M_t'] - elif re.match('^std::(__\d+::)?tuple<.*>$', impl_type): - tuple_member = obj['_M_t'] - else: - return None - 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] - if head_field.name == '_M_head_impl': - return tuple_member.cast(tuple_head_type)['_M_head_impl'] - elif head_field.is_base_class: - return tuple_member.cast(head_field.type) - else: + try: + return accessors.UniquePtr(obj.dereference()).get() + except ValueError: return None class UniquePtrDerefWorker(UniquePtrGetWorker): @@ -684,7 +673,10 @@ class SharedPtrGetWorker(gdb.xmethod.XMethodWorker): return method_name == 'get' or not self._is_array def __call__(self, obj): - return obj['_M_ptr'] + try: + return accessors.SharedPtr(obj.dereference()).get() + except ValueError: + return None class SharedPtrDerefWorker(SharedPtrGetWorker): "Implements std::shared_ptr::operator*()" @@ -739,8 +731,7 @@ class SharedPtrUseCountWorker(gdb.xmethod.XMethodWorker): return gdb.lookup_type('long') def __call__(self, obj): - refcounts = obj['_M_refcount']['_M_pi'] - return refcounts['_M_use_count'] if refcounts else 0 + return accessors.SharedPtr(obj.dereference()).use_count() class SharedPtrUniqueWorker(SharedPtrUseCountWorker): "Implements std::shared_ptr::unique()"