diff --git a/libstdc++-v3/python/libstdcxx/v6/printers.py b/libstdc++-v3/python/libstdcxx/v6/printers.py index 245b6e3dbcd..6a0b8a22f1d 100644 --- a/libstdc++-v3/python/libstdcxx/v6/printers.py +++ b/libstdc++-v3/python/libstdcxx/v6/printers.py @@ -2045,25 +2045,35 @@ class FilteringTypePrinter(object): Args: match (str): The class template to recognize. name (str): The typedef-name that will be used instead. + targ1 (str, optional): The first template argument. Defaults to None. + If arg1 is provided, only match specializations with this type + as the first template argument, e.g. if match='basic_string' Checks if a specialization of the class template 'match' is the same type as the typedef 'name', and prints it as 'name' instead. - e.g. if an instantiation of std::basic_istream is the same type as + e.g. for match='basic_istream', name='istream', if any specialization of + std::basic_istream is the same type as std::istream then print it as + std::istream. + + e.g. for match='basic_istream', name='istream', targ1='char', if any + specialization of std::basic_istream is the same type as std::istream then print it as std::istream. """ - def __init__(self, match, name): + def __init__(self, match, name, targ1 = None): self.match = match self.name = name + self.targ1 = targ1 self.enabled = True class _recognizer(object): "The recognizer class for FilteringTypePrinter." - def __init__(self, match, name): + def __init__(self, match, name, targ1): self.match = match self.name = name + self.targ1 = targ1 self.type_obj = None def recognize(self, type_obj): @@ -2075,7 +2085,11 @@ class FilteringTypePrinter(object): return None if self.type_obj is None: - if not type_obj.tag.startswith(self.match): + if self.tag1 is not None: + if not type_obj.tag.startswith('{}<{}'.format(self.match, self.targ1): + # Filter didn't match. + return None + elif not type_obj.tag.startswith(self.match): # Filter didn't match. return None try: @@ -2084,18 +2098,23 @@ class FilteringTypePrinter(object): pass if self.type_obj == type_obj: return strip_inline_namespaces(self.name) + + if self.match.split('::')[-1] is 'basic_string': + if self.type_obj.tag.replace('__cxx11::', '') == type_obj.tag.replace('__cxx11::', ''): ++ return strip_inline_namespaces(self.name) + return None def instantiate(self): "Return a recognizer object for this type printer." return self._recognizer(self.match, self.name) -def add_one_type_printer(obj, match, name): - printer = FilteringTypePrinter('std::' + match, 'std::' + name) +def add_one_type_printer(obj, match, name, targ1 = None): + printer = FilteringTypePrinter('std::' + match, 'std::' + name, targ1) gdb.types.register_type_printer(obj, printer) if _versioned_namespace: ns = 'std::' + _versioned_namespace - printer = FilteringTypePrinter(ns + match, ns + name) + printer = FilteringTypePrinter(ns + match, ns + name, targ1) gdb.types.register_type_printer(obj, printer) def register_type_printers(obj):