From patchwork Wed Sep 28 20:42:01 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: 1511 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f2ce:0:0:0:0:0 with SMTP id d14csp361357wrp; Wed, 28 Sep 2022 13:43:35 -0700 (PDT) X-Google-Smtp-Source: AMsMyM43QC/ck7ycV1x3qiNeXXqF5teYe+kqYeaWqchw5dgQx741K8jpwwdiYJ5VFp4xOM05Ph32 X-Received: by 2002:a17:906:770d:b0:73c:a08f:593c with SMTP id q13-20020a170906770d00b0073ca08f593cmr30076759ejm.182.1664397815446; Wed, 28 Sep 2022 13:43:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664397815; cv=none; d=google.com; s=arc-20160816; b=hR1HjCI1s/T5aouG+LjYZHsqNXjittqPl7A8sCa13CCheYkFa3Qr1XT+Rrg2RsUcUZ 2SgFVKuI3gVLxaHlAD0ipw0A4EjlJRxhfu2dcpjDMda8gKu+0Xi5WKJxtCzneAe4UZRb zUqRNWG1KriWviuvxsMH+riRmUhm+4pbNL9Iv8PWOhLNR8DqTMV5R4UTtKSjpd22loKa +Nf4NTyQNyg24Ko4+jYrv8i4uuKM0xBfdCa2g4PZ5oOEuuFRzEsHT5SNqGqqNdo7Kbub oUN3MaCBcG1786SN1uqYpHcCbzwoNOKoyP1gbej3ZEhvqHoVHbVng829eRSnQPUOLL73 pjpA== 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:subject :to:content-language:user-agent:mime-version:date:message-id :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=wCEjCn/y9bz5qVT5pbEDwkZL4520+cWUDrxn4M93TJk=; b=onUKToIcQxsYQ7JEUw1CrtlLi5HezWUHEyhSd7MgGmPzbdYWCeo9BFzkSmpuNVVXWt S9GYzGfh0p46MEYoeFs9zOUBGe1wV4Gz+oIHzw3AUu4rHkpSbudjoqWYzCc+y1kg8Y4Y 2GO92JMY6sPF+Kw27HeNoRExFRFVneG/wzh8GMS5FYsmUMHxazz6AJqLe6Fbn3vUuIJS +QKkaypOSezUZCtOqWNJHeqU5nBwwgx88iyXQbcOIlYKUQ6PxM+Xl57yVj18Tjx/gfJj Nxyy4OYq9pNeUBpahqTsqlKMtaZI4x2L4e9gp/W6yDefPYNiuVJ/o+ylNsS1yjbxddCa qJ1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=KAt2eVz4; 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 gs12-20020a1709072d0c00b007833ab0a3f9si6104797ejc.708.2022.09.28.13.43.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Sep 2022 13:43:35 -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=KAt2eVz4; 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 8C58E3856947 for ; Wed, 28 Sep 2022 20:42:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8C58E3856947 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1664397774; bh=wCEjCn/y9bz5qVT5pbEDwkZL4520+cWUDrxn4M93TJk=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=KAt2eVz4aXWO2fP4jQjG1a1v7/erpaHJvyPkuG1DU6Hm00xWJwWjs0XNGTcgO3qu7 ZIX+5tipXrIxZdVoq+uEjZNoocZG33F6ECuZiorZy0WaH2D2G5dDQDid22UvRBMMfJ kEmEYBGJU9QXB6MXE/tMwjBrXZ8fLuRljYKbYYd0= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by sourceware.org (Postfix) with ESMTPS id 2721B3858D28; Wed, 28 Sep 2022 20:42:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 2721B3858D28 Received: by mail-wm1-x32d.google.com with SMTP id i203-20020a1c3bd4000000b003b3df9a5ecbso2034259wma.1; Wed, 28 Sep 2022 13:42:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=subject:from:cc:to:content-language:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date; bh=wCEjCn/y9bz5qVT5pbEDwkZL4520+cWUDrxn4M93TJk=; b=rjOrGMZ3C9zpSjvhyTNtVXu+krGow3N/AAf8IwxKzEwExGMqsrqQMS9fAULbG+9DcZ qVPPDMDr5qDeCH9A9sC2/Z0fD6VNX4vfnWVqZjIFKxS54SKtTWm0IraPbNxQ2OfXbzpM 2KmJ4nEem/WA/uTenmAbZnh6bgYBLE2aCoNDoaIjHbCyVdkEGDLEyTNW8ghGAN8I178h LIuFHJrcgNGw4oqhEBeDfqWWPXjTkGYs35rekeClt23AUcUO5mWLNstX2ftkzN+8JhO0 jTEKaRiIh4C6dDmjBd/LvZmj5rAyjX5grku3ywkNM1zluwiPui/2o33fkFt/5//wscb5 wing== X-Gm-Message-State: ACrzQf2MJrSuDbjuMjYPD6RCPMfsXnAPy68mEhBC2al6j7Z4mkgaehlB SScTEcfex7EYDrp+Pc8Q/WTl7oE8yWU= X-Received: by 2002:a05:600c:b42:b0:3b4:7580:a995 with SMTP id k2-20020a05600c0b4200b003b47580a995mr8430791wmr.30.1664397722836; Wed, 28 Sep 2022 13:42:02 -0700 (PDT) Received: from ?IPV6:2a01:e0a:1dc:b1c0:82c1:bb59:16bd:d8ea? ([2a01:e0a:1dc:b1c0:82c1:bb59:16bd:d8ea]) by smtp.googlemail.com with ESMTPSA id p2-20020a5d6382000000b0022a53fe201fsm3691410wru.68.2022.09.28.13.42.02 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 28 Sep 2022 13:42:02 -0700 (PDT) Message-ID: Date: Wed, 28 Sep 2022 22:42:01 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Content-Language: fr To: "libstdc++@gcc.gnu.org" Subject: [PATCH] Fix gdb printers for std::string X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00, BODY_8BITS, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_SHORT, 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?1745247603584033440?= X-GMAIL-MSGID: =?utf-8?q?1745247603584033440?= Sometimes substitution of basic_string by one of the std::string typeedef fails. Here is the fix.     libstdc++: Fix gdb pretty printers when dealing with std::string     Since revision 33b43b0d8cd2de722d177ef823930500948a7487 std::string and other     similar typedef are ambiguous from a gdb point of view because it matches both     std::basic_string and std::__cxx11::basic_string symbols. For those     typedef add a workaround to accept the substitution as long as the same regardless     of __cxx11 namespace.     Also avoid to register printers for types in std::__cxx11::__8:: namespace, there is     no such symbols.     libstdc++-v3/ChangeLog:             * libstdc++-v3/python/libstdcxx/v6/printers.py (Printer.add_version): Do not add             version namespace for __cxx11 symbols.             (add_one_template_type_printer): Likewise.             (add_one_type_printer): Likewise.             (FilteringTypePrinter._recognizer.recognize): Add a workaround for std::string & al             ambiguous typedef matching both std:: and std::__cxx11:: symbols.             (register_type_printers): Refine type registration to limit false positive in             FilteringTypePrinter._recognize.recognize requiring to look for the type in gdb.             * libstdc++-v3/testsuite/libstdc++-prettyprinters/cxx17.cc: Remove obsolete             \#define _GLIBCXX_USE_CXX11_ABI 0.             * libstdc++-v3/testsuite/libstdc++-prettyprinters/simple.cc: Likewise.             * libstdc++-v3/testsuite/libstdc++-prettyprinters/simple11.cc: Likewise.             * libstdc++-v3/testsuite/libstdc++-prettyprinters/whatis.cc: Likewise.             * libstdc++-v3/testsuite/libstdc++-prettyprinters/80276.cc: Likewise and remove             xfail for c++20 and debug mode.             * libstdc++-v3/testsuite/libstdc++-prettyprinters/libfundts.cc: Likewise. Tested under x86_64 linux w/o _GLIBCXX_INLINE_VERSION and w/o _GLIBCXX_DEBUG. I also tested it with my patch to use cxx11 abi in _GLIBCXX_INLINE_VERSION mode. Ok to commit ? François diff --git a/libstdc++-v3/python/libstdcxx/v6/printers.py b/libstdc++-v3/python/libstdcxx/v6/printers.py index 245b6e3dbcd..b4878b93bb2 100644 --- a/libstdc++-v3/python/libstdcxx/v6/printers.py +++ b/libstdc++-v3/python/libstdcxx/v6/printers.py @@ -1857,7 +1857,7 @@ class Printer(object): # Add a name using _GLIBCXX_BEGIN_NAMESPACE_VERSION. def add_version(self, base, name, function): self.add(base + name, function) - if _versioned_namespace: + if _versioned_namespace and not '__cxx11' in base: vbase = re.sub('^(std|__gnu_cxx)::', r'\g<0>%s' % _versioned_namespace, base) self.add(vbase + name, function) @@ -2026,7 +2026,7 @@ def add_one_template_type_printer(obj, name, defargs): printer = TemplateTypePrinter('std::__debug::'+name, defargs) gdb.types.register_type_printer(obj, printer) - if _versioned_namespace: + if _versioned_namespace and not '__cxx11' in name: # Add second type printer for same type in versioned namespace: ns = 'std::' + _versioned_namespace # PR 86112 Cannot use dict comprehension here: @@ -2084,6 +2084,21 @@ class FilteringTypePrinter(object): 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 ambiguous: + if self.type_obj.tag.replace('__cxx11::', '') == type_obj.tag.replace('__cxx11::', ''): + return strip_inline_namespaces(self.name) + return None def instantiate(self): @@ -2093,7 +2108,7 @@ class FilteringTypePrinter(object): def add_one_type_printer(obj, match, name): printer = FilteringTypePrinter('std::' + match, 'std::' + name) gdb.types.register_type_printer(obj, printer) - if _versioned_namespace: + if _versioned_namespace and not '__cxx11' in match: ns = 'std::' + _versioned_namespace printer = FilteringTypePrinter(ns + match, ns + name) gdb.types.register_type_printer(obj, printer) @@ -2105,29 +2120,26 @@ 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') - # 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') + for ch in (('char', ''), ('wchar_t', 'w'), ('char8_t', 'u8'), ('char16_t', 'u16'), ('char32_t', 'u32')): + add_one_type_printer(obj, 'basic_string<' + ch[0], ch[1] + 'string') + add_one_type_printer(obj, '__cxx11::basic_string<' + ch[0], '__cxx11::' + ch[1] + 'string') + add_one_type_printer(obj, 'basic_string_view<' + ch[0], ch[1] + 'string_view') # Add type printers for typedefs std::istream, std::wistream etc. - for ch in ('', 'w'): + for ch in (('char', ''), ('wchar_t', 'w')): 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], ch[1] + x) for x in ('stringbuf', 'istringstream', 'ostringstream', 'stringstream'): - add_one_type_printer(obj, 'basic_' + x, ch + x) + add_one_type_printer(obj, 'basic_' + x, ch[1] + x) # 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], ch[1] + x) # 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', ''), ('wchar_t', 'w')): + add_one_type_printer(obj, abi + 'basic_regex<' + ch[0], abi + ch[1] + 'regex') 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'): diff --git a/libstdc++-v3/testsuite/libstdc++-prettyprinters/80276.cc b/libstdc++-v3/testsuite/libstdc++-prettyprinters/80276.cc index 4abe7d384e8..d1016b58d79 100644 --- a/libstdc++-v3/testsuite/libstdc++-prettyprinters/80276.cc +++ b/libstdc++-v3/testsuite/libstdc++-prettyprinters/80276.cc @@ -18,9 +18,6 @@ // with this library; see the file COPYING3. If not see // . -// Type printers only recognize the old std::string for now. -#define _GLIBCXX_USE_CXX11_ABI 0 - #include #include #include @@ -46,7 +43,7 @@ main() // { dg-final { whatis-regexp-test p1 "std::unique_ptr\\*>>>" } } // { dg-final { whatis-regexp-test p2 "std::unique_ptr\\*>>\\\[\\\]>" } } // { dg-final { whatis-regexp-test p3 "std::unique_ptr\\*>>\\\[10\\\]>" } } - // { dg-final { whatis-regexp-test p4 "std::unique_ptr\\\[\\\]>>\\\[99\\\]>" { xfail { c++20 || debug_mode } } } } + // { dg-final { whatis-regexp-test p4 "std::unique_ptr\\\[\\\]>>\\\[99\\\]>" } } placeholder(&p1); // Mark SPOT placeholder(&p2); diff --git a/libstdc++-v3/testsuite/libstdc++-prettyprinters/cxx17.cc b/libstdc++-v3/testsuite/libstdc++-prettyprinters/cxx17.cc index e52ffbbcc15..cf699d22e78 100644 --- a/libstdc++-v3/testsuite/libstdc++-prettyprinters/cxx17.cc +++ b/libstdc++-v3/testsuite/libstdc++-prettyprinters/cxx17.cc @@ -18,9 +18,6 @@ // with this library; see the file COPYING3. If not see // . -// Type printers only recognize the old std::string for now. -#define _GLIBCXX_USE_CXX11_ABI 0 - #include #include #include diff --git a/libstdc++-v3/testsuite/libstdc++-prettyprinters/libfundts.cc b/libstdc++-v3/testsuite/libstdc++-prettyprinters/libfundts.cc index e81308d4f7e..b2f464d0894 100644 --- a/libstdc++-v3/testsuite/libstdc++-prettyprinters/libfundts.cc +++ b/libstdc++-v3/testsuite/libstdc++-prettyprinters/libfundts.cc @@ -18,9 +18,6 @@ // with this library; see the file COPYING3. If not see // . -// Type printers only recognize the old std::string for now. -#define _GLIBCXX_USE_CXX11_ABI 0 - #include #include #include @@ -50,7 +47,7 @@ main() om = std::map{ {1, 2.}, {3, 4.}, {5, 6.} }; // { dg-final { regexp-test om {std::experimental::optional> containing std::(__debug::)?map with 3 elements = {\[1\] = 2, \[3\] = 4, \[5\] = 6}} } } optional os{ "stringy" }; -// { dg-final { note-test os {std::experimental::optional = {[contained value] = "stringy"}} { xfail { c++20 || debug_mode } } } } +// { dg-final { note-test os {std::experimental::optional = {[contained value] = "stringy"}} } } any a; // { dg-final { note-test a {std::experimental::any [no contained value]} } } @@ -61,7 +58,7 @@ main() any ap = (void*)nullptr; // { dg-final { note-test ap {std::experimental::any containing void * = {[contained value] = 0x0}} } } any as = *os; -// { dg-final { note-test as {std::experimental::any containing std::string = {[contained value] = "stringy"}} { xfail { c++20 || debug_mode } } } } +// { dg-final { note-test as {std::experimental::any containing std::string = {[contained value] = "stringy"}} } } any as2("stringiest"); // { dg-final { regexp-test as2 {std::experimental::any containing const char \* = {\[contained value\] = 0x[[:xdigit:]]+ "stringiest"}} } } any am = *om; diff --git a/libstdc++-v3/testsuite/libstdc++-prettyprinters/simple.cc b/libstdc++-v3/testsuite/libstdc++-prettyprinters/simple.cc index 1609ae2c8db..3d14120371e 100644 --- a/libstdc++-v3/testsuite/libstdc++-prettyprinters/simple.cc +++ b/libstdc++-v3/testsuite/libstdc++-prettyprinters/simple.cc @@ -20,9 +20,6 @@ // with this library; see the file COPYING3. If not see // . -// Type printers only recognize the old std::string for now. -#define _GLIBCXX_USE_CXX11_ABI 0 - #include #include #include diff --git a/libstdc++-v3/testsuite/libstdc++-prettyprinters/simple11.cc b/libstdc++-v3/testsuite/libstdc++-prettyprinters/simple11.cc index a4b82e30f9c..367e04579ca 100644 --- a/libstdc++-v3/testsuite/libstdc++-prettyprinters/simple11.cc +++ b/libstdc++-v3/testsuite/libstdc++-prettyprinters/simple11.cc @@ -20,9 +20,6 @@ // with this library; see the file COPYING3. If not see // . -// Type printers only recognize the old std::string for now. -#define _GLIBCXX_USE_CXX11_ABI 0 - #include #include #include diff --git a/libstdc++-v3/testsuite/libstdc++-prettyprinters/whatis.cc b/libstdc++-v3/testsuite/libstdc++-prettyprinters/whatis.cc index 046d26f0020..23b9947a5de 100644 --- a/libstdc++-v3/testsuite/libstdc++-prettyprinters/whatis.cc +++ b/libstdc++-v3/testsuite/libstdc++-prettyprinters/whatis.cc @@ -18,10 +18,6 @@ // with this library; see the file COPYING3. If not see // . -// GDB can't find global variables using the abi_tag attribute. -// https://sourceware.org/bugzilla/show_bug.cgi?id=19436 -#define _GLIBCXX_USE_CXX11_ABI 0 - #include #include #include