aboutsummaryrefslogtreecommitdiff
path: root/gdb/python
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/python
parent0653638f9f0efdb1561db8e2faff2580e09658af (diff)
downloadgdb-332cf4c9251a31f0addc2ce2970c9a8bb0c16f96.zip
gdb-332cf4c9251a31f0addc2ce2970c9a8bb0c16f96.tar.gz
gdb-332cf4c9251a31f0addc2ce2970c9a8bb0c16f96.tar.bz2
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/python')
-rw-r--r--gdb/python/py-prettyprint.c25
1 files changed, 15 insertions, 10 deletions
diff --git a/gdb/python/py-prettyprint.c b/gdb/python/py-prettyprint.c
index a8a8489..df0266b 100644
--- a/gdb/python/py-prettyprint.c
+++ b/gdb/python/py-prettyprint.c
@@ -195,18 +195,23 @@ pretty_print_one_value (PyObject *printer, struct value **out_value)
*out_value = NULL;
TRY
{
- result.reset (PyObject_CallMethodObjArgs (printer, gdbpy_to_string_cst,
- NULL));
- if (result != NULL)
+ if (!PyObject_HasAttr (printer, gdbpy_to_string_cst))
+ result = gdbpy_ref<>::new_reference (Py_None);
+ else
{
- if (! gdbpy_is_string (result.get ())
- && ! gdbpy_is_lazy_string (result.get ())
- && result != Py_None)
+ result.reset (PyObject_CallMethodObjArgs (printer, gdbpy_to_string_cst,
+ NULL));
+ if (result != NULL)
{
- *out_value = convert_value_from_python (result.get ());
- if (PyErr_Occurred ())
- *out_value = NULL;
- result = NULL;
+ if (! gdbpy_is_string (result.get ())
+ && ! gdbpy_is_lazy_string (result.get ())
+ && result != Py_None)
+ {
+ *out_value = convert_value_from_python (result.get ());
+ if (PyErr_Occurred ())
+ *out_value = NULL;
+ result = NULL;
+ }
}
}
}