From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 146C73959C67 for ; Wed, 16 Nov 2022 11:35:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 146C73959C67 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1668598554; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=s5Xvw66EojT53ZPPRfGVr12atO7j0OSRgJjFktjuY8c=; b=iEv/LVFzBLBLkwyIxgoupwjH2JVoh0Jq0stA3Yge6ywHEcepomxzydnVEERr13FJLK34yn G5vfr9nOvaRLPH3SXqcskmzPzworbvJ0nG6GmEDXC3xyu+LS/qMEaoYqXW3QekvI2BLxfT anHmWb+ymSoJqUva5tFXdUxG0KLrN2w= Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-524-YXt3zkq2PN6LQ9qj7nRHvw-1; Wed, 16 Nov 2022 06:35:53 -0500 X-MC-Unique: YXt3zkq2PN6LQ9qj7nRHvw-1 Received: by mail-ej1-f70.google.com with SMTP id xh12-20020a170906da8c00b007413144e87fso9620268ejb.14 for ; Wed, 16 Nov 2022 03:35:53 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=s5Xvw66EojT53ZPPRfGVr12atO7j0OSRgJjFktjuY8c=; b=d9NuQC2SjdxgbyO0+yEw+GVKaO+lNjza9Uzr5LPwK1fy196eG8VhDOntAN/lWmBX5c K3wQK0koZ68EXUbHtJ9crU9KOcrXs+cE67y5YaiXlseMdbWRBSZo6rRO3dp9SzylKmt4 Lw8MxnosZ+rbFuE2aBz3qeSDRVRueBTooCYRepel/kEi+8Y7gSrPgK8RAxTuLnj2qLdD 7crp1GEDb+E2D4rPJd1hPOggAdnYj4mZ/z1Hzun3qm4R7L0J7ky6eZ6eEnZWGeGvk4MB aHIt4A/NkBKXZ1/w8wdl4/s1iGb9G8xAb+aN7vuuzkD0VBIrdfXhwE1GmUS7EXmUnV6/ f0Kg== X-Gm-Message-State: ANoB5pnkKB0SZzHSCCPwYw7RAv6otJY7eHTiZTQmc9X13UnYaZckSw9h VDnYXp3q8k1lV9BlPiJ/8O2IANI+3sjy0LnLqJZY99GXX0tp9mJ6RBDToF5gDiUSTWNv5XpBo11 kAtvXfQlY7vVKTk5ssmuF5cBBU7ZR5ro= X-Received: by 2002:a05:6402:d78:b0:468:816f:bbc9 with SMTP id ec56-20020a0564020d7800b00468816fbbc9mr2276365edb.78.1668598552213; Wed, 16 Nov 2022 03:35:52 -0800 (PST) X-Google-Smtp-Source: AA0mqf6y5TlLdAV8VLEY/D0gG6fYdjVkdnrVW17tM7WpZin0lRaHZMs44F/NdwFVx/W4nqfrM0DgJKQI2KQTPvqS3Zw= X-Received: by 2002:a05:6402:d78:b0:468:816f:bbc9 with SMTP id ec56-20020a0564020d7800b00468816fbbc9mr2276349edb.78.1668598551917; Wed, 16 Nov 2022 03:35:51 -0800 (PST) MIME-Version: 1.0 References: <4d1dc3d4-e945-d283-964a-4dab3b3cb33e@gmail.com> <6056a668-3b5a-04b0-a0cc-98ad0c6064b2@gmail.com> In-Reply-To: <6056a668-3b5a-04b0-a0cc-98ad0c6064b2@gmail.com> From: Jonathan Wakely Date: Wed, 16 Nov 2022 11:35:41 +0000 Message-ID: Subject: Re: [PATCH] Fix gdb FilteringTypePrinter (again) To: =?UTF-8?Q?Fran=C3=A7ois_Dumont?= Cc: "libstdc++@gcc.gnu.org" , gcc-patches X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,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 Wed, 16 Nov 2022 at 06:04, Fran=C3=A7ois Dumont w= rote: > > On 15/11/22 17:17, Jonathan Wakely wrote: > > On 06/10/22 19:38 +0200, Fran=C3=A7ois Dumont wrote: > >> 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 =3D=3D type_obj: > >> return strip_inline_namespaces(self.name) > >> > >> I've added a call to gdb.types.get_basic_type so that we do not compar= e > >> a type with its typedef. > >> > >> Thanks for the pointer to the doc ! > >> > >> Doing so I eventually use your code Jonathan to make FilteringTypeFilt= er > >> 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 du= al > >> abi. > >> > >> Fran=C3=A7ois > >> > >> 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=3D'basic_string >> > >> - Checks if a specialization of the class template 'match' is the > >> same type > >> + Checks if an instantiation of the class template 'template' 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 > >> + e.g. for template=3D'basic_istream', name=3D'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=3D'basic_istream', name=3D'istream', targ1=3D'c= har', > >> if any > >> + instantiation of std::basic_istream is the same type as > >> std::istream then print it as std::istream. > >> """ > > > > These are template specializations, not instantiations. Please undo > > the changes to the comments, because the comments are 100% correct > > now, and would become wrong with this patch. > > > > template struct foo { }; > > using F =3D foo; // #1 > > template struct foo { }; // #2 > > template<> struct foo { }; // #3 > > > > #1 is a *specialization* of the class template foo. It is > > *instantiated* when you construct one or depend on its size, or its > > members. > > #2 is a *partial specialization* and #3 is an explicit specialization. > > But #1 is a speclialization, not an instantiation. > > > > Instantiation is a process that happens during compilation. A > > specialization is a type (or function, or variable) generated from a > > template by substituting arguments for the template parameters. The > > python type printer matches specializations. > > Lesson learned, thanks. > > Maybe comment on line 169 is wrong then. I think there is a clue in the > function name 'is_specialization_of' :-) Good point! Thanks, I'll fix it. > > > > >> > >> - def __init__(self, match, name): > >> - self.match =3D match > >> + def __init__(self, template, name, targ1): > > > > Is there a reason to require targ1 here, instead of making it > > optional, by using =3DNone as the default? > > In your original, and I know untested, proposal it was not working. > > The function add_one_type_printer was missing to pass its targ1 > parameter to the FilteringTypePrinter ctor but thanks to the default > value it was un-noticed by the interpreter. My untested patch had this, which adds it, doesn't it? -def add_one_type_printer(obj, match, name): - printer =3D FilteringTypePrinter('std::' + match, 'std::' + name) +def add_one_type_printer(obj, match, name, targ1 =3D None): + printer =3D FilteringTypePrinter('std::' + match, 'std::' + name, targ= 1) gdb.types.register_type_printer(obj, printer) if _versioned_namespace: ns =3D 'std::' + _versioned_namespace - printer =3D FilteringTypePrinter(ns + match, ns + name) + printer =3D FilteringTypePrinter(ns + match, ns + name, targ1) gdb.types.register_type_printer(obj, printer) I think FilteringTypePrinter should be usable without specifying None explicitly as the argument. Even if we don't actually use it that way today, it seems like a better API. If the argument is optional, then the idiomatic way to express that is to give it a default, not require None to be passed. I'll add that default argument, but first I need to figure out why I'm seeing new failures for libfundts.cc with -D_GLIBCXX_USE_CXX11_ABI=3D0. Your patch has introduced this new error: $12 =3D Python Exception : No type named std::experimental::fundamentals_v1::any::_Manager_internal, std::allocator >>. got: $12 =3D Python Exception : No type named std::experimental::fundamentals_v1::any::_Manager_internal, std::allocator >>. FAIL: libstdc++-prettyprinters/libfundts.cc print as > So I removed it as useless > and redundant with this function default value. > > > > > > > > >> + self.template =3D template > >> self.name =3D name > >> + self.targ1 =3D targ1 > >> self.enabled =3D True > >> > >> class _recognizer(object): > >> "The recognizer class for FilteringTypePrinter." > >> > >> - def __init__(self, match, name): > >> - self.match =3D match > >> + def __init__(self, template, name, targ1): > >> + self.template =3D template > >> self.name =3D name > >> + self.targ1 =3D targ1 > >> self.type_obj =3D None > >> > >> def recognize(self, type_obj): > >> """ > >> - If type_obj starts with self.match and is the same type a= s > >> + 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)): > > > > I wonder if we should make targ1 a gdb.Type object, not just a string. > > That seems like it would be better. The add_on_type_printer function > > could still accept a string, and then call gdb.lookup_type(targ1) to > > get a gdb.Type. We can change that later though. > > > > OK for trunk with the comments fixed to say "specialization" again. > > > Now committed. >