From patchwork Mon Jun 27 21:10:55 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kratochvil X-Patchwork-Id: 13413 Received: (qmail 20025 invoked by alias); 27 Jun 2016 21:11:13 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 20013 invoked by uid 89); 27 Jun 2016 21:11:12 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.2 required=5.0 tests=BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=30, 6, 17136, n* X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Mon, 27 Jun 2016 21:11:00 +0000 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 28C8763147 for ; Mon, 27 Jun 2016 21:10:59 +0000 (UTC) Received: from host1.jankratochvil.net (ovpn-116-37.ams2.redhat.com [10.36.116.37]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u5RLAunt017943 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO) for ; Mon, 27 Jun 2016 17:10:58 -0400 Date: Mon, 27 Jun 2016 23:10:55 +0200 From: Jan Kratochvil To: gdb-patches@sourceware.org Subject: [testsuite patch] PR python/17136: 'info type-printers' causes an exception when there are per-objfile printers Message-ID: <20160627211055.GA25806@host1.jankratochvil.net> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.6.1 (2016-04-27) X-IsSubscribed: yes Hi, https://sourceware.org/bugzilla/show_bug.cgi?id=17136 (gdb) info type-printers Python Exception 'gdb.Objfile' object has no attribute 'name': Error occurred in Python command: 'gdb.Objfile' object has no attribute 'name' A new testcase. The error happened only for objfile-bound type printers while GDB testsuite was testing only global type printers. (Type printers are different from pretty printers.) I find there suspicious only that 'gdb.objfiles()[0]'. One cannot use 'gdb.current_objfile()' because the .py file is not auto-loaded but it is: python exec (open ('${remote_python_file}').read ()) OK for check-in? Thanks, Jan gdb/testsuite/ChangeLog 2016-06-27 Jan Kratochvil PR python/17136 * gdb.python/py-typeprint.cc (Other, ovar): New. * gdb.python/py-typeprint.exp (info type-printers for other) (whatis ovar): New. * gdb.python/py-typeprint.py (Recognizer): Rename to ... (class StringRecognizer): ... here. (OtherRecognizer, OtherTypePrinter): New. Register them. diff --git a/gdb/testsuite/gdb.python/py-typeprint.cc b/gdb/testsuite/gdb.python/py-typeprint.cc index 94c9fff..15404e9 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 29f4eaa..2619a16 100644 --- a/gdb/testsuite/gdb.python/py-typeprint.exp +++ b/gdb/testsuite/gdb.python/py-typeprint.exp @@ -51,3 +51,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 9ab2440..458a321 100644 --- a/gdb/testsuite/gdb.python/py-typeprint.py +++ b/gdb/testsuite/gdb.python/py-typeprint.py @@ -15,7 +15,7 @@ import gdb -class Recognizer(object): +class StringRecognizer(object): def __init__(self): self.enabled = True @@ -30,6 +30,26 @@ 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())