From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by sourceware.org (Postfix) with ESMTPS id CD67A3858C20; Sat, 1 Oct 2022 10:43:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org CD67A3858C20 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wr1-x42a.google.com with SMTP id f11so7679737wrm.6; Sat, 01 Oct 2022 03:43:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date; bh=6Me+4MbuwJEaxWgV4cnBKWVeTRUy48SYhEI+/8vNRdA=; b=QA1rEmuBvC9ac3n0EZSEGT9XfrNpiN9u56nmgq8k9TbSF/O/vpBHMnr7zlOwNUBDwD obG+9bayxhzp6tYtxGz12Oe/m36tSuh5tDqWVxia9KLhiv3cjAzYiiEl8QIrkPYMH4gd XR+o2dFQTZwLrxF3dZloCVQHJSsLPitI/cGMg9L5wQeY06EVKr9lQ1XMpxscQZFFbT4f N9lzW6XHnhhhclWjXSDwSHcuzWCLUhamfBblgwypGZNWb2icT6AFO30TvO3XzCCIGI13 kUG64TrhmoJImBsdHIWMA6Zn+BkT39cQJaLTqQH5Wf48XcFvTsAnTDCE53jyzej05ppA Pz4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date; bh=6Me+4MbuwJEaxWgV4cnBKWVeTRUy48SYhEI+/8vNRdA=; b=KtXYO/KOgf74qD3JEKxXm4/VUgpzHhvwwEAohQUmdh+ly9LjNjO8SXpfXRySD/IOqX MmHtie03+t0RTMWMRsEQIjiXlqoAh/Is4uANj0Kmk1SSBFDeiD/RjPkRMh376+zv0Re9 5KQDU8iKs7D4SLusTcfJov8KxVhCmfSYYr7DKi3MIjXoG8u6B0DUzxssPkVNYdmAVxBV D7HdA+zcYWjcjUAU8adCpN5miw+7RWluOzoCfrpCUo9Bl6QbFKrUxaL0a7NYvm7tU2uw RHe374PxewehPjXekniTlETGVpV42UhQKFrhTvaEjEiBumjWvFzQzety/qPKrmsxaRpM 4/ng== X-Gm-Message-State: ACrzQf0PaDOG0ZU1Rj4/4UQXQF9w5ao2a61n3I4sDtpt/oPvAys0b028 stAqgN7cFLKLw7AX0Kx0h2Q= X-Google-Smtp-Source: AMsMyM70L73hBdLJGaID8jHZIB7tlo9GLXHZJAo7P6/aJlSCN/mvkI+DzSwA9axJbv4k/5wxfxPjMg== X-Received: by 2002:a05:6000:16c5:b0:22c:bdbd:e06b with SMTP id h5-20020a05600016c500b0022cbdbde06bmr8457270wrf.53.1664621004099; Sat, 01 Oct 2022 03:43:24 -0700 (PDT) Received: from ?IPV6:2a01:e0a:1dc:b1c0:c8bd:cfc:cadc:2187? ([2a01:e0a:1dc:b1c0:c8bd:cfc:cadc:2187]) by smtp.googlemail.com with ESMTPSA id e13-20020a5d530d000000b0022aeba020casm4779116wrv.83.2022.10.01.03.43.23 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 01 Oct 2022 03:43:23 -0700 (PDT) Message-ID: <2eb944c4-131e-001d-a3a6-cf1b7aea5614@gmail.com> Date: Sat, 1 Oct 2022 12:43:22 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: Re: [PATCH] Fix gdb printers for std::string Content-Language: fr To: Jonathan Wakely Cc: "libstdc++@gcc.gnu.org" , gcc-patches References: <1d7b853e-0180-718c-1947-2517272f44e8@gmail.com> From: =?UTF-8?Q?Fran=c3=a7ois_Dumont?= In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-5.3 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,NICE_REPLY_A,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 List-Id: On 01/10/22 12:06, Jonathan Wakely wrote: > On Sat, 1 Oct 2022 at 08:20, François Dumont via Libstdc++ > wrote: >> I had forgotten to re-run tests after I removed the #define >> _GLIBCXX_USE_CXX11_ABI 0. >> >> The comment was misleading, it could also impact output of std::list. >> >> I am also restoring the correct std::string alias for >> std::__cxx11::basic_string, even if with my workaround it doesn't really >> matter as the one for std::basic_string will be used. >> >> I also restored the printer for std::__cxx11::string typedef. Is it >> intentional to keep this ? > Yes, I kept that intentionally. There can be programs where some > objects still use that typedef, if those objects were compiled with > GCC 8.x or older. > >> 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. > Thanks for figuring out what was going wrong here, and how to fix it. > > >> 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. > I don't really like this part of the change though: I'll check what you are proposing but I don't think it is necessary to fix the problem. I did this on my path to find out what was going wrong. Once I understood it I consider that it was just a good change to keep. If you think otherwise I can revert this part. I also noted that gdb consider the filters as a filo list, not fifo. And I think that the 1st filters registered are the most extensively used. I can propose to invert all the registration if you think it worth it. > > @@ -2105,29 +2120,29 @@ 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', ''), ('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], > ch[1] + 'string') > > > As the docs for FilteringTypePrinter says, the first argument is > supposed to be the class template name: > > class FilteringTypePrinter(object): > r""" > A type printer that uses typedef names for common template specializations. > > Args: > match (str): The class template to recognize. > name (str): The typedef-name that will be used instead. > > Checks if a specialization of the class template 'match' is the same type > as the typedef 'name', and prints it as 'name' instead. > > e.g. if an instantiation of std::basic_istream is the same type as > std::istream then print it as std::istream. > """ > > With this change, the "class template" is sometimes just a string > prefix of a particular specialization, e.g. "basic_string The class template is "basic_string", and that's how the > FilteringTypePrinter was intended to work. > > How about something like the attached (untested) change instead. which > keeps the 'match' argument as the class template name, but optionally > supports passing the first template argument? Then you can use > match.split('::')[-1] is 'basic_string' to check if we are dealing > with one of the possibly ambiguous typedefs.