summaryrefslogtreecommitdiff
path: root/gdb
diff options
context:
space:
mode:
authorMarc Khouzam <marc.khouzam@ericsson.com>2008-04-09 13:29:55 +0000
committerMarc Khouzam <marc.khouzam@ericsson.com>2008-04-09 13:29:55 +0000
commit0fd18dcbb81b1b7cec7c17c08b3488aff839dfb9 (patch)
tree65b4d8bd1d553e4c9c18fe79579964b1c85856dd /gdb
parent4a918424ebdecf606a762d95c6fb144c252c6257 (diff)
downloadgdb-0fd18dcbb81b1b7cec7c17c08b3488aff839dfb9.tar.gz
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')
-rw-r--r--gdb/ChangeLog20
-rw-r--r--gdb/Makefile.in2
-rw-r--r--gdb/doc/ChangeLog5
-rw-r--r--gdb/doc/gdb.texinfo13
-rw-r--r--gdb/mi/mi-cmd-var.c105
-rw-r--r--gdb/testsuite/ChangeLog6
-rw-r--r--gdb/testsuite/gdb.mi/mi-var-display.exp44
-rw-r--r--gdb/testsuite/gdb.mi/mi2-var-display.exp43
-rw-r--r--gdb/varobj.c46
-rw-r--r--gdb/varobj.h3
10 files changed, 241 insertions, 46 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 6058b95939c..8565ee0f6f7 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,23 @@
+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.
+
2008-04-08 Joel Brobecker <brobecker@adacore.com>
* stabsread.c (cleanup_undefined_types_noname): Manually set the
diff --git a/gdb/Makefile.in b/gdb/Makefile.in
index 45f9fcb62e3..a2a9d4b81ae 100644
--- a/gdb/Makefile.in
+++ b/gdb/Makefile.in
@@ -3219,7 +3219,7 @@ mi-cmd-target.o: $(srcdir)/mi/mi-cmd-target.c $(defs_h) $(mi_cmds_h) \
$(mi_getopt_h) $(remote_h)
$(CC) -c $(INTERNAL_CFLAGS) $(srcdir)/mi/mi-cmd-target.c
mi-cmd-var.o: $(srcdir)/mi/mi-cmd-var.c $(defs_h) $(mi_cmds_h) $(ui_out_h) \
- $(mi_out_h) $(varobj_h) $(value_h) $(gdb_string_h)
+ $(mi_out_h) $(varobj_h) $(value_h) $(gdb_string_h) $(mi_getopt_h)
$(CC) -c $(INTERNAL_CFLAGS) $(srcdir)/mi/mi-cmd-var.c
mi-console.o: $(srcdir)/mi/mi-console.c $(defs_h) $(mi_console_h) \
$(gdb_string_h)
diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog
index 2cf219e1144..5e27b377d22 100644
--- a/gdb/doc/ChangeLog
+++ b/gdb/doc/ChangeLog
@@ -1,3 +1,8 @@
+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.
+
2008-04-03 Joel Brobecker <brobecker@adacore.com>
* gdb.texinfo (Breakpoint Menus): Delete. Contents moved inside
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 080e42f787a..9355d47adcc 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -20034,6 +20034,7 @@ Returns an error if the object @var{name} is not found.
Sets the output format for the value of the object @var{name} to be
@var{format-spec}.
+@anchor{-var-set-format}
The syntax for the @var{format-spec} is as follows:
@smallexample
@@ -20210,12 +20211,16 @@ where @var{attr} is @code{@{ @{ editable | noneditable @} | TBD @}}.
@subsubheading Synopsis
@smallexample
- -var-evaluate-expression @var{name}
+ -var-evaluate-expression [-f @var{format-spec}] @var{name}
@end smallexample
Evaluates the expression that is represented by the specified variable
-object and returns its value as a string. The format of the
-string can be changed using the @code{-var-set-format} command.
+object and returns its value as a string. The format of the string
+can be specified with the @samp{-f} option. The possible values of
+this option are the same as for @code{-var-set-format}
+(@pxref{-var-set-format}). If the @samp{-f} option is not specified,
+the current display format will be used. The current display format
+can be changed using the @code{-var-set-format} command.
@smallexample
value=@var{value}
@@ -20268,7 +20273,7 @@ be a root variable object. Here, ``changed'' means that the result of
object names, all existing variable objects are updated, except
for frozen ones (@pxref{-var-set-frozen}). The option
@var{print-values} determines whether both names and values, or just
-names are printed. The possible values of this options are the same
+names are printed. The possible values of this option are the same
as for @code{-var-list-children} (@pxref{-var-list-children}). It is
recommended to use the @samp{--all-values} option, to reduce the
number of MI commands needed on each program stop.
diff --git a/gdb/mi/mi-cmd-var.c b/gdb/mi/mi-cmd-var.c
index 301126d91a9..ddea2cf0378 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;
}
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index aa2f8b9fec6..245bc58904f 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,9 @@
+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.
+
2008-04-07 Vladimir Prus <vladimir@codesourcery.com>
Introduce test setup helpers.
diff --git a/gdb/testsuite/gdb.mi/mi-var-display.exp b/gdb/testsuite/gdb.mi/mi-var-display.exp
index b6742de6bcd..22ad34d73fb 100644
--- a/gdb/testsuite/gdb.mi/mi-var-display.exp
+++ b/gdb/testsuite/gdb.mi/mi-var-display.exp
@@ -161,6 +161,50 @@ mi_gdb_test "-var-evaluate-expression foo" \
"\\^done,value=\"3\"" \
"eval variable foo"
+
+# Test: c_variable-6.19
+# Desc: check optional format parameter of var-evaluate-expression
+# and check that current format is not changed
+mi_gdb_test "-var-evaluate-expression -f hex foo" \
+ "\\^done,value=\"0x3\"" \
+ "eval variable foo in hex"
+
+mi_gdb_test "-var-show-format foo" \
+ "\\^done,format=\"decimal\"" \
+ "show format variable foo after eval in hex"
+
+mi_gdb_test "-var-evaluate-expression -f octal foo" \
+ "\\^done,value=\"03\"" \
+ "eval variable foo in octal"
+
+mi_gdb_test "-var-show-format foo" \
+ "\\^done,format=\"decimal\"" \
+ "show format variable foo after eval in octal"
+
+mi_gdb_test "-var-evaluate-expression -f decimal foo" \
+ "\\^done,value=\"3\"" \
+ "eval variable foo in decimal"
+
+mi_gdb_test "-var-show-format foo" \
+ "\\^done,format=\"decimal\"" \
+ "show format variable foo after eval in decimal"
+
+mi_gdb_test "-var-evaluate-expression -f nat foo" \
+ "\\^done,value=\"0x3\"" \
+ "eval variable foo in natural"
+
+mi_gdb_test "-var-show-format foo" \
+ "\\^done,format=\"decimal\"" \
+ "show format variable foo after eval in natural"
+
+mi_gdb_test "-var-evaluate-expression -f bin foo" \
+ "\\^done,value=\"11\"" \
+ "eval variable foo in binary"
+
+mi_gdb_test "-var-show-format foo" \
+ "\\^done,format=\"decimal\"" \
+ "show format variable foo after eval in binary"
+
mi_gdb_test "-var-delete foo" \
"\\^done,ndeleted=\"1\"" \
"delete var foo"
diff --git a/gdb/testsuite/gdb.mi/mi2-var-display.exp b/gdb/testsuite/gdb.mi/mi2-var-display.exp
index 21f1aa6d6f7..00e5a85119c 100644
--- a/gdb/testsuite/gdb.mi/mi2-var-display.exp
+++ b/gdb/testsuite/gdb.mi/mi2-var-display.exp
@@ -161,6 +161,49 @@ mi_gdb_test "-var-evaluate-expression foo" \
"\\^done,value=\"3\"" \
"eval variable foo"
+# Test: c_variable-6.19
+# Desc: check optional format parameter of var-evaluate-expression
+# and check that current format is not changed
+mi_gdb_test "-var-evaluate-expression -f hex foo" \
+ "\\^done,value=\"0x3\"" \
+ "eval variable foo in hex"
+
+mi_gdb_test "-var-show-format foo" \
+ "\\^done,format=\"decimal\"" \
+ "show format variable foo after eval in hex"
+
+mi_gdb_test "-var-evaluate-expression -f octal foo" \
+ "\\^done,value=\"03\"" \
+ "eval variable foo in octal"
+
+mi_gdb_test "-var-show-format foo" \
+ "\\^done,format=\"decimal\"" \
+ "show format variable foo after eval in octal"
+
+mi_gdb_test "-var-evaluate-expression -f decimal foo" \
+ "\\^done,value=\"3\"" \
+ "eval variable foo in decimal"
+
+mi_gdb_test "-var-show-format foo" \
+ "\\^done,format=\"decimal\"" \
+ "show format variable foo after eval in decimal"
+
+mi_gdb_test "-var-evaluate-expression -f nat foo" \
+ "\\^done,value=\"0x3\"" \
+ "eval variable foo in natural"
+
+mi_gdb_test "-var-show-format foo" \
+ "\\^done,format=\"decimal\"" \
+ "show format variable foo after eval in natural"
+
+mi_gdb_test "-var-evaluate-expression -f bin foo" \
+ "\\^done,value=\"11\"" \
+ "eval variable foo in binary"
+
+mi_gdb_test "-var-show-format foo" \
+ "\\^done,format=\"decimal\"" \
+ "show format variable foo after eval in binary"
+
mi_gdb_test "-var-delete foo" \
"\\^done,ndeleted=\"1\"" \
"delete var foo"
diff --git a/gdb/varobj.c b/gdb/varobj.c
index 3e7550715b4..7f7fda2c511 100644
--- a/gdb/varobj.c
+++ b/gdb/varobj.c
@@ -228,7 +228,8 @@ static struct value *value_of_root (struct varobj **var_handle, int *);
static struct value *value_of_child (struct varobj *parent, int index);
-static char *my_value_of_variable (struct varobj *var);
+static char *my_value_of_variable (struct varobj *var,
+ enum varobj_display_formats format);
static char *value_get_print_value (struct value *value,
enum varobj_display_formats format);
@@ -253,7 +254,8 @@ static struct value *c_value_of_child (struct varobj *parent, int index);
static struct type *c_type_of_child (struct varobj *parent, int index);
-static char *c_value_of_variable (struct varobj *var);
+static char *c_value_of_variable (struct varobj *var,
+ enum varobj_display_formats format);
/* C++ implementation */
@@ -273,7 +275,8 @@ static struct value *cplus_value_of_child (struct varobj *parent, int index);
static struct type *cplus_type_of_child (struct varobj *parent, int index);
-static char *cplus_value_of_variable (struct varobj *var);
+static char *cplus_value_of_variable (struct varobj *var,
+ enum varobj_display_formats format);
/* Java implementation */
@@ -291,7 +294,8 @@ static struct value *java_value_of_child (struct varobj *parent, int index);
static struct type *java_type_of_child (struct varobj *parent, int index);
-static char *java_value_of_variable (struct varobj *var);
+static char *java_value_of_variable (struct varobj *var,
+ enum varobj_display_formats format);
/* The language specific vector */
@@ -324,7 +328,8 @@ struct language_specific
struct type *(*type_of_child) (struct varobj * parent, int index);
/* The current value of VAR. */
- char *(*value_of_variable) (struct varobj * var);
+ char *(*value_of_variable) (struct varobj * var,
+ enum varobj_display_formats format);
};
/* Array of known source language routines. */
@@ -858,9 +863,16 @@ varobj_get_attributes (struct varobj *var)
}
char *
+varobj_get_formatted_value (struct varobj *var,
+ enum varobj_display_formats format)
+{
+ return my_value_of_variable (var, format);
+}
+
+char *
varobj_get_value (struct varobj *var)
{
- return my_value_of_variable (var);
+ return my_value_of_variable (var, var->format);
}
/* Set the value of an object variable (if it is editable) to the
@@ -1777,10 +1789,10 @@ value_of_child (struct varobj *parent, int index)
/* GDB already has a command called "value_of_variable". Sigh. */
static char *
-my_value_of_variable (struct varobj *var)
+my_value_of_variable (struct varobj *var, enum varobj_display_formats format)
{
if (var->root->is_valid)
- return (*var->root->lang->value_of_variable) (var);
+ return (*var->root->lang->value_of_variable) (var, format);
else
return NULL;
}
@@ -2253,7 +2265,7 @@ c_type_of_child (struct varobj *parent, int index)
}
static char *
-c_value_of_variable (struct varobj *var)
+c_value_of_variable (struct varobj *var, enum varobj_display_formats format)
{
/* BOGUS: if val_print sees a struct/class, or a reference to one,
it will print out its children instead of "{...}". So we need to
@@ -2298,7 +2310,13 @@ c_value_of_variable (struct varobj *var)
gdb_assert (varobj_value_is_changeable_p (var));
gdb_assert (!value_lazy (var->value));
- return xstrdup (var->print_value);
+
+ /* If the specified format is the current one,
+ we can reuse print_value */
+ if (format == var->format)
+ return xstrdup (var->print_value);
+ else
+ return value_get_print_value (var->value, format);
}
}
}
@@ -2624,7 +2642,7 @@ cplus_type_of_child (struct varobj *parent, int index)
}
static char *
-cplus_value_of_variable (struct varobj *var)
+cplus_value_of_variable (struct varobj *var, enum varobj_display_formats format)
{
/* If we have one of our special types, don't print out
@@ -2632,7 +2650,7 @@ cplus_value_of_variable (struct varobj *var)
if (CPLUS_FAKE_CHILD (var))
return xstrdup ("");
- return c_value_of_variable (var);
+ return c_value_of_variable (var, format);
}
/* Java */
@@ -2707,9 +2725,9 @@ java_type_of_child (struct varobj *parent, int index)
}
static char *
-java_value_of_variable (struct varobj *var)
+java_value_of_variable (struct varobj *var, enum varobj_display_formats format)
{
- return cplus_value_of_variable (var);
+ return cplus_value_of_variable (var, format);
}
extern void _initialize_varobj (void);
diff --git a/gdb/varobj.h b/gdb/varobj.h
index 0926d7288b5..4fc7d1ecfb2 100644
--- a/gdb/varobj.h
+++ b/gdb/varobj.h
@@ -111,6 +111,9 @@ extern enum varobj_languages varobj_get_language (struct varobj *var);
extern int varobj_get_attributes (struct varobj *var);
+extern char *varobj_get_formatted_value (struct varobj *var,
+ enum varobj_display_formats format);
+
extern char *varobj_get_value (struct varobj *var);
extern int varobj_set_value (struct varobj *var, char *expression);