diff options
author | Marc Khouzam <marc.khouzam@ericsson.com> | 2008-04-09 13:29:55 +0000 |
---|---|---|
committer | Marc Khouzam <marc.khouzam@ericsson.com> | 2008-04-09 13:29:55 +0000 |
commit | de051565dfd9173f9ca885ac8e294ae2c90e409c (patch) | |
tree | 833f79330dea8f31531d2fba050483a361efe667 /gdb/mi/mi-cmd-var.c | |
parent | cdb0b8f5655411f9926c49ae39386430d3df67b0 (diff) | |
download | gdb-de051565dfd9173f9ca885ac8e294ae2c90e409c.zip gdb-de051565dfd9173f9ca885ac8e294ae2c90e409c.tar.gz gdb-de051565dfd9173f9ca885ac8e294ae2c90e409c.tar.bz2 |
gdb/ChangeLog
2008-04-09 Marc Khouzam <marc.khouzam@ericsson.com>
* mi/mi-cmd-var.c: Include "mi-getopt.h".
(mi_parse_format): New. Factored out from mi_cmd_var_set_format.
(mi_cmd_var_set_format): Use new mi_parse_format.
(mi_cmd_var_evaluate_expression): Support for -f option to specify
format.
* Makefile.in (mi-cmd-var.o): Update dependencies.
* varobj.h (varobj_get_formatted_value): Declare.
* varobj.c (my_value_of_variable): Added format parameter.
(cplus_value_of_variable): Likewise.
(java_value_of_variable): Likewise.
(c_value_of_variable): Likewise. Evaluate expression based
on format parameter.
(struct language_specific): Add format parameter to function member
*value_of_variable.
(varobj_get_formatted_value): New.
(varobj_get_value): Added format parameter to method call.
gdb/doc/ChangeLog
2008-04-09 Marc Khouzam <marc.khouzam@ericsson.com>
* gdb.texinfo (GDB/MI Variable Objects): Add anchor to
-var-set-format. Add -f option to -var-evaluate-expression.
gdb/testsuite/ChangeLog
2008-04-09 Marc Khouzam <marc.khouzam@ericsson.com>
* gdb.mi/mi2-var-display.exp: Added tests for the new -f
option of -var-evaluate-expression.
* gdb.mi/mi2-var-display.exp: Likewise.
Diffstat (limited to 'gdb/mi/mi-cmd-var.c')
-rw-r--r-- | gdb/mi/mi-cmd-var.c | 105 |
1 files changed, 78 insertions, 27 deletions
diff --git a/gdb/mi/mi-cmd-var.c b/gdb/mi/mi-cmd-var.c index 301126d..ddea2cf 100644 --- a/gdb/mi/mi-cmd-var.c +++ b/gdb/mi/mi-cmd-var.c @@ -28,6 +28,7 @@ #include "value.h" #include <ctype.h> #include "gdb_string.h" +#include "mi-getopt.h" const char mi_no_values[] = "--no-values"; const char mi_simple_values[] = "--simple-values"; @@ -195,13 +196,37 @@ mi_cmd_var_delete (char *command, char **argv, int argc) return MI_CMD_DONE; } +/* Parse a string argument into a format value. */ + +static enum varobj_display_formats +mi_parse_format (const char *arg) +{ + if (arg != NULL) + { + 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; + } + + error (_("Must specify the format as: \"natural\", \"binary\", \"decimal\", \"hexadecimal\", or \"octal\"")); +} + enum mi_cmd_result mi_cmd_var_set_format (char *command, char **argv, int argc) { enum varobj_display_formats format; - int len; struct varobj *var; - char *formspec; if (argc != 2) error (_("mi_cmd_var_set_format: Usage: NAME FORMAT.")); @@ -212,25 +237,8 @@ mi_cmd_var_set_format (char *command, char **argv, int argc) if (var == NULL) error (_("mi_cmd_var_set_format: Variable object not found")); - formspec = argv[1]; - if (formspec == NULL) - error (_("mi_cmd_var_set_format: Must specify the format as: \"natural\", \"binary\", \"decimal\", \"hexadecimal\", or \"octal\"")); - - len = strlen (formspec); - - if (strncmp (formspec, "natural", len) == 0) - format = FORMAT_NATURAL; - else if (strncmp (formspec, "binary", len) == 0) - format = FORMAT_BINARY; - else if (strncmp (formspec, "decimal", len) == 0) - format = FORMAT_DECIMAL; - else if (strncmp (formspec, "hexadecimal", len) == 0) - format = FORMAT_HEXADECIMAL; - else if (strncmp (formspec, "octal", len) == 0) - format = FORMAT_OCTAL; - else - error (_("mi_cmd_var_set_format: Unknown display format: must be: \"natural\", \"binary\", \"decimal\", \"hexadecimal\", or \"octal\"")); - + format = mi_parse_format (argv[1]); + /* Set the format of VAR to given format */ varobj_set_display_format (var, format); @@ -493,15 +501,58 @@ mi_cmd_var_evaluate_expression (char *command, char **argv, int argc) { struct varobj *var; - if (argc != 1) - error (_("mi_cmd_var_evaluate_expression: Usage: NAME.")); + enum varobj_display_formats format; + int formatFound; + int optind; + char *optarg; + + enum opt + { + OP_FORMAT + }; + static struct mi_opt opts[] = + { + {"f", OP_FORMAT, 1}, + { 0, 0, 0 } + }; + + /* Parse arguments */ + format = FORMAT_NATURAL; + formatFound = 0; + optind = 0; + while (1) + { + int opt = mi_getopt ("-var-evaluate-expression", argc, argv, opts, &optind, &optarg); + if (opt < 0) + break; + switch ((enum opt) opt) + { + case OP_FORMAT: + if (formatFound) + error (_("Cannot specify format more than once")); + + format = mi_parse_format (optarg); + formatFound = 1; + break; + } + } - /* Get varobj handle, if a valid var obj name was specified */ - var = varobj_get_handle (argv[0]); + if (optind >= argc) + error (_("Usage: [-f FORMAT] NAME")); + + if (optind < argc - 1) + error (_("Garbage at end of command")); + + /* Get varobj handle, if a valid var obj name was specified */ + var = varobj_get_handle (argv[optind]); if (var == NULL) - error (_("mi_cmd_var_evaluate_expression: Variable object not found")); + error (_("Variable object not found")); + + if (formatFound) + ui_out_field_string (uiout, "value", varobj_get_formatted_value (var, format)); + else + ui_out_field_string (uiout, "value", varobj_get_value (var)); - ui_out_field_string (uiout, "value", varobj_get_value (var)); return MI_CMD_DONE; } |