From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-f54.google.com (mail-wr1-f54.google.com [209.85.221.54]) by sourceware.org (Postfix) with ESMTPS id 4B4B3385840F for ; Thu, 23 Feb 2023 19:50:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4B4B3385840F Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=palves.net Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wr1-f54.google.com with SMTP id bt28so4996313wrb.8 for ; Thu, 23 Feb 2023 11:50:16 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:content-language:in-reply-to:mime-version :user-agent:date:message-id:from:references:to:subject :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=bE0BG3q94OgN83tf22Mm1/uG7D2uZSSCRQ42oN4xt2U=; b=pF4wZeo1+aB/okCtsNFDufZpeUcbYa0JCo4lXkIE+tw8a0UkpSGsBkGvvytKGuqpMX B71/P7qLNQgtgGT/XPnf2K2O8/sv1ijsAeMIUIL0ksWqwiMcMr2RXAIQfIqVD6zYvGDZ jCuVh1uyokVyhur8sxKPRXtEJYZQfGaRVS5HB55AGjOn9odNYfjnnuZ8q5CfFiHuJLXV WKHTGA5jnXUFU2udz1h0/+4yiRIMxJefotZLISTqoX0zizIHL+Ot4ED8c/75LjLhDPXR rgDqhms+af8iyyRD0IJqh4mYaCu3V/32EzgT2CoFuMX5iBBcrk4BOjHZ2rdpEGCICP3o TSjA== X-Gm-Message-State: AO0yUKVS7lQkmWLnOi74RvPGA5or3yBEKdMEq3ZCYk01Zdzu27d7E6be B5aICdp7O79l0QlkHNuIJtSy7KvDrulNbA== X-Google-Smtp-Source: AK7set9kwUs9PfrXlKascIX+qr6wyd+3xtA8fAJ7dHuo1G1O/w3yq+F2RlXNWodOtRi/E18ZJMt6Lg== X-Received: by 2002:a05:6000:617:b0:2c5:5822:96d4 with SMTP id bn23-20020a056000061700b002c5582296d4mr10753228wrb.30.1677181814831; Thu, 23 Feb 2023 11:50:14 -0800 (PST) Received: from ?IPv6:2001:8a0:f92b:9e00::1fe? ([2001:8a0:f92b:9e00::1fe]) by smtp.gmail.com with ESMTPSA id v25-20020a5d5919000000b002c551f7d452sm10589355wrd.98.2023.02.23.11.50.14 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 23 Feb 2023 11:50:14 -0800 (PST) Subject: Re: [PATCH] gdb/testsuite: add regression test for per-objfile typeprinters To: Bruno Larsen , gdb-patches@sourceware.org References: <20230223131333.3743376-1-blarsen@redhat.com> From: Pedro Alves Message-ID: Date: Thu, 23 Feb 2023 19:50:12 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.10.1 MIME-Version: 1.0 In-Reply-To: <20230223131333.3743376-1-blarsen@redhat.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-10.2 required=5.0 tests=BAYES_00,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,GIT_PATCH_0,HEADER_FROM_DIFFERENT_DOMAINS,KAM_DMARC_STATUS,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,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 2023-02-23 1:13 p.m., Bruno Larsen via Gdb-patches wrote: > PR python/17136 reported an unhandled exception when using typeprinters > only valid on some objfiles, rather than being a global typeprinter. The > fix was accepted without a regression test, and we've been carrying one > out-of-tree for a while but I think it's worth upstreaming. The code > itself was developed by Jan Kratochvil. That suggests that the patch should have Author: Jan, or Co-Authored-By: Jan. Pedro Alves > > Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=17136 > --- > gdb/testsuite/gdb.python/py-typeprint.cc | 6 ++++++ > gdb/testsuite/gdb.python/py-typeprint.exp | 4 ++++ > gdb/testsuite/gdb.python/py-typeprint.py | 25 ++++++++++++++++++++--- > 3 files changed, 32 insertions(+), 3 deletions(-) > > diff --git a/gdb/testsuite/gdb.python/py-typeprint.cc b/gdb/testsuite/gdb.python/py-typeprint.cc > index ccd2ed02db1..3f274a73498 100644 > --- a/gdb/testsuite/gdb.python/py-typeprint.cc > +++ b/gdb/testsuite/gdb.python/py-typeprint.cc > @@ -31,6 +31,12 @@ templ s; > > basic_string bs; > > +class Other > +{ > +}; > + > +Other ovar; > + > int main() > { > return 0; > diff --git a/gdb/testsuite/gdb.python/py-typeprint.exp b/gdb/testsuite/gdb.python/py-typeprint.exp > index 40f7e53847f..778583b9eff 100644 > --- a/gdb/testsuite/gdb.python/py-typeprint.exp > +++ b/gdb/testsuite/gdb.python/py-typeprint.exp > @@ -48,3 +48,7 @@ gdb_test_no_output "enable type-printer string" > gdb_test "whatis bs" "string" "whatis with enabled printer" > > gdb_test "whatis s" "templ" > + > +gdb_test "info type-printers" "Type printers for \[^\r\n\]*/py-typeprint:\r\n *other\r\n.*" \ > + "info type-printers for other" > +gdb_test "whatis ovar" "type = Another" > diff --git a/gdb/testsuite/gdb.python/py-typeprint.py b/gdb/testsuite/gdb.python/py-typeprint.py > index b5ba243889b..aac42a1a99a 100644 > --- a/gdb/testsuite/gdb.python/py-typeprint.py > +++ b/gdb/testsuite/gdb.python/py-typeprint.py > @@ -15,8 +15,7 @@ > > import gdb > > - > -class Recognizer(object): > +class StringRecognizer(object): > def __init__(self): > self.enabled = True > > @@ -32,7 +31,27 @@ class StringTypePrinter(object): > self.enabled = True > > def instantiate(self): > - return Recognizer() > + return StringRecognizer() > > > gdb.type_printers.append(StringTypePrinter()) > + > +class OtherRecognizer(object): > + def __init__(self): > + self.enabled = True > + > + def recognize(self, type_obj): > + if type_obj.tag == 'Other': > + return 'Another' > + return None > + > +class OtherTypePrinter(object): > + def __init__(self): > + self.name = 'other' > + self.enabled = True > + > + def instantiate(self): > + return OtherRecognizer() > + > +import gdb.types > +gdb.types.register_type_printer(gdb.objfiles()[0], OtherTypePrinter()) >