RE: [Patch] -var-evaluate-expression NAME [FORMAT]

Marc Khouzam
2008-01-23T14:30:09Z

> > I kind of cheated and used NULL to indicate that the format used should be
> > the one stored in the varobj structure.
>
> I would use a new function, e.g., something like
>
> char *
> varobj_get_formatted_value (struct varobj *var,
> enum varobj_display_formats format)
> {
> enum varobj_display_formats oldformat;
> char* value;
> oldformat = var->format;
> var->format = format;
> value = varobj_get_value (var);
> var->format = oldformat;
> return value;
> }
>
> and call it when argc == 2 in mi_cmd_var_evaluate_expression so that you
> don't have to change all calls to varobj_get_value and related functions.
> (Note: not tested)

I hadn't thought of temporarily setting var->format, instead of passing 'format'
everywhere. Much easier! Is there any way that varob_get_value() could not return?
Like a failed gdb_assert? Or are we sure that var->format will be reset to
the old format properly no matter what happens to varobj_get_value?

> > +/* Parse a string argument into a format value. */
> > +
> > +static enum varobj_display_formats
> > +mi_parse_format (const char *arg)
> > +{
> > + int len;
> > +
> > + len = strlen (arg);
> > +
> > + if (strncmp (arg, "natural", len) == 0)
> > + return FORMAT_NATURAL;
> > + else if (strncmp (arg, "binary", len) == 0)
> > + return FORMAT_BINARY;
> > + else if (strncmp (arg, "decimal", len) == 0)
> > + return FORMAT_DECIMAL;
> > + else if (strncmp (arg, "hexadecimal", len) == 0)
> > + return FORMAT_HEXADECIMAL;
> > + else if (strncmp (arg, "octal", len) == 0)
> > + return FORMAT_OCTAL;
> > + else
> > + error (_("Unknown display format: must be: \"natural\", \"binary\", \"decimal\", \"hexadecimal\", or \"octal\""));
> > +}
> > +
>
> and I would refactor this out of mi_cmd_var_set_format.

Didn't I do that already?