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.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 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=1677496350; 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; bh=7YyIOCx584Q8vAevVDK59IRiI9l4n7fVgX729BlD57g=; b=e29s4VZu+/GrkmJwdg+Za2WFQkPBm+a7scTI8BNz+eDAe147/v9v9nQfDiMnGEY3qSCUb/ NII9K7z25XH5MYvYOm00pvEDqwtfDS6ItHiql1xSZeUdjleQDn0W2DzXEAa6Mm6hAZfbNC KlriZAUiz30C18XzGbpzfZLqrOMCa9o= 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) From: Bruno Larsen 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 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true 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 List-Id: 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()) -- 2.39.1