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

Nick Roberts
2008-01-23T03:04:19Z

> 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)

>...
> +/* 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.

--
Nick http://www.inet.net.nz/~nickrob