From patchwork Mon Feb 27 11:12:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guinevere Larsen X-Patchwork-Id: 65675 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 523623858C2B for ; Mon, 27 Feb 2023 11:12:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 523623858C2B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1677496374; bh=7YyIOCx584Q8vAevVDK59IRiI9l4n7fVgX729BlD57g=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=fX9aGkjrQaTkofqMyi30g8E1NlvQgwLxLqgvKPQd6Hl7gofET5uBnge4F7ePX1G6l KprW+tzDy69xa+jUIqV7G8wbcWC32SMfljWgiwOP/KcfGEIUf+1O++n3Px6T+utj/r H4tYeez7ifgsUS0Go3/P5pP2douJZWGBDa/j1ukQ= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 02C9C3858D20 for ; Mon, 27 Feb 2023 11:12:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 02C9C3858D20 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-37-VYhIOwfCMYyb-h_IxZAXhg-1; Mon, 27 Feb 2023 06:12:27 -0500 X-MC-Unique: VYhIOwfCMYyb-h_IxZAXhg-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A7E9B185A7A4; Mon, 27 Feb 2023 11:12:26 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.45.224.8]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 299A21121314; Mon, 27 Feb 2023 11:12:25 +0000 (UTC) To: gdb-patches@sourceware.org Cc: jkratochvil@azul.com, pedro@palves.com, Bruno Larsen , Andrew Burgess Subject: [PATCH v2] gdb/testsuite: add regression test for per-objfile typeprinters Date: Mon, 27 Feb 2023 12:12:01 +0100 Message-Id: <20230227111201.4092957-1-blarsen@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.6 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 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Bruno Larsen via Gdb-patches From: Guinevere Larsen Reply-To: Bruno Larsen Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" 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. Co-Authored-By: Jan Kratochvil Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=17136 Reviewed-By: Andrew Burgess --- 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())