This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[testsuite patch] PR python/17136: 'info type-printers' causes an exception when there are per-objfile printers
- From: Jan Kratochvil <jan dot kratochvil at redhat dot com>
- To: gdb-patches at sourceware dot org
- Date: Mon, 27 Jun 2016 23:10:55 +0200
- Subject: [testsuite patch] PR python/17136: 'info type-printers' causes an exception when there are per-objfile printers
- Authentication-results: sourceware.org; auth=none
Hi,
https://sourceware.org/bugzilla/show_bug.cgi?id=17136
(gdb) info type-printers
Python Exception <type 'exceptions.AttributeError'> '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 <jan.kratochvil@redhat.com>
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<basic_string> 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<string>"
+
+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())