From patchwork Wed Oct 4 16:58:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 148428 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:254a:b0:403:3b70:6f57 with SMTP id hf10csp274856vqb; Wed, 4 Oct 2023 10:02:15 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEZGLiWPtecAMty0CKPNfNWruX5nKptoNHdeUIWTEtQWkhbSvLxjMeB2ciWA7slVPy2BDAS X-Received: by 2002:a17:907:7857:b0:9ad:ef31:6efc with SMTP id lb23-20020a170907785700b009adef316efcmr2505995ejc.21.1696438935509; Wed, 04 Oct 2023 10:02:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696438935; cv=none; d=google.com; s=arc-20160816; b=CVeOoQkU00kDjAblfb4RdSCgj5IXDHDfJW4EiZhc6wTlV70olOzyTEvoAC2KfYerBU msCgnqudjWb1WetlEpOkg4CaZlB4U5ahuGu2SXBg8zmXVFsvPT9ppEhkur7PPPsQoQRb iwDmzxYY4nR4La9HWlWAjjZhKLBP7eDvVhNA9PJvlwFMJUFWzSKFbz7KrnGsbcZgj27M H6NiIKAr1ezVLLaB8dLMicngUjqQCw0r9OYUAzmkQAdiWb2k6w1+ERtm5hLdId7jILC5 KdgguwOCTCisFjgqpEBphzkWeJ6ha/igV0HaFXdC+R2fLwUZUUajmhqpesJSK0qJS3Yd N3EQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature:dmarc-filter:delivered-to; bh=8HP1LrQmB+CqReu/wCxNRvYptf1uhMnM66UMmqGkWbE=; fh=Ogh3zaPUNpdNYHofIVNHsbX+D3lwaT1T8Jhe/MolwAA=; b=xcoMkB05dUdztkwRuIvNQ+HtKbU88dJRCeUjItIyvC7Q8z9Oy87N0Aby3i4XEd7M/8 az7i7Yb6MkNgH3vd0JAeo74vdyH/6+3mDtsXFTqEsDPrLC3B2c+TBx2UbKOLsyY7ZcRD QCwVf1KCybiLKr3zu/x32uxY1aQeNmcckANn5FlSp26GZnMWSObyOKp6Gkcpotk0luri Bojq2d5ma3WPzM5NmjRiQV61Fv8I6xsjShShxaZxDxKy7JUNny4UaaJt0dAjV5JpcI7L Vzjdhut9dh8kbwrBq7PLkaRrNVSwHiY8c7XstcGp1twVNczJHNcDtLN5zFpbDJCM3zE6 4k1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@adacore.com header.s=google header.b=b9CubyKd; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=adacore.com Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id k20-20020a170906681400b00992e21b04aasi1854331ejr.720.2023.10.04.10.02.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Oct 2023 10:02:15 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@adacore.com header.s=google header.b=b9CubyKd; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=adacore.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id F0BC3388B68B for ; Wed, 4 Oct 2023 16:59:45 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-il1-x12c.google.com (mail-il1-x12c.google.com [IPv6:2607:f8b0:4864:20::12c]) by sourceware.org (Postfix) with ESMTPS id 5968F385C6EF for ; Wed, 4 Oct 2023 16:58:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5968F385C6EF Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com Received: by mail-il1-x12c.google.com with SMTP id e9e14a558f8ab-3527428a402so223785ab.0 for ; Wed, 04 Oct 2023 09:58:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1696438725; x=1697043525; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=8HP1LrQmB+CqReu/wCxNRvYptf1uhMnM66UMmqGkWbE=; b=b9CubyKd0AxqbXg8cqTNbogL9ZwqPTZsfAa9ENrF/vS9VyaubtgwGBEY1WwvnXbhGn Tly4UorPdW0Cdsll47aQD0fCihwaIR97g6MzWd9Hp+cCwtL5VLRKj1iMKeXB6um2vXGk GMmiVBkfga2v/4YwiAsRuWI1hoGbeGunQdxS0gRPOeiH7394gdLK9n3vU8aCI1BK50KU cSR8qU+T2v+Nteb9iZMqFG4ew9rEH1YkexekSrW488JKU/eAumzHkeVWii5AINnaM6n5 +F2JaYpufewKXV0I6+WQOr2py60fNiQGgm+OX8ihOY8UyobaDEKmiqzmDJMdrpuckgtG MDCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696438725; x=1697043525; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8HP1LrQmB+CqReu/wCxNRvYptf1uhMnM66UMmqGkWbE=; b=RHD8wQv1xup/cKFesrtBZdVeeZ2khhVzceBvgQ1ndb4EkZHYVPAWOxh1xwWNbSCTM3 uKxXGB//6+3Od5WmM6i0hHlvydYEaZK+E3NNHX5agv8Gy7k9f+tlvB5zElJN0W3hdH/I HBJM0GmNzUMcf9I6PzIT67nNEJyk6Kp9R0XaOCCVsc53DexE9cpNUD0u4Ltu9GQ1xo/e jgrBAf4g6uU9VvIM+1WfqIXZPUqbzxy3Mij2ea+NohOQOhjnj5cmVCsuUDGi9iqX0u7n kFYvuphs5q95tcgHi+QoGlne3PQdge4RTUI4canNP9Ljb38rhg+p+DkKW1U94BiUmKZl JtvQ== X-Gm-Message-State: AOJu0Yz0RMxiiq/c3dOI69PcryfjE8PooUOR51Yn1YnDwQ4Vdb85hqG6 qMU9VCzDOVqmj2XsmvE9kJsOEs/CwYuZrLUkkeDwSg== X-Received: by 2002:a05:6e02:1988:b0:350:f956:91c4 with SMTP id g8-20020a056e02198800b00350f95691c4mr3509780ilf.4.1696438725110; Wed, 04 Oct 2023 09:58:45 -0700 (PDT) Received: from localhost.localdomain (71-211-130-31.hlrn.qwest.net. [71.211.130.31]) by smtp.gmail.com with ESMTPSA id e4-20020a02a784000000b0043cec02791bsm1066491jaj.96.2023.10.04.09.58.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Oct 2023 09:58:44 -0700 (PDT) From: Tom Tromey To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Tom Tromey Subject: [RFC 1/2] libstdc++: Use 'black' and 'isort' in pretty printers Date: Wed, 4 Oct 2023 10:58:31 -0600 Message-Id: <20231004165832.1750191-2-tromey@adacore.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231004165832.1750191-1-tromey@adacore.com> References: <20231004165832.1750191-1-tromey@adacore.com> MIME-Version: 1.0 X-Spam-Status: No, score=-11.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_FILL_THIS_FORM_SHORT autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778845153225046343 X-GMAIL-MSGID: 1778845153225046343 This changes libstdc++ to use the 'black' Python formatter. This formatter is somewhat standard and fairly comprehensive. FWIW we use this in gdb, mainly because it means we don't have to review Python code for formatting style. This patch also runs 'isort', which handles sorting the imports. A new pyproject.tom file is added, so after this you can: cd .../libstdc++/python black . isort . ... and have any changes reformatted. libstdc++-v3/ChangeLog: * pyproject.toml: New file. * python/libstdcxx/v6/printers.py: Reformat. * python/libstdcxx/v6/xmethods.py: Reformat. * python/libstdcxx/v6/__init__.py: Reformat. --- libstdc++-v3/python/libstdcxx/v6/__init__.py | 5 + libstdc++-v3/python/libstdcxx/v6/printers.py | 834 ++++++++++++------- libstdc++-v3/python/libstdcxx/v6/xmethods.py | 138 +-- libstdc++-v3/python/pyproject.toml | 6 + 4 files changed, 648 insertions(+), 335 deletions(-) create mode 100644 libstdc++-v3/python/pyproject.toml diff --git a/libstdc++-v3/python/libstdcxx/v6/__init__.py b/libstdc++-v3/python/libstdcxx/v6/__init__.py index 8b2cbc60a1b..cb0abf38e6b 100644 --- a/libstdc++-v3/python/libstdcxx/v6/__init__.py +++ b/libstdc++-v3/python/libstdcxx/v6/__init__.py @@ -13,19 +13,24 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . + # Load the xmethods if GDB supports them. def gdb_has_xmethods(): try: import gdb.xmethod + return True except ImportError: return False + def register_libstdcxx_printers(obj): # Load the pretty-printers. from .printers import register_libstdcxx_printers + register_libstdcxx_printers(obj) if gdb_has_xmethods(): from .xmethods import register_libstdcxx_xmethods + register_libstdcxx_xmethods(obj) diff --git a/libstdc++-v3/python/libstdcxx/v6/printers.py b/libstdc++-v3/python/libstdcxx/v6/printers.py index 7e16a49aeb0..e26b8b36013 100644 --- a/libstdc++-v3/python/libstdcxx/v6/printers.py +++ b/libstdc++-v3/python/libstdcxx/v6/printers.py @@ -15,12 +15,13 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -import gdb +import datetime +import errno import itertools import re import sys -import errno -import datetime + +import gdb # Python 2 + Python 3 compatibility code @@ -78,6 +79,7 @@ else: def dst(self, dt): return datetime.timedelta(0) + _utc_timezone = UTC() # Try to use the new-style pretty-printing if available. @@ -91,6 +93,7 @@ except ImportError: _use_type_printing = False try: import gdb.types + if hasattr(gdb.types, 'TypePrinter'): _use_type_printing = True except ImportError: @@ -148,6 +151,7 @@ def lookup_templ_spec(templ, *args): pass raise e + # 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): @@ -177,8 +181,9 @@ def lookup_node_type(nodename, containertype): except gdb.error: # For debug mode containers the node is in std::__cxx1998. if is_member_of_namespace(nodename, 'std'): - if is_member_of_namespace(containertype, 'std::__cxx1998', - 'std::__debug', '__gnu_debug'): + if is_member_of_namespace( + containertype, 'std::__cxx1998', 'std::__debug', '__gnu_debug' + ): nodename = nodename.replace('::', '::__cxx1998::', 1) try: return lookup_templ_spec(nodename, valtype) @@ -296,7 +301,9 @@ class SharedPointerPrinter(printer_base): state = 'expired, weak count %d' % weakcount else: state = 'use count %d, weak count %d' % ( - usecount, weakcount - 1) + usecount, + weakcount - 1, + ) return '%s<%s> (%s)' % (self._typename, targ, state) @@ -305,13 +312,15 @@ def _tuple_impl_get(val): bases = val.type.fields() if not bases[-1].is_base_class: raise ValueError( - "Unsupported implementation for std::tuple: %s" % str(val.type)) + "Unsupported implementation for std::tuple: %s" % str(val.type) + ) # Get the _Head_base base class: head_base = val.cast(bases[-1].type) fields = head_base.type.fields() if len(fields) == 0: raise ValueError( - "Unsupported implementation for std::tuple: %s" % str(val.type)) + "Unsupported implementation for std::tuple: %s" % str(val.type) + ) if fields[0].name == '_M_head_impl': # The tuple element is the _Head_base::_M_head_impl data member. return head_base['_M_head_impl'] @@ -321,7 +330,8 @@ def _tuple_impl_get(val): return head_base.cast(fields[0].type) else: raise ValueError( - "Unsupported implementation for std::tuple: %s" % str(val.type)) + "Unsupported implementation for std::tuple: %s" % str(val.type) + ) def tuple_get(n, val): @@ -345,14 +355,16 @@ def unique_ptr_get(val): # or within a data member of type __uniq_ptr_data. 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'): + if 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'): tuple_member = val['_M_t'] else: raise ValueError( - "Unsupported implementation for unique_ptr: %s" % str(impl_type)) + "Unsupported implementation for unique_ptr: %s" % str(impl_type) + ) return tuple_get(0, tuple_member) @@ -438,9 +450,12 @@ class NodeIteratorPrinter(printer_base): def to_string(self): if not self._val['_M_node']: - return 'non-dereferenceable iterator for std::%s' % (self._contname) - node = self._val['_M_node'].cast( - self._nodetype.pointer()).dereference() + return 'non-dereferenceable iterator for std::%s' % ( + self._contname + ) + node = ( + self._val['_M_node'].cast(self._nodetype.pointer()).dereference() + ) return str(get_value_from_list_node(node)) @@ -455,8 +470,9 @@ class StdFwdListIteratorPrinter(NodeIteratorPrinter): """Print std::forward_list::iterator.""" def __init__(self, typename, val): - NodeIteratorPrinter.__init__(self, typename, val, 'forward_list', - '_Fwd_list_node') + NodeIteratorPrinter.__init__( + self, typename, val, 'forward_list', '_Fwd_list_node' + ) class StdSlistPrinter(printer_base): @@ -503,8 +519,11 @@ class StdSlistIteratorPrinter(printer_base): if not self._val['_M_node']: return 'non-dereferenceable iterator for __gnu_cxx::slist' nodetype = lookup_node_type( - '__gnu_cxx::_Slist_node', self._val.type).pointer() - return str(self._val['_M_node'].cast(nodetype).dereference()['_M_data']) + '__gnu_cxx::_Slist_node', self._val.type + ).pointer() + return str( + self._val['_M_node'].cast(nodetype).dereference()['_M_data'] + ) class StdVectorPrinter(printer_base): @@ -550,13 +569,16 @@ class StdVectorPrinter(printer_base): def __init__(self, typename, val): self._typename = strip_versioned_namespace(typename) self._val = val - self._is_bool = val.type.template_argument( - 0).code == gdb.TYPE_CODE_BOOL + self._is_bool = ( + val.type.template_argument(0).code == gdb.TYPE_CODE_BOOL + ) def children(self): - return self._iterator(self._val['_M_impl']['_M_start'], - self._val['_M_impl']['_M_finish'], - self._is_bool) + return self._iterator( + self._val['_M_impl']['_M_start'], + self._val['_M_impl']['_M_finish'], + self._is_bool, + ) def to_string(self): start = self._val['_M_impl']['_M_start'] @@ -570,11 +592,17 @@ class StdVectorPrinter(printer_base): bl = 8 * itype.sizeof length = bl * (finish - start) + fo capacity = bl * (end - start) - return ('%s of length %d, capacity %d' - % (self._typename, int(length), int(capacity))) + return '%s of length %d, capacity %d' % ( + self._typename, + int(length), + int(capacity), + ) else: - return ('%s of length %d, capacity %d' - % (self._typename, int(finish - start), int(end - start))) + return '%s of length %d, capacity %d' % ( + self._typename, + int(finish - start), + int(end - start), + ) def display_hint(self): return 'array' @@ -601,8 +629,9 @@ class StdBitIteratorPrinter(printer_base): 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(printer_base): @@ -631,7 +660,8 @@ class StdTuplePrinter(printer_base): elif len(nodes) == 0: return False raise ValueError( - "Top of tuple tree does not consist of a single node.") + "Top of tuple tree does not consist of a single node." + ) def __init__(self, head): self._head = head @@ -659,7 +689,8 @@ class StdTuplePrinter(printer_base): # Check that this iteration has an expected structure. if len(nodes) > 2: raise ValueError( - "Cannot parse more than 2 nodes in a tuple tree.") + "Cannot parse more than 2 nodes in a tuple tree." + ) if len(nodes) == 1: # This is the last node of a GCC 5+ std::tuple. @@ -713,8 +744,10 @@ class StdStackOrQueuePrinter(printer_base): return self._visualizer.children() def to_string(self): - return '%s wrapping: %s' % (self._typename, - self._visualizer.to_string()) + return '%s wrapping: %s' % ( + self._typename, + self._visualizer.to_string(), + ) def display_hint(self): if hasattr(self._visualizer, 'display_hint'): @@ -777,6 +810,7 @@ def get_value_from_Rb_tree_node(node): pass raise ValueError("Unsupported implementation for %s" % str(node.type)) + # This is a pretty printer for std::_Rb_tree_iterator (which is # std::map::iterator), and has nothing to do with the RbtreeIterator # class above. @@ -852,8 +886,10 @@ class StdMapPrinter(printer_base): self._val = val def to_string(self): - return '%s with %s' % (self._typename, - num_elements(len(RbtreeIterator(self._val)))) + return '%s with %s' % ( + self._typename, + num_elements(len(RbtreeIterator(self._val))), + ) def children(self): node = lookup_node_type('_Rb_tree_node', self._val.type).pointer() @@ -891,8 +927,10 @@ class StdSetPrinter(printer_base): self._val = val def to_string(self): - return '%s with %s' % (self._typename, - num_elements(len(RbtreeIterator(self._val)))) + return '%s with %s' % ( + self._typename, + num_elements(len(RbtreeIterator(self._val))), + ) def children(self): node = lookup_node_type('_Rb_tree_node', self._val.type).pointer() @@ -1004,8 +1042,13 @@ class StdDequePrinter(printer_base): def children(self): start = self._val['_M_impl']['_M_start'] end = self._val['_M_impl']['_M_finish'] - return self._iter(start['_M_node'], start['_M_cur'], start['_M_last'], - end['_M_cur'], self._buffer_size) + return self._iter( + start['_M_node'], + start['_M_cur'], + start['_M_last'], + end['_M_cur'], + self._buffer_size, + ) def display_hint(self): return 'array' @@ -1104,7 +1147,9 @@ class StdStringStreamPrinter(printer_base): def to_string(self): if self._was_redirected: return "%s redirected to %s" % ( - self._typename, self._streambuf.dereference()) + self._typename, + self._streambuf.dereference(), + ) return self._val['_M_stringbuf'] def display_hint(self): @@ -1150,8 +1195,11 @@ class StdHashtableIterator(Iterator): self._node = hashtable['_M_before_begin']['_M_nxt'] valtype = hashtable.type.template_argument(1) cached = hashtable.type.template_argument(9).template_argument(0) - node_type = lookup_templ_spec('std::__detail::_Hash_node', str(valtype), - 'true' if cached else 'false') + node_type = lookup_templ_spec( + 'std::__detail::_Hash_node', + str(valtype), + 'true' if cached else 'false', + ) self._node_type = node_type.pointer() def __iter__(self): @@ -1229,11 +1277,13 @@ class Tr1UnorderedMapPrinter(printer_base): # Map over the hash table and flatten the result. if self._typename.startswith('std::tr1'): data = self._flatten( - imap(self._format_one, Tr1HashtableIterator(self._hashtable()))) + imap(self._format_one, Tr1HashtableIterator(self._hashtable())) + ) # Zip the two iterators together. return izip(counter, data) data = self._flatten( - imap(self._format_one, StdHashtableIterator(self._hashtable()))) + imap(self._format_one, StdHashtableIterator(self._hashtable())) + ) # Zip the two iterators together. return izip(counter, data) @@ -1291,8 +1341,9 @@ class SingleObjContainerPrinter(printer_base): global _use_type_printing if not _use_type_printing: return str(type) - return gdb.types.apply_type_recognizers(gdb.types.get_type_recognizers(), - type) or str(type) + return gdb.types.apply_type_recognizers( + gdb.types.get_type_recognizers(), type + ) or str(type) class _contained(Iterator): def __init__(self, val): @@ -1316,8 +1367,9 @@ class SingleObjContainerPrinter(printer_base): return self._contained(self._contained_value) def display_hint(self): - if (hasattr(self._visualizer, 'children') - and hasattr(self._visualizer, 'display_hint')): + if hasattr(self._visualizer, 'children') and hasattr( + self._visualizer, 'display_hint' + ): # If contained value is a map we want to display in the same way. return self._visualizer.display_hint() return self._hint @@ -1352,8 +1404,12 @@ class StdExpAnyPrinter(SingleObjContainerPrinter): def __init__(self, typename, val): self._typename = strip_versioned_namespace(typename) - self._typename = re.sub(r'^std::experimental::fundamentals_v\d::', - 'std::experimental::', self._typename, 1) + self._typename = re.sub( + r'^std::experimental::fundamentals_v\d::', + 'std::experimental::', + self._typename, + 1, + ) self._val = val self._contained_type = None contained_value = None @@ -1363,7 +1419,8 @@ class StdExpAnyPrinter(SingleObjContainerPrinter): func = function_pointer_to_name(mgr) if not func: raise ValueError( - "Invalid function pointer in %s" % (self._typename)) + "Invalid function pointer in %s" % (self._typename) + ) # We want to use this regular expression: # T::_Manager_xxx<.*>::_S_manage\(T::_Op, const T\*, T::_Arg\*\) # where T is std::any or std::experimental::any. @@ -1377,7 +1434,8 @@ class StdExpAnyPrinter(SingleObjContainerPrinter): m = re.match(rx, func) if not m: raise ValueError( - "Unknown manager function in %s" % self._typename) + "Unknown manager function in %s" % self._typename + ) mgrname = m.group(1) # FIXME need to expand 'std::string' so that gdb.lookup_type works @@ -1413,9 +1471,11 @@ class StdExpAnyPrinter(SingleObjContainerPrinter): valptr = self._val['_M_storage']['_M_ptr'] else: raise ValueError( - "Unknown manager function in %s" % self._typename) + "Unknown manager function in %s" % self._typename + ) contained_value = valptr.cast( - self._contained_type.pointer()).dereference() + self._contained_type.pointer() + ).dereference() visualizer = gdb.default_visualizer(contained_value) super(StdExpAnyPrinter, self).__init__(contained_value, visualizer) @@ -1436,8 +1496,7 @@ class StdExpAnyPrinter(SingleObjContainerPrinter): strings = {str(gdb.lookup_type('std::string').strip_typedefs())} # So also consider all the other possible std::string types! s = 'basic_string, std::allocator >' - quals = ['std::', 'std::__cxx11::', - 'std::' + _versioned_namespace] + quals = ['std::', 'std::__cxx11::', 'std::' + _versioned_namespace] strings |= {q + s for q in quals} # set of unique strings return strings @@ -1449,7 +1508,10 @@ class StdExpOptionalPrinter(SingleObjContainerPrinter): typename = strip_versioned_namespace(typename) self._typename = re.sub( r'^std::(experimental::|)(fundamentals_v\d::|)(.*)', - r'std::\1\3', typename, 1) + r'std::\1\3', + typename, + 1, + ) payload = val['_M_payload'] if self._typename.startswith('std::experimental'): engaged = val['_M_engaged'] @@ -1466,14 +1528,17 @@ class StdExpOptionalPrinter(SingleObjContainerPrinter): if not engaged: contained_value = None super(StdExpOptionalPrinter, self).__init__( - contained_value, visualizer) + contained_value, visualizer + ) def to_string(self): if self._contained_value is None: return "%s [no contained value]" % self._typename if hasattr(self._visualizer, 'children'): - return "%s containing %s" % (self._typename, - self._visualizer.to_string()) + return "%s containing %s" % ( + self._typename, + self._visualizer.to_string(), + ) return self._typename @@ -1492,17 +1557,22 @@ class StdVariantPrinter(SingleObjContainerPrinter): self._contained_type = alternatives[int(self._index)] addr = val['_M_u']['_M_first']['_M_storage'].address contained_value = addr.cast( - self._contained_type.pointer()).dereference() + self._contained_type.pointer() + ).dereference() visualizer = gdb.default_visualizer(contained_value) super(StdVariantPrinter, self).__init__( - contained_value, visualizer, 'array') + contained_value, visualizer, 'array' + ) def to_string(self): if self._contained_value is None: return "%s [no contained value]" % self._typename if hasattr(self._visualizer, 'children'): - return "%s [index %d] containing %s" % (self._typename, self._index, - self._visualizer.to_string()) + return "%s [index %d] containing %s" % ( + self._typename, + self._index, + self._visualizer.to_string(), + ) return "%s [index %d]" % (self._typename, self._index) @@ -1513,24 +1583,30 @@ class StdNodeHandlePrinter(SingleObjContainerPrinter): self._value_type = val.type.template_argument(1) nodetype = val.type.template_argument(2).template_argument(0) self._is_rb_tree_node = is_specialization_of( - nodetype.name, '_Rb_tree_node') + nodetype.name, '_Rb_tree_node' + ) self._is_map_node = val.type.template_argument(0) != self._value_type nodeptr = val['_M_ptr'] if nodeptr: if self._is_rb_tree_node: contained_value = get_value_from_Rb_tree_node( - nodeptr.dereference()) + nodeptr.dereference() + ) else: - contained_value = get_value_from_aligned_membuf(nodeptr['_M_storage'], - self._value_type) + contained_value = get_value_from_aligned_membuf( + nodeptr['_M_storage'], self._value_type + ) visualizer = gdb.default_visualizer(contained_value) else: contained_value = None visualizer = None optalloc = val['_M_alloc'] - self._alloc = optalloc['_M_payload'] if optalloc['_M_engaged'] else None - super(StdNodeHandlePrinter, self).__init__(contained_value, visualizer, - 'array') + self._alloc = ( + optalloc['_M_payload'] if optalloc['_M_engaged'] else None + ) + super(StdNodeHandlePrinter, self).__init__( + contained_value, visualizer, 'array' + ) def to_string(self): desc = 'node handle for ' @@ -1662,7 +1738,7 @@ class StdPathPrinter(printer_base): char_type = gdb.lookup_type('char') impl = impl.cast(int_type.pointer()) size = impl.dereference() - #self._capacity = (impl + 1).dereference() + # self._capacity = (impl + 1).dereference() if hasattr(gdb.Type, 'alignof'): sizeof_Impl = max(2 * int_type.sizeof, cmpt_type.alignof) else: @@ -1732,7 +1808,7 @@ class StdCmpCatPrinter(printer_base): """Print a comparison category object.""" def __init__(self, typename, val): - self._typename = typename[typename.rfind(':') + 1:] + self._typename = typename[typename.rfind(':') + 1 :] self._val = val['_M_value'] def to_string(self): @@ -1756,6 +1832,7 @@ class StdErrorCodePrinter(printer_base): if StdErrorCodePrinter._system_is_posix is None: try: import posix + StdErrorCodePrinter._system_is_posix = True except ImportError: StdErrorCodePrinter._system_is_posix = False @@ -1846,8 +1923,10 @@ class StdErrorCodePrinter(printer_base): cat = self._val['_M_cat'] name, alt_name, enum, is_errno = self._category_info(cat) if value == 0: - default_cats = {'error_code': 'system', - 'error_condition': 'generic'} + default_cats = { + 'error_code': 'system', + 'error_condition': 'generic', + } if name == default_cats[self._unqualified_name(self._typename)]: return self._typename + ' = { }' # default-constructed value @@ -1880,14 +1959,21 @@ class StdRegexStatePrinter(printer_base): opcode = opcode[25:] next_id = self._val['_M_next'] - variants = {'repeat': 'alt', 'alternative': 'alt', - 'subexpr_begin': 'subexpr', 'subexpr_end': 'subexpr', - 'line_begin_assertion': None, 'line_end_assertion': None, - 'word_boundary': 'neg', 'subexpr_lookahead': 'neg', - 'backref': 'backref_index', - 'match': None, 'accept': None, - 'dummy': None, 'unknown': None - } + variants = { + 'repeat': 'alt', + 'alternative': 'alt', + 'subexpr_begin': 'subexpr', + 'subexpr_end': 'subexpr', + 'line_begin_assertion': None, + 'line_end_assertion': None, + 'word_boundary': 'neg', + 'subexpr_lookahead': 'neg', + 'backref': 'backref_index', + 'match': None, + 'accept': None, + 'dummy': None, + 'unknown': None, + } v = variants[opcode] s = "opcode={}, next={}".format(opcode, next_id) @@ -1963,8 +2049,9 @@ class StdAtomicPrinter(printer_base): self._value_type = self._val.type.template_argument(0) if self._value_type.tag is not None: typ = strip_versioned_namespace(self._value_type.tag) - if (typ.startswith('std::shared_ptr<') - or typ.startswith('std::weak_ptr<')): + if typ.startswith('std::shared_ptr<') or typ.startswith( + 'std::weak_ptr<' + ): impl = val['_M_impl'] self._shptr_printer = SharedPointerPrinter(typename, impl) self.children = self._shptr_children @@ -1991,6 +2078,7 @@ class StdAtomicPrinter(printer_base): class StdFormatArgsPrinter(printer_base): """Print a std::basic_format_args.""" + # TODO: add printer for basic_format_arg and print out children. # TODO: add printer for __format::_ArgStore. @@ -2068,8 +2156,10 @@ class StdChronoTimePointPrinter(printer_base): def _clock(self): clock = self._val.type.template_argument(0) name = strip_versioned_namespace(clock.name) - if name == 'std::chrono::_V2::system_clock' \ - or name == 'std::chrono::system_clock': + if ( + name == 'std::chrono::_V2::system_clock' + or name == 'std::chrono::system_clock' + ): return ('std::chrono::sys_time', 0) # XXX need to remove leap seconds from utc, gps, and tai if name == 'std::chrono::utc_clock': @@ -2120,11 +2210,32 @@ class StdChronoZonedTimePrinter(printer_base): return 'std::chrono::zoned_time = {{ {} {} }}'.format(zone, time) -months = [None, 'January', 'February', 'March', 'April', 'May', 'June', - 'July', 'August', 'September', 'October', 'November', 'December'] - -weekdays = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', - 'Saturday', 'Sunday'] +months = [ + None, + 'January', + 'February', + 'March', + 'April', + 'May', + 'June', + 'July', + 'August', + 'September', + 'October', + 'November', + 'December', +] + +weekdays = [ + 'Sunday', + 'Monday', + 'Tuesday', + 'Wednesday', + 'Thursday', + 'Friday', + 'Saturday', + 'Sunday', +] class StdChronoCalendarPrinter(printer_base): @@ -2180,8 +2291,9 @@ class StdChronoCalendarPrinter(printer_base): if typ.startswith('std::chrono::hh_mm_ss'): fract = '' if val['fractional_width'] != 0: - fract = '.{:0{}d}'.format(int(val['_M_ss']['_M_r']), - int(val['fractional_width'])) + fract = '.{:0{}d}'.format( + int(val['_M_ss']['_M_r']), int(val['fractional_width']) + ) h = int(val['_M_h']['__r']) m = int(val['_M_m']['__r']) s = int(val['_M_s']['__r']) @@ -2239,8 +2351,15 @@ class StdChronoTimeZoneRulePrinter(printer_base): on = self._val['on'] kind = on['kind'] month = months[on['month']] - suffixes = {1: 'st', 2: 'nd', 3: 'rd', - 21: 'st', 22: 'nd', 23: 'rd', 31: 'st'} + suffixes = { + 1: 'st', + 2: 'nd', + 3: 'rd', + 21: 'st', + 22: 'nd', + 23: 'rd', + 31: 'st', + } day = on['day_of_month'] ordinal_day = '{}{}'.format(day, suffixes.get(day, 'th')) if kind == 0: # DayOfMonth @@ -2255,11 +2374,12 @@ class StdChronoTimeZoneRulePrinter(printer_base): else: direction = ('first', '>=') day = on['day_of_month'] - start = '{} {} {} {} {}'.format(direction[0], weekday, - direction[1], month, - ordinal_day) + start = '{} {} {} {} {}'.format( + direction[0], weekday, direction[1], month, ordinal_day + ) return 'time_zone rule {} from {} to {} starting on {}'.format( - self._val['name'], self._val['from'], self._val['to'], start) + self._val['name'], self._val['from'], self._val['to'], start + ) class StdLocalePrinter(printer_base): @@ -2292,7 +2412,7 @@ class StdLocalePrinter(printer_base): if len(uniq_names) == 1: name = n elif len(uniq_names) == 2: - n1, n2 = (uniq_names) + n1, n2 = uniq_names name_list = list(cat_names.values()) other = None if name_list.count(n1) == 1: @@ -2326,6 +2446,7 @@ class RxPrinter(object): return self._function(self.name, value) + # A pretty-printer that conforms to the "PrettyPrinter" protocol from # gdb.printing. It can also be used directly as an old-style printer. @@ -2344,7 +2465,8 @@ class Printer(object): # FIXME if not self._compiled_rx.match(name): raise ValueError( - 'libstdc++ programming error: "%s" does not match' % name) + 'libstdc++ programming error: "%s" does not match' % name + ) printer = RxPrinter(name, function) self._subprinters.append(printer) self._lookup[name] = printer @@ -2353,8 +2475,9 @@ class Printer(object): def add_version(self, base, name, function): self.add(base + name, function) if '__cxx11' not in base: - vbase = re.sub('^(std|__gnu_cxx)::', r'\g<0>%s' % - _versioned_namespace, base) + vbase = re.sub( + '^(std|__gnu_cxx)::', r'\g<0>%s' % _versioned_namespace, base + ) self.add(vbase + name, function) # Add a name using _GLIBCXX_BEGIN_NAMESPACE_CONTAINER. @@ -2468,7 +2591,7 @@ class TemplateTypePrinter(object): displayed_args.append(self._recognize_subtype(targ)) # This assumes no class templates in the nested-name-specifier: - template_name = type_obj.tag[0:type_obj.tag.find('<')] + template_name = type_obj.tag[0 : type_obj.tag.find('<')] template_name = strip_inline_namespaces(template_name) return template_name + '<' + ', '.join(displayed_args) + '>' @@ -2491,7 +2614,8 @@ class TemplateTypePrinter(object): return self._recognize_subtype(type_obj.target()) + '&&' type_str = gdb.types.apply_type_recognizers( - gdb.types.get_type_recognizers(), type_obj) + gdb.types.get_type_recognizers(), type_obj + ) if type_str: return type_str return str(type_obj) @@ -2528,8 +2652,9 @@ def add_one_template_type_printer(obj, name, defargs): # Add second type printer for same type in versioned namespace: ns = 'std::' + _versioned_namespace # PR 86112 Cannot use dict comprehension here: - defargs = dict((n, d.replace('std::', ns)) - for (n, d) in defargs.items()) + defargs = dict( + (n, d.replace('std::', ns)) for (n, d) in defargs.items() + ) printer = TemplateTypePrinter(ns + name, defargs) gdb.types.register_type_printer(obj, printer) @@ -2595,7 +2720,8 @@ class FilteringTypePrinter(object): try: self._type_obj = gdb.lookup_type( - self.name).strip_typedefs() + self.name + ).strip_typedefs() except: pass @@ -2638,27 +2764,45 @@ def register_type_printers(obj): return # Add type printers for typedefs std::string, std::wstring etc. - for ch in (('', 'char'), - ('w', 'wchar_t'), - ('u8', 'char8_t'), - ('u16', 'char16_t'), - ('u32', 'char32_t')): + for ch in ( + ('', 'char'), + ('w', 'wchar_t'), + ('u8', 'char8_t'), + ('u16', 'char16_t'), + ('u32', 'char32_t'), + ): add_one_type_printer(obj, 'basic_string', ch[0] + 'string', ch[1]) - add_one_type_printer(obj, '__cxx11::basic_string', - ch[0] + 'string', ch[1]) + add_one_type_printer( + obj, '__cxx11::basic_string', ch[0] + 'string', ch[1] + ) # Typedefs for __cxx11::basic_string used to be in namespace __cxx11: - add_one_type_printer(obj, '__cxx11::basic_string', - '__cxx11::' + ch[0] + 'string', ch[1]) - add_one_type_printer(obj, 'basic_string_view', - ch[0] + 'string_view', ch[1]) + add_one_type_printer( + obj, '__cxx11::basic_string', '__cxx11::' + ch[0] + 'string', ch[1] + ) + add_one_type_printer( + obj, 'basic_string_view', ch[0] + 'string_view', ch[1] + ) # Add type printers for typedefs std::istream, std::wistream etc. for ch in (('', 'char'), ('w', 'wchar_t')): - for x in ('ios', 'streambuf', 'istream', 'ostream', 'iostream', - 'filebuf', 'ifstream', 'ofstream', 'fstream'): + for x in ( + 'ios', + 'streambuf', + 'istream', + 'ostream', + 'iostream', + 'filebuf', + 'ifstream', + 'ofstream', + 'fstream', + ): add_one_type_printer(obj, 'basic_' + x, ch[0] + x, ch[1]) - for x in ('stringbuf', 'istringstream', 'ostringstream', - 'stringstream'): + for x in ( + 'stringbuf', + 'istringstream', + 'ostringstream', + 'stringstream', + ): add_one_type_printer(obj, 'basic_' + x, ch[0] + x, ch[1]) # types are in __cxx11 namespace, but typedefs aren't: add_one_type_printer(obj, '__cxx11::basic_' + x, ch[0] + x, ch[1]) @@ -2666,11 +2810,13 @@ def register_type_printers(obj): # Add type printers for typedefs regex, wregex, cmatch, wcmatch etc. for abi in ('', '__cxx11::'): for ch in (('', 'char'), ('w', 'wchar_t')): - add_one_type_printer(obj, abi + 'basic_regex', - abi + ch[0] + 'regex', ch[1]) + add_one_type_printer( + obj, abi + 'basic_regex', abi + ch[0] + 'regex', ch[1] + ) for ch in ('c', 's', 'wc', 'ws'): add_one_type_printer( - obj, abi + 'match_results', abi + ch + 'match') + obj, abi + 'match_results', abi + ch + 'match' + ) for x in ('sub_match', 'regex_iterator', 'regex_token_iterator'): add_one_type_printer(obj, abi + x, abi + ch + x) @@ -2679,8 +2825,18 @@ def register_type_printers(obj): add_one_type_printer(obj, 'fpos', 'streampos') # Add type printers for typedefs. - for dur in ('nanoseconds', 'microseconds', 'milliseconds', 'seconds', - 'minutes', 'hours', 'days', 'weeks', 'years', 'months'): + for dur in ( + 'nanoseconds', + 'microseconds', + 'milliseconds', + 'seconds', + 'minutes', + 'hours', + 'days', + 'weeks', + 'years', + 'months', + ): add_one_type_printer(obj, 'chrono::duration', 'chrono::' + dur) # Add type printers for typedefs. @@ -2696,50 +2852,82 @@ def register_type_printers(obj): # Add type printers for experimental::basic_string_view typedefs. ns = 'experimental::fundamentals_v1::' - for ch in (('', 'char'), - ('w', 'wchar_t'), - ('u8', 'char8_t'), - ('u16', 'char16_t'), - ('u32', 'char32_t')): - add_one_type_printer(obj, ns + 'basic_string_view', - ns + ch[0] + 'string_view', ch[1]) + for ch in ( + ('', 'char'), + ('w', 'wchar_t'), + ('u8', 'char8_t'), + ('u16', 'char16_t'), + ('u32', 'char32_t'), + ): + add_one_type_printer( + obj, ns + 'basic_string_view', ns + ch[0] + 'string_view', ch[1] + ) # Do not show defaulted template arguments in class templates. - add_one_template_type_printer(obj, 'unique_ptr', - {1: 'std::default_delete<{0}>'}) + add_one_template_type_printer( + obj, 'unique_ptr', {1: 'std::default_delete<{0}>'} + ) add_one_template_type_printer(obj, 'deque', {1: 'std::allocator<{0}>'}) add_one_template_type_printer( - obj, 'forward_list', {1: 'std::allocator<{0}>'}) + obj, 'forward_list', {1: 'std::allocator<{0}>'} + ) add_one_template_type_printer(obj, 'list', {1: 'std::allocator<{0}>'}) add_one_template_type_printer( - obj, '__cxx11::list', {1: 'std::allocator<{0}>'}) + obj, '__cxx11::list', {1: 'std::allocator<{0}>'} + ) add_one_template_type_printer(obj, 'vector', {1: 'std::allocator<{0}>'}) - add_one_template_type_printer(obj, 'map', - {2: 'std::less<{0}>', - 3: 'std::allocator>'}) - add_one_template_type_printer(obj, 'multimap', - {2: 'std::less<{0}>', - 3: 'std::allocator>'}) - add_one_template_type_printer(obj, 'set', - {1: 'std::less<{0}>', 2: 'std::allocator<{0}>'}) - add_one_template_type_printer(obj, 'multiset', - {1: 'std::less<{0}>', 2: 'std::allocator<{0}>'}) - add_one_template_type_printer(obj, 'unordered_map', - {2: 'std::hash<{0}>', - 3: 'std::equal_to<{0}>', - 4: 'std::allocator>'}) - add_one_template_type_printer(obj, 'unordered_multimap', - {2: 'std::hash<{0}>', - 3: 'std::equal_to<{0}>', - 4: 'std::allocator>'}) - add_one_template_type_printer(obj, 'unordered_set', - {1: 'std::hash<{0}>', - 2: 'std::equal_to<{0}>', - 3: 'std::allocator<{0}>'}) - add_one_template_type_printer(obj, 'unordered_multiset', - {1: 'std::hash<{0}>', - 2: 'std::equal_to<{0}>', - 3: 'std::allocator<{0}>'}) + add_one_template_type_printer( + obj, + 'map', + {2: 'std::less<{0}>', 3: 'std::allocator>'}, + ) + add_one_template_type_printer( + obj, + 'multimap', + {2: 'std::less<{0}>', 3: 'std::allocator>'}, + ) + add_one_template_type_printer( + obj, 'set', {1: 'std::less<{0}>', 2: 'std::allocator<{0}>'} + ) + add_one_template_type_printer( + obj, 'multiset', {1: 'std::less<{0}>', 2: 'std::allocator<{0}>'} + ) + add_one_template_type_printer( + obj, + 'unordered_map', + { + 2: 'std::hash<{0}>', + 3: 'std::equal_to<{0}>', + 4: 'std::allocator>', + }, + ) + add_one_template_type_printer( + obj, + 'unordered_multimap', + { + 2: 'std::hash<{0}>', + 3: 'std::equal_to<{0}>', + 4: 'std::allocator>', + }, + ) + add_one_template_type_printer( + obj, + 'unordered_set', + { + 1: 'std::hash<{0}>', + 2: 'std::equal_to<{0}>', + 3: 'std::allocator<{0}>', + }, + ) + add_one_template_type_printer( + obj, + 'unordered_multiset', + { + 1: 'std::hash<{0}>', + 2: 'std::equal_to<{0}>', + 3: 'std::allocator<{0}>', + }, + ) def register_libstdcxx_printers(obj): @@ -2768,7 +2956,8 @@ def build_libstdcxx_dictionary(): # http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/a01847.html libstdcxx_printer.add_version('std::', 'basic_string', StdStringPrinter) libstdcxx_printer.add_version( - 'std::__cxx11::', 'basic_string', StdStringPrinter) + 'std::__cxx11::', 'basic_string', StdStringPrinter + ) libstdcxx_printer.add_container('std::', 'bitset', StdBitsetPrinter) libstdcxx_printer.add_container('std::', 'deque', StdDequePrinter) libstdcxx_printer.add_container('std::', 'list', StdListPrinter) @@ -2777,8 +2966,9 @@ def build_libstdcxx_dictionary(): libstdcxx_printer.add_container('std::', 'multimap', StdMapPrinter) libstdcxx_printer.add_container('std::', 'multiset', StdSetPrinter) libstdcxx_printer.add_version('std::', 'pair', StdPairPrinter) - libstdcxx_printer.add_version('std::', 'priority_queue', - StdStackOrQueuePrinter) + libstdcxx_printer.add_version( + 'std::', 'priority_queue', StdStackOrQueuePrinter + ) libstdcxx_printer.add_version('std::', 'queue', StdStackOrQueuePrinter) libstdcxx_printer.add_version('std::', 'tuple', StdTuplePrinter) libstdcxx_printer.add_container('std::', 'set', StdSetPrinter) @@ -2789,10 +2979,12 @@ def build_libstdcxx_dictionary(): libstdcxx_printer.add_version('std::', 'locale', StdLocalePrinter) if hasattr(gdb.Value, 'dynamic_type'): - libstdcxx_printer.add_version('std::', 'error_code', - StdErrorCodePrinter) - libstdcxx_printer.add_version('std::', 'error_condition', - StdErrorCodePrinter) + libstdcxx_printer.add_version( + 'std::', 'error_code', StdErrorCodePrinter + ) + libstdcxx_printer.add_version( + 'std::', 'error_condition', StdErrorCodePrinter + ) # Printer registrations for classes compiled with -D_GLIBCXX_DEBUG. libstdcxx_printer.add('std::__debug::bitset', StdBitsetPrinter) @@ -2808,119 +3000,173 @@ def build_libstdcxx_dictionary(): # For array - the default GDB pretty-printer seems reasonable. libstdcxx_printer.add_version('std::', 'shared_ptr', SharedPointerPrinter) libstdcxx_printer.add_version('std::', 'weak_ptr', SharedPointerPrinter) - libstdcxx_printer.add_container('std::', 'unordered_map', - Tr1UnorderedMapPrinter) - libstdcxx_printer.add_container('std::', 'unordered_set', - Tr1UnorderedSetPrinter) - libstdcxx_printer.add_container('std::', 'unordered_multimap', - Tr1UnorderedMapPrinter) - libstdcxx_printer.add_container('std::', 'unordered_multiset', - Tr1UnorderedSetPrinter) - libstdcxx_printer.add_container('std::', 'forward_list', - StdForwardListPrinter) + libstdcxx_printer.add_container( + 'std::', 'unordered_map', Tr1UnorderedMapPrinter + ) + libstdcxx_printer.add_container( + 'std::', 'unordered_set', Tr1UnorderedSetPrinter + ) + libstdcxx_printer.add_container( + 'std::', 'unordered_multimap', Tr1UnorderedMapPrinter + ) + libstdcxx_printer.add_container( + 'std::', 'unordered_multiset', Tr1UnorderedSetPrinter + ) + libstdcxx_printer.add_container( + 'std::', 'forward_list', StdForwardListPrinter + ) libstdcxx_printer.add_version( - 'std::tr1::', 'shared_ptr', SharedPointerPrinter) + 'std::tr1::', 'shared_ptr', SharedPointerPrinter + ) + libstdcxx_printer.add_version( + 'std::tr1::', 'weak_ptr', SharedPointerPrinter + ) + libstdcxx_printer.add_version( + 'std::tr1::', 'unordered_map', Tr1UnorderedMapPrinter + ) + libstdcxx_printer.add_version( + 'std::tr1::', 'unordered_set', Tr1UnorderedSetPrinter + ) + libstdcxx_printer.add_version( + 'std::tr1::', 'unordered_multimap', Tr1UnorderedMapPrinter + ) + libstdcxx_printer.add_version( + 'std::tr1::', 'unordered_multiset', Tr1UnorderedSetPrinter + ) + libstdcxx_printer.add_version( - 'std::tr1::', 'weak_ptr', SharedPointerPrinter) - libstdcxx_printer.add_version('std::tr1::', 'unordered_map', - Tr1UnorderedMapPrinter) - libstdcxx_printer.add_version('std::tr1::', 'unordered_set', - Tr1UnorderedSetPrinter) - libstdcxx_printer.add_version('std::tr1::', 'unordered_multimap', - Tr1UnorderedMapPrinter) - libstdcxx_printer.add_version('std::tr1::', 'unordered_multiset', - Tr1UnorderedSetPrinter) - - libstdcxx_printer.add_version('std::', 'initializer_list', - StdInitializerListPrinter) + 'std::', 'initializer_list', StdInitializerListPrinter + ) libstdcxx_printer.add_version('std::', 'atomic', StdAtomicPrinter) libstdcxx_printer.add_version( - 'std::', 'basic_stringbuf', StdStringBufPrinter) + 'std::', 'basic_stringbuf', StdStringBufPrinter + ) libstdcxx_printer.add_version( - 'std::__cxx11::', 'basic_stringbuf', StdStringBufPrinter) + 'std::__cxx11::', 'basic_stringbuf', StdStringBufPrinter + ) for sstream in ('istringstream', 'ostringstream', 'stringstream'): libstdcxx_printer.add_version( - 'std::', 'basic_' + sstream, StdStringStreamPrinter) + 'std::', 'basic_' + sstream, StdStringStreamPrinter + ) libstdcxx_printer.add_version( - 'std::__cxx11::', 'basic_' + sstream, StdStringStreamPrinter) + 'std::__cxx11::', 'basic_' + sstream, StdStringStreamPrinter + ) - libstdcxx_printer.add_version('std::chrono::', 'duration', - StdChronoDurationPrinter) - libstdcxx_printer.add_version('std::chrono::', 'time_point', - StdChronoTimePointPrinter) + libstdcxx_printer.add_version( + 'std::chrono::', 'duration', StdChronoDurationPrinter + ) + libstdcxx_printer.add_version( + 'std::chrono::', 'time_point', StdChronoTimePointPrinter + ) # std::regex components - libstdcxx_printer.add_version('std::__detail::', '_State', - StdRegexStatePrinter) + libstdcxx_printer.add_version( + 'std::__detail::', '_State', StdRegexStatePrinter + ) # These are the C++11 printer registrations for -D_GLIBCXX_DEBUG cases. # The tr1 namespace containers do not have any debug equivalents, # so do not register printers for them. - libstdcxx_printer.add('std::__debug::unordered_map', - Tr1UnorderedMapPrinter) - libstdcxx_printer.add('std::__debug::unordered_set', - Tr1UnorderedSetPrinter) - libstdcxx_printer.add('std::__debug::unordered_multimap', - Tr1UnorderedMapPrinter) - libstdcxx_printer.add('std::__debug::unordered_multiset', - Tr1UnorderedSetPrinter) - libstdcxx_printer.add('std::__debug::forward_list', - StdForwardListPrinter) + libstdcxx_printer.add( + 'std::__debug::unordered_map', Tr1UnorderedMapPrinter + ) + libstdcxx_printer.add( + 'std::__debug::unordered_set', Tr1UnorderedSetPrinter + ) + libstdcxx_printer.add( + 'std::__debug::unordered_multimap', Tr1UnorderedMapPrinter + ) + libstdcxx_printer.add( + 'std::__debug::unordered_multiset', Tr1UnorderedSetPrinter + ) + libstdcxx_printer.add('std::__debug::forward_list', StdForwardListPrinter) # Library Fundamentals TS components - libstdcxx_printer.add_version('std::experimental::fundamentals_v1::', - 'any', StdExpAnyPrinter) - libstdcxx_printer.add_version('std::experimental::fundamentals_v1::', - 'optional', StdExpOptionalPrinter) - libstdcxx_printer.add_version('std::experimental::fundamentals_v1::', - 'basic_string_view', StdExpStringViewPrinter) + libstdcxx_printer.add_version( + 'std::experimental::fundamentals_v1::', 'any', StdExpAnyPrinter + ) + libstdcxx_printer.add_version( + 'std::experimental::fundamentals_v1::', + 'optional', + StdExpOptionalPrinter, + ) + libstdcxx_printer.add_version( + 'std::experimental::fundamentals_v1::', + 'basic_string_view', + StdExpStringViewPrinter, + ) # Filesystem TS components - libstdcxx_printer.add_version('std::experimental::filesystem::v1::', - 'path', StdExpPathPrinter) - libstdcxx_printer.add_version('std::experimental::filesystem::v1::__cxx11::', - 'path', StdExpPathPrinter) - libstdcxx_printer.add_version('std::filesystem::', - 'path', StdPathPrinter) - libstdcxx_printer.add_version('std::filesystem::__cxx11::', - 'path', StdPathPrinter) + libstdcxx_printer.add_version( + 'std::experimental::filesystem::v1::', 'path', StdExpPathPrinter + ) + libstdcxx_printer.add_version( + 'std::experimental::filesystem::v1::__cxx11::', + 'path', + StdExpPathPrinter, + ) + libstdcxx_printer.add_version('std::filesystem::', 'path', StdPathPrinter) + libstdcxx_printer.add_version( + 'std::filesystem::__cxx11::', 'path', StdPathPrinter + ) # C++17 components - libstdcxx_printer.add_version('std::', - 'any', StdExpAnyPrinter) - libstdcxx_printer.add_version('std::', - 'optional', StdExpOptionalPrinter) - libstdcxx_printer.add_version('std::', - 'basic_string_view', StdExpStringViewPrinter) - libstdcxx_printer.add_version('std::', - 'variant', StdVariantPrinter) - libstdcxx_printer.add_version('std::', - '_Node_handle', StdNodeHandlePrinter) + libstdcxx_printer.add_version('std::', 'any', StdExpAnyPrinter) + libstdcxx_printer.add_version('std::', 'optional', StdExpOptionalPrinter) + libstdcxx_printer.add_version( + 'std::', 'basic_string_view', StdExpStringViewPrinter + ) + libstdcxx_printer.add_version('std::', 'variant', StdVariantPrinter) + libstdcxx_printer.add_version( + 'std::', '_Node_handle', StdNodeHandlePrinter + ) # C++20 components libstdcxx_printer.add_version( - 'std::', 'partial_ordering', StdCmpCatPrinter) + 'std::', 'partial_ordering', StdCmpCatPrinter + ) libstdcxx_printer.add_version('std::', 'weak_ordering', StdCmpCatPrinter) libstdcxx_printer.add_version('std::', 'strong_ordering', StdCmpCatPrinter) libstdcxx_printer.add_version('std::', 'span', StdSpanPrinter) - libstdcxx_printer.add_version('std::', 'basic_format_args', - StdFormatArgsPrinter) - for c in ['day', 'month', 'year', 'weekday', 'weekday_indexed', 'weekday_last', - 'month_day', 'month_day_last', 'month_weekday', 'month_weekday_last', - 'year_month', 'year_month_day', 'year_month_day_last', - 'year_month_weekday', 'year_month_weekday_last', 'hh_mm_ss']: - libstdcxx_printer.add_version('std::chrono::', c, - StdChronoCalendarPrinter) - libstdcxx_printer.add_version('std::chrono::', 'time_zone', - StdChronoTimeZonePrinter) - libstdcxx_printer.add_version('std::chrono::', 'time_zone_link', - StdChronoTimeZonePrinter) - libstdcxx_printer.add_version('std::chrono::', 'zoned_time', - StdChronoZonedTimePrinter) - libstdcxx_printer.add_version('std::chrono::', 'leap_second', - StdChronoLeapSecondPrinter) libstdcxx_printer.add_version( - 'std::chrono::', 'tzdb', StdChronoTzdbPrinter) + 'std::', 'basic_format_args', StdFormatArgsPrinter + ) + for c in [ + 'day', + 'month', + 'year', + 'weekday', + 'weekday_indexed', + 'weekday_last', + 'month_day', + 'month_day_last', + 'month_weekday', + 'month_weekday_last', + 'year_month', + 'year_month_day', + 'year_month_day_last', + 'year_month_weekday', + 'year_month_weekday_last', + 'hh_mm_ss', + ]: + libstdcxx_printer.add_version( + 'std::chrono::', c, StdChronoCalendarPrinter + ) + libstdcxx_printer.add_version( + 'std::chrono::', 'time_zone', StdChronoTimeZonePrinter + ) + libstdcxx_printer.add_version( + 'std::chrono::', 'time_zone_link', StdChronoTimeZonePrinter + ) + libstdcxx_printer.add_version( + 'std::chrono::', 'zoned_time', StdChronoZonedTimePrinter + ) + libstdcxx_printer.add_version( + 'std::chrono::', 'leap_second', StdChronoLeapSecondPrinter + ) + libstdcxx_printer.add_version( + 'std::chrono::', 'tzdb', StdChronoTzdbPrinter + ) # libstdcxx_printer.add_version('std::chrono::(anonymous namespace)', 'Rule', # StdChronoTimeZoneRulePrinter) @@ -2930,37 +3176,51 @@ def build_libstdcxx_dictionary(): if True: # These shouldn't be necessary, if GDB "print *i" worked. # But it often doesn't, so here they are. - libstdcxx_printer.add_container('std::', '_List_iterator', - StdListIteratorPrinter) - libstdcxx_printer.add_container('std::', '_List_const_iterator', - StdListIteratorPrinter) - libstdcxx_printer.add_version('std::', '_Rb_tree_iterator', - StdRbtreeIteratorPrinter) - libstdcxx_printer.add_version('std::', '_Rb_tree_const_iterator', - StdRbtreeIteratorPrinter) - libstdcxx_printer.add_container('std::', '_Deque_iterator', - StdDequeIteratorPrinter) - libstdcxx_printer.add_container('std::', '_Deque_const_iterator', - StdDequeIteratorPrinter) - libstdcxx_printer.add_version('__gnu_cxx::', '__normal_iterator', - StdVectorIteratorPrinter) - libstdcxx_printer.add_container('std::', '_Bit_iterator', - StdBitIteratorPrinter) - libstdcxx_printer.add_container('std::', '_Bit_const_iterator', - StdBitIteratorPrinter) - libstdcxx_printer.add_container('std::', '_Bit_reference', - StdBitReferencePrinter) - libstdcxx_printer.add_version('__gnu_cxx::', '_Slist_iterator', - StdSlistIteratorPrinter) - libstdcxx_printer.add_container('std::', '_Fwd_list_iterator', - StdFwdListIteratorPrinter) - libstdcxx_printer.add_container('std::', '_Fwd_list_const_iterator', - StdFwdListIteratorPrinter) + libstdcxx_printer.add_container( + 'std::', '_List_iterator', StdListIteratorPrinter + ) + libstdcxx_printer.add_container( + 'std::', '_List_const_iterator', StdListIteratorPrinter + ) + libstdcxx_printer.add_version( + 'std::', '_Rb_tree_iterator', StdRbtreeIteratorPrinter + ) + libstdcxx_printer.add_version( + 'std::', '_Rb_tree_const_iterator', StdRbtreeIteratorPrinter + ) + libstdcxx_printer.add_container( + 'std::', '_Deque_iterator', StdDequeIteratorPrinter + ) + libstdcxx_printer.add_container( + 'std::', '_Deque_const_iterator', StdDequeIteratorPrinter + ) + libstdcxx_printer.add_version( + '__gnu_cxx::', '__normal_iterator', StdVectorIteratorPrinter + ) + libstdcxx_printer.add_container( + 'std::', '_Bit_iterator', StdBitIteratorPrinter + ) + libstdcxx_printer.add_container( + 'std::', '_Bit_const_iterator', StdBitIteratorPrinter + ) + libstdcxx_printer.add_container( + 'std::', '_Bit_reference', StdBitReferencePrinter + ) + libstdcxx_printer.add_version( + '__gnu_cxx::', '_Slist_iterator', StdSlistIteratorPrinter + ) + libstdcxx_printer.add_container( + 'std::', '_Fwd_list_iterator', StdFwdListIteratorPrinter + ) + libstdcxx_printer.add_container( + 'std::', '_Fwd_list_const_iterator', StdFwdListIteratorPrinter + ) # Debug (compiled with -D_GLIBCXX_DEBUG) printer # registrations. - libstdcxx_printer.add('__gnu_debug::_Safe_iterator', - StdDebugIteratorPrinter) + libstdcxx_printer.add( + '__gnu_debug::_Safe_iterator', StdDebugIteratorPrinter + ) build_libstdcxx_dictionary() diff --git a/libstdc++-v3/python/libstdcxx/v6/xmethods.py b/libstdc++-v3/python/libstdcxx/v6/xmethods.py index 42e60eb57b1..b9b32927e56 100644 --- a/libstdc++-v3/python/libstdcxx/v6/xmethods.py +++ b/libstdc++-v3/python/libstdcxx/v6/xmethods.py @@ -15,9 +15,10 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +import re + import gdb import gdb.xmethod -import re matcher_name_prefix = 'libstdc++::' @@ -25,11 +26,14 @@ matcher_name_prefix = 'libstdc++::' def get_bool_type(): return gdb.lookup_type('bool') + def get_std_size_type(): return gdb.lookup_type('std::size_t') + _versioned_namespace = '__8::' + def is_specialization_of(x, template_name): """ Test whether a type is a specialization of the named class template. @@ -42,11 +46,13 @@ def is_specialization_of(x, template_name): template_name = '(%s)?%s' % (_versioned_namespace, template_name) return re.match(r'^std::(__\d::)?%s<.*>$' % template_name, x) is not None + class LibStdCxxXMethod(gdb.xmethod.XMethod): def __init__(self, name, worker_class): gdb.xmethod.XMethod.__init__(self, name) self.worker_class = worker_class + # Xmethods for std::array @@ -85,7 +91,7 @@ class ArrayEmptyWorker(ArrayWorkerBase): return get_bool_type() def __call__(self, obj): - return (int(self._size) == 0) + return int(self._size) == 0 class ArrayFrontWorker(ArrayWorkerBase): @@ -134,8 +140,10 @@ class ArrayAtWorker(ArrayWorkerBase): def __call__(self, obj, index): if int(index) >= int(self._size): - raise IndexError('Array index "%d" should not be >= %d.' % - ((int(index), self._size))) + raise IndexError( + 'Array index "%d" should not be >= %d.' + % ((int(index), self._size)) + ) return obj['_M_elems'][index] @@ -158,8 +166,9 @@ class ArraySubscriptWorker(ArrayWorkerBase): class ArrayMethodsMatcher(gdb.xmethod.XMethodMatcher): def __init__(self): - gdb.xmethod.XMethodMatcher.__init__(self, - matcher_name_prefix + 'array') + gdb.xmethod.XMethodMatcher.__init__( + self, matcher_name_prefix + 'array' + ) self._method_dict = { 'size': LibStdCxxXMethod('size', ArraySizeWorker), 'empty': LibStdCxxXMethod('empty', ArrayEmptyWorker), @@ -213,8 +222,10 @@ class DequeEmptyWorker(DequeWorkerBase): return get_bool_type() def __call__(self, obj): - return (obj['_M_impl']['_M_start']['_M_cur'] == - obj['_M_impl']['_M_finish']['_M_cur']) + return ( + obj['_M_impl']['_M_start']['_M_cur'] + == obj['_M_impl']['_M_finish']['_M_cur'] + ) class DequeSizeWorker(DequeWorkerBase): @@ -247,8 +258,10 @@ class DequeBackWorker(DequeWorkerBase): return self._val_type def __call__(self, obj): - if (obj['_M_impl']['_M_finish']['_M_cur'] == - obj['_M_impl']['_M_finish']['_M_first']): + if ( + obj['_M_impl']['_M_finish']['_M_cur'] + == obj['_M_impl']['_M_finish']['_M_first'] + ): prev_node = obj['_M_impl']['_M_finish']['_M_node'] - 1 return prev_node[0][self._bufsize - 1] else: @@ -276,23 +289,26 @@ class DequeAtWorker(DequeWorkerBase): def __call__(self, obj, index): deque_size = int(self.size(obj)) if int(index) >= deque_size: - raise IndexError('Deque index "%d" should not be >= %d.' % - (int(index), deque_size)) + raise IndexError( + 'Deque index "%d" should not be >= %d.' + % (int(index), deque_size) + ) else: return self.index(obj, index) class DequeMethodsMatcher(gdb.xmethod.XMethodMatcher): def __init__(self): - gdb.xmethod.XMethodMatcher.__init__(self, - matcher_name_prefix + 'deque') + gdb.xmethod.XMethodMatcher.__init__( + self, matcher_name_prefix + 'deque' + ) self._method_dict = { 'empty': LibStdCxxXMethod('empty', DequeEmptyWorker), 'size': LibStdCxxXMethod('size', DequeSizeWorker), 'front': LibStdCxxXMethod('front', DequeFrontWorker), 'back': LibStdCxxXMethod('back', DequeBackWorker), 'operator[]': LibStdCxxXMethod('operator[]', DequeSubscriptWorker), - 'at': LibStdCxxXMethod('at', DequeAtWorker) + 'at': LibStdCxxXMethod('at', DequeAtWorker), } self.methods = [self._method_dict[m] for m in self._method_dict] @@ -304,6 +320,7 @@ class DequeMethodsMatcher(gdb.xmethod.XMethodMatcher): return None return method.worker_class(class_type.template_argument(0)) + # Xmethods for std::forward_list @@ -340,7 +357,7 @@ class ForwardListMethodsMatcher(gdb.xmethod.XMethodMatcher): gdb.xmethod.XMethodMatcher.__init__(self, matcher_name) self._method_dict = { 'empty': LibStdCxxXMethod('empty', ForwardListEmptyWorker), - 'front': LibStdCxxXMethod('front', ForwardListFrontWorker) + 'front': LibStdCxxXMethod('front', ForwardListFrontWorker), } self.methods = [self._method_dict[m] for m in self._method_dict] @@ -354,6 +371,7 @@ class ForwardListMethodsMatcher(gdb.xmethod.XMethodMatcher): node_type = gdb.lookup_type(str(class_type) + '::_Node').pointer() return method.worker_class(val_type, node_type) + # Xmethods for std::list @@ -421,13 +439,12 @@ class ListBackWorker(ListWorkerBase): class ListMethodsMatcher(gdb.xmethod.XMethodMatcher): def __init__(self): - gdb.xmethod.XMethodMatcher.__init__(self, - matcher_name_prefix + 'list') + gdb.xmethod.XMethodMatcher.__init__(self, matcher_name_prefix + 'list') self._method_dict = { 'empty': LibStdCxxXMethod('empty', ListEmptyWorker), 'size': LibStdCxxXMethod('size', ListSizeWorker), 'front': LibStdCxxXMethod('front', ListFrontWorker), - 'back': LibStdCxxXMethod('back', ListBackWorker) + 'back': LibStdCxxXMethod('back', ListBackWorker), } self.methods = [self._method_dict[m] for m in self._method_dict] @@ -441,6 +458,7 @@ class ListMethodsMatcher(gdb.xmethod.XMethodMatcher): node_type = gdb.lookup_type(str(class_type) + '::_Node').pointer() return method.worker_class(val_type, node_type) + # Xmethods for std::vector @@ -523,8 +541,9 @@ class VectorAtWorker(VectorWorkerBase): def __call__(self, obj, index): size = int(self.size(obj)) if int(index) >= size: - raise IndexError('Vector index "%d" should not be >= %d.' % - ((int(index), size))) + raise IndexError( + 'Vector index "%d" should not be >= %d.' % ((int(index), size)) + ) return self.get(obj, int(index)) @@ -541,16 +560,18 @@ class VectorSubscriptWorker(VectorWorkerBase): class VectorMethodsMatcher(gdb.xmethod.XMethodMatcher): def __init__(self): - gdb.xmethod.XMethodMatcher.__init__(self, - matcher_name_prefix + 'vector') + gdb.xmethod.XMethodMatcher.__init__( + self, matcher_name_prefix + 'vector' + ) self._method_dict = { 'size': LibStdCxxXMethod('size', VectorSizeWorker), 'empty': LibStdCxxXMethod('empty', VectorEmptyWorker), 'front': LibStdCxxXMethod('front', VectorFrontWorker), 'back': LibStdCxxXMethod('back', VectorBackWorker), 'at': LibStdCxxXMethod('at', VectorAtWorker), - 'operator[]': LibStdCxxXMethod('operator[]', - VectorSubscriptWorker), + 'operator[]': LibStdCxxXMethod( + 'operator[]', VectorSubscriptWorker + ), } self.methods = [self._method_dict[m] for m in self._method_dict] @@ -562,6 +583,7 @@ class VectorMethodsMatcher(gdb.xmethod.XMethodMatcher): return None return method.worker_class(class_type.template_argument(0)) + # Xmethods for associative containers @@ -597,13 +619,13 @@ class AssociativeContainerSizeWorker(AssociativeContainerWorkerBase): class AssociativeContainerMethodsMatcher(gdb.xmethod.XMethodMatcher): def __init__(self, name): - gdb.xmethod.XMethodMatcher.__init__(self, - matcher_name_prefix + name) + gdb.xmethod.XMethodMatcher.__init__(self, matcher_name_prefix + name) self._name = name self._method_dict = { 'size': LibStdCxxXMethod('size', AssociativeContainerSizeWorker), - 'empty': LibStdCxxXMethod('empty', - AssociativeContainerEmptyWorker), + 'empty': LibStdCxxXMethod( + 'empty', AssociativeContainerEmptyWorker + ), } self.methods = [self._method_dict[m] for m in self._method_dict] @@ -616,6 +638,7 @@ class AssociativeContainerMethodsMatcher(gdb.xmethod.XMethodMatcher): unordered = 'unordered' in self._name return method.worker_class(unordered) + # Xmethods for std::unique_ptr @@ -651,7 +674,7 @@ class UniquePtrGetWorker(gdb.xmethod.XMethodWorker): 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 + 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'] @@ -700,13 +723,16 @@ class UniquePtrSubscriptWorker(UniquePtrGetWorker): class UniquePtrMethodsMatcher(gdb.xmethod.XMethodMatcher): def __init__(self): - gdb.xmethod.XMethodMatcher.__init__(self, - matcher_name_prefix + 'unique_ptr') + gdb.xmethod.XMethodMatcher.__init__( + self, matcher_name_prefix + 'unique_ptr' + ) self._method_dict = { 'get': LibStdCxxXMethod('get', UniquePtrGetWorker), 'operator->': LibStdCxxXMethod('operator->', UniquePtrGetWorker), 'operator*': LibStdCxxXMethod('operator*', UniquePtrDerefWorker), - 'operator[]': LibStdCxxXMethod('operator[]', UniquePtrSubscriptWorker), + 'operator[]': LibStdCxxXMethod( + 'operator[]', UniquePtrSubscriptWorker + ), } self.methods = [self._method_dict[m] for m in self._method_dict] @@ -721,6 +747,7 @@ class UniquePtrMethodsMatcher(gdb.xmethod.XMethodMatcher): return worker return None + # Xmethods for std::shared_ptr @@ -787,8 +814,10 @@ class SharedPtrSubscriptWorker(SharedPtrGetWorker): # Check bounds if _elem_type is an array of known bound m = re.match(r'.*\[(\d+)]$', str(self._elem_type)) if m and index >= int(m.group(1)): - raise IndexError('shared_ptr<%s> index "%d" should not be >= %d.' % - (self._elem_type, int(index), int(m.group(1)))) + raise IndexError( + 'shared_ptr<%s> index "%d" should not be >= %d.' + % (self._elem_type, int(index), int(m.group(1))) + ) return SharedPtrGetWorker.__call__(self, obj)[index] @@ -827,14 +856,19 @@ class SharedPtrUniqueWorker(SharedPtrUseCountWorker): class SharedPtrMethodsMatcher(gdb.xmethod.XMethodMatcher): def __init__(self): - gdb.xmethod.XMethodMatcher.__init__(self, - matcher_name_prefix + 'shared_ptr') + gdb.xmethod.XMethodMatcher.__init__( + self, matcher_name_prefix + 'shared_ptr' + ) self._method_dict = { 'get': LibStdCxxXMethod('get', SharedPtrGetWorker), 'operator->': LibStdCxxXMethod('operator->', SharedPtrGetWorker), 'operator*': LibStdCxxXMethod('operator*', SharedPtrDerefWorker), - 'operator[]': LibStdCxxXMethod('operator[]', SharedPtrSubscriptWorker), - 'use_count': LibStdCxxXMethod('use_count', SharedPtrUseCountWorker), + 'operator[]': LibStdCxxXMethod( + 'operator[]', SharedPtrSubscriptWorker + ), + 'use_count': LibStdCxxXMethod( + 'use_count', SharedPtrUseCountWorker + ), 'unique': LibStdCxxXMethod('unique', SharedPtrUniqueWorker), } self.methods = [self._method_dict[m] for m in self._method_dict] @@ -849,7 +883,7 @@ class SharedPtrMethodsMatcher(gdb.xmethod.XMethodMatcher): if worker._supports(method_name): return worker return None - + def register_libstdcxx_xmethods(locus): gdb.xmethod.register_xmethod_matcher(locus, ArrayMethodsMatcher()) @@ -858,20 +892,28 @@ def register_libstdcxx_xmethods(locus): gdb.xmethod.register_xmethod_matcher(locus, ListMethodsMatcher()) gdb.xmethod.register_xmethod_matcher(locus, VectorMethodsMatcher()) gdb.xmethod.register_xmethod_matcher( - locus, AssociativeContainerMethodsMatcher('set')) + locus, AssociativeContainerMethodsMatcher('set') + ) gdb.xmethod.register_xmethod_matcher( - locus, AssociativeContainerMethodsMatcher('map')) + locus, AssociativeContainerMethodsMatcher('map') + ) gdb.xmethod.register_xmethod_matcher( - locus, AssociativeContainerMethodsMatcher('multiset')) + locus, AssociativeContainerMethodsMatcher('multiset') + ) gdb.xmethod.register_xmethod_matcher( - locus, AssociativeContainerMethodsMatcher('multimap')) + locus, AssociativeContainerMethodsMatcher('multimap') + ) gdb.xmethod.register_xmethod_matcher( - locus, AssociativeContainerMethodsMatcher('unordered_set')) + locus, AssociativeContainerMethodsMatcher('unordered_set') + ) gdb.xmethod.register_xmethod_matcher( - locus, AssociativeContainerMethodsMatcher('unordered_map')) + locus, AssociativeContainerMethodsMatcher('unordered_map') + ) gdb.xmethod.register_xmethod_matcher( - locus, AssociativeContainerMethodsMatcher('unordered_multiset')) + locus, AssociativeContainerMethodsMatcher('unordered_multiset') + ) gdb.xmethod.register_xmethod_matcher( - locus, AssociativeContainerMethodsMatcher('unordered_multimap')) + locus, AssociativeContainerMethodsMatcher('unordered_multimap') + ) gdb.xmethod.register_xmethod_matcher(locus, UniquePtrMethodsMatcher()) gdb.xmethod.register_xmethod_matcher(locus, SharedPtrMethodsMatcher()) diff --git a/libstdc++-v3/python/pyproject.toml b/libstdc++-v3/python/pyproject.toml new file mode 100644 index 00000000000..dd4c4bf5df1 --- /dev/null +++ b/libstdc++-v3/python/pyproject.toml @@ -0,0 +1,6 @@ +[tool.black] +line-length = 79 +skip-string-normalization = true + +[tool.isort] +profile = "black"