Re: [PATCH] Catch errors in value_get_print_value

Nick Roberts
2007-02-08T22:19:09Z

> > Currently when common_val_print throws an error from install_new_value it gets
> > caught in mi_execute_command and prints an MI error (^error,...) without
> > cleaning up. This patch catches the error in value_get_print_value so that GDB
> > can proceed normally. It could be adapted to output something like
> > "<error_reading_variable>" but I think the empty string works better.
>
> Could you explain why? I would be confused to see an empty value in
> my locals window. That's separate from this bug though.

It's much quieter than a window full of error/warning messages. If there's no
value available, the frontend doesn't show one. That seems logical to me but
perhaps only because I'm used to it.

> > ! TRY_CATCH (except, RETURN_MASK_ERROR)
> > ! {
> > ! common_val_print (value, stb, format_code[(int) format], 1, 0, 0);
> > ! }
> > !
>
> val_print, called by common_val_print, already has code to catch this
> error and prettyprint it.

Yes but I think the error is in value_contents_all. It's the only way that I can
catch it in varobj.c.

...
> So I checked this in instead. Let me know if it doesn't work for you.
>
> --
> Daniel Jacobowitz
> CodeSourcery
>
> 2007-02-08 Daniel Jacobowitz <dan@codesourcery.com>
>
> * varobj.c (install_new_value): Only call value_get_print_value
> if changeable.
>
> Index: varobj.c
> ===================================================================
> RCS file: /cvs/src/src/gdb/varobj.c,v
> retrieving revision 1.82
> diff -u -p -r1.82 varobj.c
> --- varobj.c 24 Jan 2007 19:54:13 -0000 1.82
> +++ varobj.c 8 Feb 2007 17:38:36 -0000
> @@ -953,7 +953,7 @@ install_new_value (struct varobj *var, s
> /* If the type is changeable, compare the old and the new values.
> If this is the initial assignment, we don't have any old value
> to compare with. */
> - if (initial)
> + if (initial && changeable)
> var->print_value = value_get_print_value (value, var->format);
> else if (changeable)
> {

Thanks. This is clearly a better patch as it's much simpler. Thinking more
generally, I wonder if there are other cases where value_contents_all should
catch this error?