Tested x86_64-linux (GDB 13.2, Python 3.11). Pushed to trunk.
-- >8 --
Some of these changes were suggested by autopep8's --aggressive
option, others are for readability.
Break long lines by splitting strings across multiple lines, or
introducing local variables to hold results.
Use raw strings for regular expressions, so that backslashes don't need
to be escaped.
libstdc++-v3/ChangeLog:
* python/libstdcxx/v6/printers.py: Break long lines. Use raw
strings for regular expressions. Add whitespace around
operators.
(is_member_of_namespace): Use isinstance to check type.
(is_specialization_of): Likewise. Adjust template_name
for versioned namespace instead of duplicating the re.match
call.
(StdExpAnyPrinter._string_types): New static method.
(StdExpAnyPrinter.to_string): Use _string_types.
---
libstdc++-v3/python/libstdcxx/v6/printers.py | 122 ---
1 file changed, 75 insertions(+), 47 deletions(-)
diff --git a/libstdc++-v3/python/libstdcxx/v6/printers.py
b/libstdc++-v3/python/libstdcxx/v6/printers.py
index 7889235ce1c..3f22ba23452 100644
--- a/libstdc++-v3/python/libstdcxx/v6/printers.py
+++ b/libstdc++-v3/python/libstdcxx/v6/printers.py
@@ -145,7 +145,6 @@ def lookup_templ_spec(templ, *args):
# Use this to find container node types instead of find_type,
# see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91997 for details.
-
def lookup_node_type(nodename, containertype):
"""
Lookup specialization of template nodename corresponding to containertype.
@@ -188,7 +187,7 @@ def is_member_of_namespace(typ, *namespaces):
Test whether a type is a member of one of the specified namespaces.
The type can be specified as a string or a gdb.Type object.
"""
-if type(typ) is gdb.Type:
+if isinstance(typ, gdb.Type):
typ = str(typ)
typ = strip_versioned_namespace(typ)
for namespace in namespaces:
@@ -205,10 +204,10 @@ def is_specialization_of(x, template_name):
without any 'std' qualification.
"""
global _versioned_namespace
-if type(x) is gdb.Type:
+if isinstance(x, gdb.Type):
x = x.tag
if _versioned_namespace:
-return re.match('^std::(%s)?%s<.*>$' % (_versioned_namespace,
template_name), x) is not None
+template_name = '(%s)?%s' % (_versioned_namespace, template_name)
return re.match('^std::%s<.*>$' % template_name, x) is not None
@@ -225,9 +224,9 @@ def strip_inline_namespaces(type_str):
type_str = type_str.replace('std::__cxx11::', 'std::')
expt_ns = 'std::experimental::'
for lfts_ns in ('fundamentals_v1', 'fundamentals_v2'):
-type_str = type_str.replace(expt_ns+lfts_ns+'::', expt_ns)
+type_str = type_str.replace(expt_ns + lfts_ns + '::', expt_ns)
fs_ns = expt_ns + 'filesystem::'
-type_str = type_str.replace(fs_ns+'v1::', fs_ns)
+type_str = type_str.replace(fs_ns + 'v1::', fs_ns)
return type_str
@@ -365,7 +364,8 @@ class UniquePointerPrinter:
return SmartPtrIterator(unique_ptr_get(self.val))
def to_string(self):
-return ('std::unique_ptr<%s>' %
(str(self.val.type.template_argument(0
+t = self.val.type.template_argument(0)
+return 'std::unique_ptr<{}>'.format(str(t))
def get_value_from_aligned_membuf(buf, valtype):
@@ -597,7 +597,8 @@ class StdBitIteratorPrinter:
def to_string(self):
if not self.val['_M_p']:
return 'non-dereferenceable iterator for std::vector'
-return bool(self.val['_M_p'].dereference() & (1 <<
self.val['_M_offset']))
+return bool(self.val['_M_p'].dereference()
+& (1 << self.val['_M_offset']))
class StdBitReferencePrinter:
@@ -1087,9 +1088,10 @@ class StdStringStreamPrinter:
self.val = val
self.typename = typename
-# Check if the stream was redirected:
-# This is essentially: val['_M_streambuf'] ==
val['_M_stringbuf'].address
-# However, GDB can't resolve the virtual inheritance, so we do that
manually
+# Check if the stream was redirected. This is essentially:
+# val['_M_streambuf'] != val['_M_stringbuf'].address
+# However, GDB can't resolve the virtual inheritance, so we do that
+# manually.
basetype = [f.type for f in val.type.fields() if f.is_base_class][0]
gdb.set_convenience_variable('__stream', val.cast(basetype).address)
self.streambuf = gdb.parse_and_eval('$__stream->rdbuf()')
@@ -1097,7 +1099,8 @@ class StdStringStreamPrinter:
def to_string(self):
if self.was_redirected:
-return "%s redirected to %s" % (self.typename,
self.streambuf.dereference())
+return "%s redirected to %s" % (
+self.typename, self.streambuf.dereference())
return self.val['_M_stringbuf']
def display_hint(self):
@@ -1309,8 +1312,9 @@ class