-/* Helper for apply_val_pretty_printer which calls to_string and
- formats the result. If the value returnd is Py_None, nothing is
- printed and the function returns a 1; in all other cases data is
- printed as given by the pretty printer and the function returns 0.
-*/
-static int
+/* A wrapper for gdbpy_print_stack that ignores MemoryError. */
+
+static void
+print_stack_unless_memory_error (struct ui_file *stream)
+{
+ if (PyErr_ExceptionMatches (gdbpy_gdb_memory_error))
+ {
+ PyObject *type, *value, *trace;
+
+ PyErr_Fetch (&type, &value, &trace);
+
+ gdbpy_ref<> type_ref (type);
+ gdbpy_ref<> value_ref (value);
+ gdbpy_ref<> trace_ref (trace);
+
+ gdb::unique_xmalloc_ptr<char>
+ msg (gdbpy_exception_to_string (type, value));
+
+ if (msg == NULL || *msg == '\0')
+ fprintf_filtered (stream, _("<error reading variable>"));
+ else
+ fprintf_filtered (stream, _("<error reading variable: %s>"),
+ msg.get ());
+ }
+ else
+ gdbpy_print_stack ();
+}
+
+/* Helper for gdbpy_apply_val_pretty_printer which calls to_string and
+ formats the result. */
+
+static enum string_repr_result