* varobj.c (value_get_print_value): Rearrange.  Pass stream to
	apply_varobj_pretty_printer.
	* c-lang.c: Include exceptions.h.
	(c_get_string): Throw MEMORY_ERROR when appropriate.
	* python/py-prettyprint.c (enum string_repr_result): New.
	(print_stack_unless_memory_error): New function.
	(print_string_repr): Change return type.  Use
	print_stack_unless_memory_error.
	(print_children): Use print_stack_unless_memory_error.
	(apply_val_pretty_printer): Update.  Don't print children if
	string representation threw an exception.
	(apply_varobj_pretty_printer): Add 'stream' argument.  Use
	print_stack_unless_memory_error.
	* python/python.c (gdbpy_gdb_error, gdbpy_gdb_memory_error): New
	globals.
	(_initialize_python): Initialize them.
	* python/python-internal.h (GDB_PY_HANDLE_EXCEPTION): Use
	gdbpy_convert_exception.
	(GDB_PY_SET_HANDLE_EXCEPTION): Likewise.
	(gdbpy_gdb_error, gdbpy_gdb_memory_error): Declare.
	(gdbpy_convert_exception): Declare.
	(apply_varobj_pretty_printer): Update.
	* python/py-utils.c (gdbpy_convert_exception): New function.
gdb/doc
	* gdb.texinfo (Basic Python): Update.  Add xref.
	(Exception Handling): Document new exception classes.
	(Types In Python): Update.
	(Frames In Python): Update.
gdb/testsuite
	* gdb.python/py-prettyprint.c (main): Add new 'ns2' local.
	* gdb.python/py-prettyprint.exp (run_lang_tests): Add test for
	MemoryError.
	* gdb.python/python.exp (gdb_py_test_multiple): Update exception
	type.
	* gdb.python/py-value.exp (test_value_in_inferior): Add test for
	MemoryError.
	(test_subscript_regression): Update exception type.
This commit is contained in:
Tom Tromey 2010-11-12 20:49:43 +00:00
parent f1b9e6e7ee
commit 621c83642d
14 changed files with 223 additions and 58 deletions

View file

@ -2477,7 +2477,7 @@ value_get_print_value (struct value *value, enum varobj_display_formats format,
struct varobj *var)
{
struct ui_file *stb;
struct cleanup *old_chain = make_cleanup (null_cleanup, NULL);
struct cleanup *old_chain;
gdb_byte *thevalue = NULL;
struct value_print_options opts;
struct type *type = NULL;
@ -2491,6 +2491,9 @@ value_get_print_value (struct value *value, enum varobj_display_formats format,
if (value == NULL)
return NULL;
stb = mem_fileopen ();
old_chain = make_cleanup_ui_file_delete (stb);
gdbarch = get_type_arch (value_type (value));
#if HAVE_PYTHON
{
@ -2503,7 +2506,10 @@ value_get_print_value (struct value *value, enum varobj_display_formats format,
/* First check to see if we have any children at all. If so,
we simply return {...}. */
if (dynamic_varobj_has_child_method (var))
return xstrdup ("{...}");
{
do_cleanups (old_chain);
return xstrdup ("{...}");
}
if (PyObject_HasAttr (value_formatter, gdbpy_to_string_cst))
{
@ -2520,7 +2526,8 @@ value_get_print_value (struct value *value, enum varobj_display_formats format,
}
output = apply_varobj_pretty_printer (value_formatter,
&replacement);
&replacement,
stb);
if (output)
{
make_cleanup_py_decref (output);
@ -2565,9 +2572,6 @@ value_get_print_value (struct value *value, enum varobj_display_formats format,
}
#endif
stb = mem_fileopen ();
make_cleanup_ui_file_delete (stb);
get_formatted_print_options (&opts, format_code[(int) format]);
opts.deref_ref = 0;
opts.raw = 1;