From patchwork Thu Oct 6 17:38:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Fran=C3=A7ois_Dumont?= X-Patchwork-Id: 1789 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp429783wrs; Thu, 6 Oct 2022 10:39:02 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5W/ZwSpdIeF7RnALyi9uxmjkKkxRlpJgX0TCnPCykW5EY/RaOrRcCTUPu8jkqcSPWok4zG X-Received: by 2002:a17:907:60ca:b0:781:e17d:3698 with SMTP id hv10-20020a17090760ca00b00781e17d3698mr833370ejc.218.1665077941795; Thu, 06 Oct 2022 10:39:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665077941; cv=none; d=google.com; s=arc-20160816; b=JoqsfvSwtlAzoIb6Mbuk+yDsyvO1dRANCVMNrtPrygBS46HY8EPWtbx4JcBS/LANZd 7XV3PipUVofmdBxxxPLmctz9JQZ5g/DGs4ICMl443fBbqnv10WMad9jt6ttcMqNSRc8n c3uDO+jxHJZUmhgSOB2hX5gjvZ+YPHA0WiTNbPHgVWHklAZ2cXfjBVU4YfNfuChGMAkO BjRbIplgtm1kRtTxjf+Oc/eQ9xF2R8R9rvq5fNGUFLKdQXlpGjAz58FeTz4+jB9gRPUX xRXR4+LxtwHUI/z1+M95QWnTHbnGu13LouZJlKW5QPkHHqfK4XD6IMjRdpm8mm9u/SAM g+WQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:reply-to:from:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :content-language:to:subject:user-agent:mime-version:date:message-id :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=+HDvEAzz3WNvF71Uv7L3EvcQCrqLpo+giyMrAvBD1yY=; b=LyJ/nK4SqG9Ob8ESguH1jlRxygPbA3++LwZ7k/pqbTWlSeDC9M1Nx+Iam8KRMAxW1u nRNcUgtY6BV0h48A8wGzpDIdZyYOBf1c9J9LxgefRnnfpo7o0vPuRJ4txmFChcmZDZWj 1JlL54Q0mKFViOzZ82u2sivKR3TpGAz3NKWxIrjiBR0Ni+8fc5ZA2CxRsohmB9S8PQyT qZSKlSN/bqvPw1E8soAdLzkp/LsZ67AY7K72Z0FEKiJtWhYN7sptF2QAykFpTCyq6VjM umXfEAS8MQwM8HcjAeQyG55yuauu0+J+Ir9rUy8pO3mzIQTcfzPMd7XEmjyaoLL67eYe gCCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=almzY005; 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=gnu.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id dm20-20020a170907949400b0077d1df3967asi13693815ejc.563.2022.10.06.10.39.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Oct 2022 10:39:01 -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=@gcc.gnu.org header.s=default header.b=almzY005; 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=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B3796384B82D for ; Thu, 6 Oct 2022 17:39:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B3796384B82D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1665077940; bh=+HDvEAzz3WNvF71Uv7L3EvcQCrqLpo+giyMrAvBD1yY=; h=Date:Subject:To:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=almzY0058hGgCvb1ZNq7YWiJoOz4gqMURC9wOkbs5N2My0KdMlrfFfjHwoNQUGnGu oExDmpXFfOzXJ5lMU2lgDy06Cok3PF2LWHzFzheBp0Ot/FpxiYhVz/QH3+PhRcOXsm hDgc3TUBGsqcZOeVsPn+uXu2F3N6kkXjHIo0XwHw= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-ed1-x529.google.com (mail-ed1-x529.google.com [IPv6:2a00:1450:4864:20::529]) by sourceware.org (Postfix) with ESMTPS id CDF773858D37; Thu, 6 Oct 2022 17:38:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org CDF773858D37 Received: by mail-ed1-x529.google.com with SMTP id e18so3867380edj.3; Thu, 06 Oct 2022 10:38:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-language:cc:to:subject:from:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=+HDvEAzz3WNvF71Uv7L3EvcQCrqLpo+giyMrAvBD1yY=; b=J4bw5efLjTU57giDWi8hMoK2MCWHg6DRCOdYKVfYonh/GoFtIrbRTQLLjLPhAHUmIT 012seCyMAIiRfYYhTvte9wlhMmq3zWeDhZWzU7L7mV3BIS/nLSUccwEow3G1IpqA9SXf mD1gLe6Jnl+SI2efCeHpJXUhhwSUb2CB8xxvtMTkU8r63DCgiBup+YnB8IDAGTdCX/9t brjBdZmbxlCRilQJ0QBfNEHoFsOBcnpjnhxSQaFGMR/5ggGLrvGqCgiLy2r1Mbm5HuUF T7jMd/R18BhYz+72/da7rg1Ujn0qL2DtC96PJh3EFMG4L2HbTB//HP6o8Q5Yjq7cCSpw XSXw== X-Gm-Message-State: ACrzQf3V2PB03drF/CkxlV4dFFobmdd02G9uvHDOkNma0PcNH6Hvwv31 DjgnbxfhmqNNQyPUS5y2ur7IfIDiRic= X-Received: by 2002:a05:6402:14c9:b0:459:1a5b:6c47 with SMTP id f9-20020a05640214c900b004591a5b6c47mr899552edx.426.1665077894161; Thu, 06 Oct 2022 10:38:14 -0700 (PDT) Received: from [10.60.1.117] ([109.190.253.15]) by smtp.googlemail.com with ESMTPSA id bd18-20020a056402207200b00457e20cb2e4sm6213790edb.48.2022.10.06.10.38.12 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 06 Oct 2022 10:38:13 -0700 (PDT) Message-ID: <4d1dc3d4-e945-d283-964a-4dab3b3cb33e@gmail.com> Date: Thu, 6 Oct 2022 19:38:09 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: [PATCH] Fix gdb FilteringTypePrinter (again) To: "libstdc++@gcc.gnu.org" Content-Language: en-US X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00, BODY_8BITS, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: =?utf-8?q?Fran=C3=A7ois_Dumont_via_Gcc-patches?= From: =?utf-8?q?Fran=C3=A7ois_Dumont?= Reply-To: =?utf-8?q?Fran=C3=A7ois_Dumont?= Cc: gcc-patches Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1745960767978622968?= X-GMAIL-MSGID: =?utf-8?q?1745960767978622968?= Hi Looks like the previous patch was not enough. When using it in the context of a build without dual abi and versioned namespace I started having failures again. I guess I hadn't rebuild everything properly. This time I think the problem was in those lines:             if self.type_obj == type_obj:                 return strip_inline_namespaces(self.name) I've added a call to gdb.types.get_basic_type so that we do not compare a type with its typedef. Thanks for the pointer to the doc ! Doing so I eventually use your code Jonathan to make FilteringTypeFilter more specific to a given instantiation.     libstdc++: Fix gdb FilteringTypePrinter     Once we found a matching FilteringTypePrinter instance we look for the associated     typedef and check that the returned Python Type is equal to the Type to recognize.     But gdb Python Type includes properties to distinguish a typedef from the actual     type. So use gdb.types.get_basic_type to check if we are indeed on the same type.     Additionnaly enhance FilteringTypePrinter matching mecanism by introducing targ1 that,     if not None, will be used as the 1st template parameter.     libstdc++-v3/ChangeLog:             * python/libstdcxx/v6/printers.py (FilteringTypePrinter): Rename 'match' field             'template'. Add self.targ1 to specify the first template parameter of the instantiation             to match.             (add_one_type_printer): Add targ1 optional parameter, default to None.             Use gdb.types.get_basic_type to compare the type to recognize and the type             returned from the typedef lookup.             (register_type_printers): Adapt calls to add_one_type_printers. Tested under Linux x86_64 normal, version namespace with or without dual abi. François diff --git a/libstdc++-v3/python/libstdcxx/v6/printers.py b/libstdc++-v3/python/libstdcxx/v6/printers.py index 0fa7805183e..52339b247d8 100644 --- a/libstdc++-v3/python/libstdcxx/v6/printers.py +++ b/libstdc++-v3/python/libstdcxx/v6/printers.py @@ -2040,62 +2040,72 @@ def add_one_template_type_printer(obj, name, defargs): class FilteringTypePrinter(object): r""" - A type printer that uses typedef names for common template specializations. + A type printer that uses typedef names for common template instantiations. Args: - match (str): The class template to recognize. + template (str): The class template to recognize. name (str): The typedef-name that will be used instead. + targ1 (str): The first template argument. + If arg1 is provided (not None), only template instantiations with this type + as the first template argument, e.g. if template='basic_string is the same type as + e.g. for template='basic_istream', name='istream', if any instantiation of + std::basic_istream is the same type as std::istream then print it as + std::istream. + + e.g. for template='basic_istream', name='istream', targ1='char', if any + instantiation of std::basic_istream is the same type as std::istream then print it as std::istream. """ - def __init__(self, match, name): - self.match = match + def __init__(self, template, name, targ1): + self.template = template self.name = name + self.targ1 = targ1 self.enabled = True class _recognizer(object): "The recognizer class for FilteringTypePrinter." - def __init__(self, match, name): - self.match = match + def __init__(self, template, name, targ1): + self.template = template self.name = name + self.targ1 = targ1 self.type_obj = None def recognize(self, type_obj): """ - If type_obj starts with self.match and is the same type as + If type_obj starts with self.template and is the same type as self.name then return self.name, otherwise None. """ if type_obj.tag is None: return None if self.type_obj is None: - if not type_obj.tag.startswith(self.match): + if self.targ1 is not None: + if not type_obj.tag.startswith('{}<{}'.format(self.template, self.targ1)): + # Filter didn't match. + return None + elif not type_obj.tag.startswith(self.template): # Filter didn't match. return None + try: self.type_obj = gdb.lookup_type(self.name).strip_typedefs() except: pass - if self.type_obj == type_obj: - return strip_inline_namespaces(self.name) if self.type_obj is None: return None - # Workaround ambiguous typedefs matching both std:: and std::__cxx11:: symbols. - ambiguous = False - for ch in ('', 'w', 'u8', 'u16', 'u32'): - if self.name == 'std::' + ch + 'string': - ambiguous = True - break + if gdb.types.get_basic_type(self.type_obj) == gdb.types.get_basic_type(type_obj): + return strip_inline_namespaces(self.name) - if ambiguous: + # Workaround ambiguous typedefs matching both std:: and std::__cxx11:: symbols. + if self.template.split('::')[-1] == 'basic_string': if self.type_obj.tag.replace('__cxx11::', '') == type_obj.tag.replace('__cxx11::', ''): return strip_inline_namespaces(self.name) @@ -2103,14 +2113,14 @@ class FilteringTypePrinter(object): def instantiate(self): "Return a recognizer object for this type printer." - return self._recognizer(self.match, self.name) + return self._recognizer(self.template, self.name, self.targ1) -def add_one_type_printer(obj, match, name): - printer = FilteringTypePrinter('std::' + match, 'std::' + name) +def add_one_type_printer(obj, template, name, targ1 = None): + printer = FilteringTypePrinter('std::' + template, 'std::' + name, targ1) gdb.types.register_type_printer(obj, printer) - if _versioned_namespace and not '__cxx11' in match: + if _versioned_namespace and not '__cxx11' in template: ns = 'std::' + _versioned_namespace - printer = FilteringTypePrinter(ns + match, ns + name) + printer = FilteringTypePrinter(ns + template, ns + name, targ1) gdb.types.register_type_printer(obj, printer) def register_type_printers(obj): @@ -2120,29 +2130,33 @@ def register_type_printers(obj): return # Add type printers for typedefs std::string, std::wstring etc. - for ch in ('', 'w', 'u8', 'u16', 'u32'): - add_one_type_printer(obj, 'basic_string', ch + 'string') - add_one_type_printer(obj, '__cxx11::basic_string', ch + 'string') + 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]) # Typedefs for __cxx11::basic_string used to be in namespace __cxx11: add_one_type_printer(obj, '__cxx11::basic_string', - '__cxx11::' + ch + 'string') - add_one_type_printer(obj, 'basic_string_view', ch + 'string_view') + '__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 ('', 'w'): + for ch in (('', 'char'), ('w', 'wchar_t')): for x in ('ios', 'streambuf', 'istream', 'ostream', 'iostream', 'filebuf', 'ifstream', 'ofstream', 'fstream'): - add_one_type_printer(obj, 'basic_' + x, ch + x) + add_one_type_printer(obj, 'basic_' + x, ch[0] + x, ch[1]) for x in ('stringbuf', 'istringstream', 'ostringstream', 'stringstream'): - add_one_type_printer(obj, 'basic_' + x, ch + x) + 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 + x) + add_one_type_printer(obj, '__cxx11::basic_' + x, ch[0] + x, ch[1]) # Add type printers for typedefs regex, wregex, cmatch, wcmatch etc. for abi in ('', '__cxx11::'): - for ch in ('', 'w'): - add_one_type_printer(obj, abi + 'basic_regex', abi + ch + 'regex') + for ch in (('', 'char'), ('w', 'wchar_t')): + 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') for x in ('sub_match', 'regex_iterator', 'regex_token_iterator'): @@ -2170,9 +2184,13 @@ def register_type_printers(obj): # Add type printers for experimental::basic_string_view typedefs. ns = 'experimental::fundamentals_v1::' - for ch in ('', 'w', 'u8', 'u16', 'u32'): + 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 + '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',