summaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.python/py-prettyprint.py
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2018-09-08 14:40:38 -0600
committerTom Tromey <tom@tromey.com>2018-09-08 20:49:15 -0600
commit332cf4c9251a31f0addc2ce2970c9a8bb0c16f96 (patch)
tree63347831188fef2e0558e93c69cc166c7f14f878 /gdb/testsuite/gdb.python/py-prettyprint.py
parent0653638f9f0efdb1561db8e2faff2580e09658af (diff)
downloadbinutils-gdb-332cf4c9251a31f0addc2ce2970c9a8bb0c16f96.tar.gz
Allow a pretty-printer without a to_string method
PR python/16047 points out that, while the documentation says that the to_string method is optional for a pretty-printer, the code disagrees and throws an exception. This patch fixes the problem. varobj is already ok here. Tested on x86-64 Fedora 26. gdb/ChangeLog 2018-09-08 Tom Tromey <tom@tromey.com> PR python/16047: * python/py-prettyprint.c (pretty_print_one_value): Check for to_string method. gdb/testsuite/ChangeLog 2018-09-08 Tom Tromey <tom@tromey.com> PR python/16047: * gdb.python/py-prettyprint.py (pp_int_typedef3): New class. (register_pretty_printers): Register new printer. * gdb.python/py-prettyprint.exp (run_lang_tests): Add int_type3 test. * gdb.python/py-prettyprint.c (int_type3): New typedef. (an_int_type3): New global.
Diffstat (limited to 'gdb/testsuite/gdb.python/py-prettyprint.py')
-rw-r--r--gdb/testsuite/gdb.python/py-prettyprint.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/gdb/testsuite/gdb.python/py-prettyprint.py b/gdb/testsuite/gdb.python/py-prettyprint.py
index 7357f05cc93..91592b4ec79 100644
--- a/gdb/testsuite/gdb.python/py-prettyprint.py
+++ b/gdb/testsuite/gdb.python/py-prettyprint.py
@@ -253,6 +253,15 @@ class pp_int_typedef (object):
def to_string(self):
return "type=%s, val=%s" % (self.val.type, int(self.val))
+class pp_int_typedef3 (object):
+ "A printer without a to_string method"
+
+ def __init__(self, val):
+ self.val = val
+
+ def children(self):
+ yield 's', 27
+
def lookup_function (val):
"Look-up and return a pretty-printer that can print val."
@@ -362,6 +371,7 @@ def register_pretty_printers ():
typedefs_pretty_printers_dict[re.compile ('^int_type$')] = pp_int_typedef
typedefs_pretty_printers_dict[re.compile ('^int_type2$')] = pp_int_typedef
+ typedefs_pretty_printers_dict[re.compile ('^int_type3$')] = pp_int_typedef3
# Dict for struct types with typedefs fully stripped.
pretty_printers_dict = {}