From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27434 invoked by alias); 8 Apr 2008 15:27:17 -0000 Received: (qmail 27411 invoked by uid 22791); 8 Apr 2008 15:27:09 -0000 X-Spam-Check-By: sourceware.org Received: from imr1.ericy.com (HELO imr1.ericy.com) (198.24.6.9) by sourceware.org (qpsmtpd/0.31) with ESMTP; Tue, 08 Apr 2008 15:26:39 +0000 Received: from eusrcmw751.eamcs.ericsson.se (eusrcmw751.exu.ericsson.se [138.85.77.51]) by imr1.ericy.com (8.13.1/8.13.1) with ESMTP id m38FQcc0023037 for ; Tue, 8 Apr 2008 10:26:38 -0500 Received: from ecamlmw720.eamcs.ericsson.se ([142.133.1.72]) by eusrcmw751.eamcs.ericsson.se with Microsoft SMTPSVC(6.0.3790.1830); Tue, 8 Apr 2008 10:26:37 -0500 Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Subject: RE: [Patch] Try2: -var-evaluate-expression [-f FORMAT] NAME Date: Tue, 08 Apr 2008 17:04:00 -0000 Message-ID: <6D19CA8D71C89C43A057926FE0D4ADAA04291040@ecamlmw720.eamcs.ericsson.se> In-Reply-To: <6D19CA8D71C89C43A057926FE0D4ADAA04290FFC@ecamlmw720.eamcs.ericsson.se> From: "Marc Khouzam" To: X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2008-04/txt/msg00155.txt.bz2 Hi Eli, You had previously approved the same doc change, but since I re-submitted t= he patch, can you approve again, when you have a moment? Previous doc approval: http://sourceware.org/ml/gdb-patches/2008-02/msg00082.html code approval: http://sourceware.org/ml/gdb-patches/2008-04/msg00097.html Thanks gdb/ChangeLog 2008-04-01 Marc Khouzam * 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. (*(value_of_variable)): Likewise. (c_value_of_variable): Likewise. Evaluate expression based on format parameter. (varobj_get_formatted_value): New. (varobj_get_value): Added format parameter to method call. gdb/doc/ChangeLog 2008-04-01 Marc Khouzam * gdb.texinfo (GDB/MI Variable Objects): Add anchor to=20 -var-set-format. Add -f option to -var-evaluate-expression. gdb/testsuite/ChangeLog 2008-04-01 Marc Khouzam * gdb.mi/mi2-var-display.exp: Added tests for the new -f option of -var-evaluate-expression. * gdb.mi/mi2-var-display.exp: Likewise. Index: gdb/doc/gdb.texinfo =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvs/src/src/gdb/doc/gdb.texinfo,v retrieving revision 1.478 diff -u -r1.478 gdb.texinfo --- gdb/doc/gdb.texinfo 26 Mar 2008 18:37:47 -0000 1.478 +++ gdb/doc/gdb.texinfo 1 Apr 2008 14:01:36 -0000 @@ -19996,6 +19996,7 @@ Sets the output format for the value of the object @var{name} to be @var{format-spec}. =20 +@anchor{-var-set-format} The syntax for the @var{format-spec} is as follows: =20 @smallexample @@ -20172,12 +20173,16 @@ @subsubheading Synopsis =20 @smallexample - -var-evaluate-expression @var{name} + -var-evaluate-expression [-f @var{format-spec}] @var{name} @end smallexample =20 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=20 +this option are the same as for @code{-var-set-format}=20 +(@pxref{-var-set-format}). If the @samp{-f} option is not specified, +the current display format will be used. The current display format=20 +can be changed using the @code{-var-set-format} command. =20 @smallexample value=3D@var{value} @@ -20230,7 +20235,7 @@ 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. Index: gdb/testsuite/gdb.mi/mi-var-display.exp =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvs/src/src/gdb/testsuite/gdb.mi/mi-var-display.exp,v retrieving revision 1.23 diff -u -r1.23 mi-var-display.exp --- gdb/testsuite/gdb.mi/mi-var-display.exp 26 Mar 2008 13:36:51 -0000 = 1.23 +++ gdb/testsuite/gdb.mi/mi-var-display.exp 1 Apr 2008 14:01:36 -0000 @@ -168,6 +168,50 @@ "\\^done,value=3D\"3\"" \ "eval variable foo" =20 + +# 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=3D\"0x3\"" \ + "eval variable foo in hex" + +mi_gdb_test "-var-show-format foo" \ + "\\^done,format=3D\"decimal\"" \ + "show format variable foo after eval in hex" + +mi_gdb_test "-var-evaluate-expression -f octal foo" \ + "\\^done,value=3D\"03\"" \ + "eval variable foo in octal" + +mi_gdb_test "-var-show-format foo" \ + "\\^done,format=3D\"decimal\"" \ + "show format variable foo after eval in octal" + +mi_gdb_test "-var-evaluate-expression -f decimal foo" \ + "\\^done,value=3D\"3\"" \ + "eval variable foo in decimal" + +mi_gdb_test "-var-show-format foo" \ + "\\^done,format=3D\"decimal\"" \ + "show format variable foo after eval in decimal" + +mi_gdb_test "-var-evaluate-expression -f nat foo" \ + "\\^done,value=3D\"0x3\"" \ + "eval variable foo in natural" + +mi_gdb_test "-var-show-format foo" \ + "\\^done,format=3D\"decimal\"" \ + "show format variable foo after eval in natural" + +mi_gdb_test "-var-evaluate-expression -f bin foo" \ + "\\^done,value=3D\"11\"" \ + "eval variable foo in binary" + +mi_gdb_test "-var-show-format foo" \ + "\\^done,format=3D\"decimal\"" \ + "show format variable foo after eval in binary" + mi_gdb_test "-var-delete foo" \ "\\^done,ndeleted=3D\"1\"" \ "delete var foo" Index: gdb/testsuite/gdb.mi/mi2-var-display.exp =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvs/src/src/gdb/testsuite/gdb.mi/mi2-var-display.exp,v retrieving revision 1.16 diff -u -r1.16 mi2-var-display.exp --- gdb/testsuite/gdb.mi/mi2-var-display.exp 26 Mar 2008 13:36:51 -0000 = 1.16 +++ gdb/testsuite/gdb.mi/mi2-var-display.exp 1 Apr 2008 14:01:36 -0000 @@ -168,6 +168,49 @@ "\\^done,value=3D\"3\"" \ "eval variable foo" =20 +# 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=3D\"0x3\"" \ + "eval variable foo in hex" + +mi_gdb_test "-var-show-format foo" \ + "\\^done,format=3D\"decimal\"" \ + "show format variable foo after eval in hex" + +mi_gdb_test "-var-evaluate-expression -f octal foo" \ + "\\^done,value=3D\"03\"" \ + "eval variable foo in octal" + +mi_gdb_test "-var-show-format foo" \ + "\\^done,format=3D\"decimal\"" \ + "show format variable foo after eval in octal" + +mi_gdb_test "-var-evaluate-expression -f decimal foo" \ + "\\^done,value=3D\"3\"" \ + "eval variable foo in decimal" + +mi_gdb_test "-var-show-format foo" \ + "\\^done,format=3D\"decimal\"" \ + "show format variable foo after eval in decimal" + +mi_gdb_test "-var-evaluate-expression -f nat foo" \ + "\\^done,value=3D\"0x3\"" \ + "eval variable foo in natural" + +mi_gdb_test "-var-show-format foo" \ + "\\^done,format=3D\"decimal\"" \ + "show format variable foo after eval in natural" + +mi_gdb_test "-var-evaluate-expression -f bin foo" \ + "\\^done,value=3D\"11\"" \ + "eval variable foo in binary" + +mi_gdb_test "-var-show-format foo" \ + "\\^done,format=3D\"decimal\"" \ + "show format variable foo after eval in binary" + mi_gdb_test "-var-delete foo" \ "\\^done,ndeleted=3D\"1\"" \ "delete var foo" Index: gdb/varobj.h =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvs/src/src/gdb/varobj.h,v retrieving revision 1.17 diff -u -r1.17 varobj.h --- gdb/varobj.h 26 Mar 2008 14:51:28 -0000 1.17 +++ gdb/varobj.h 1 Apr 2008 14:01:32 -0000 @@ -111,6 +111,9 @@ =20 extern int varobj_get_attributes (struct varobj *var); =20 +extern char *varobj_get_formatted_value (struct varobj *var, + enum varobj_display_formats format= ); + extern char *varobj_get_value (struct varobj *var); =20 extern int varobj_set_value (struct varobj *var, char *expression); Index: gdb/varobj.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvs/src/src/gdb/varobj.c,v retrieving revision 1.108 diff -u -r1.108 varobj.c --- gdb/varobj.c 26 Mar 2008 14:51:28 -0000 1.108 +++ gdb/varobj.c 1 Apr 2008 14:01:32 -0000 @@ -228,7 +228,8 @@ =20 static struct value *value_of_child (struct varobj *parent, int index); =20 -static char *my_value_of_variable (struct varobj *var); +static char *my_value_of_variable (struct varobj *var, + enum varobj_display_formats format); =20 static char *value_get_print_value (struct value *value, enum varobj_display_formats format); @@ -253,7 +254,8 @@ =20 static struct type *c_type_of_child (struct varobj *parent, int index); =20 -static char *c_value_of_variable (struct varobj *var); +static char *c_value_of_variable (struct varobj *var, + enum varobj_display_formats format); =20 /* C++ implementation */ =20 @@ -273,7 +275,8 @@ =20 static struct type *cplus_type_of_child (struct varobj *parent, int index); =20 -static char *cplus_value_of_variable (struct varobj *var); +static char *cplus_value_of_variable (struct varobj *var, + enum varobj_display_formats format); =20 /* Java implementation */ =20 @@ -291,7 +294,8 @@ =20 static struct type *java_type_of_child (struct varobj *parent, int index); =20 -static char *java_value_of_variable (struct varobj *var); +static char *java_value_of_variable (struct varobj *var, + enum varobj_display_formats format); =20 /* The language specific vector */ =20 @@ -324,7 +328,8 @@ struct type *(*type_of_child) (struct varobj * parent, int index); =20 /* The current value of VAR. */ - char *(*value_of_variable) (struct varobj * var); + char *(*value_of_variable) (struct varobj * var, + enum varobj_display_formats format); }; =20 /* Array of known source language routines. */ @@ -858,9 +863,16 @@ } =20 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); } =20 /* Set the value of an object variable (if it is editable) to the @@ -1777,10 +1789,10 @@ =20 /* 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 form= at) { 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 @@ } =20 static char * -c_value_of_variable (struct varobj *var) +c_value_of_variable (struct varobj *var, enum varobj_display_formats forma= t) { /* 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 @@ =20 gdb_assert (varobj_value_is_changeable_p (var)); gdb_assert (!value_lazy (var->value)); - return xstrdup (var->print_value); +=20=20=20=20=20=20=20=20=20=20=20 + /* If the specified format is the current one, + we can reuse print_value */ + if (format =3D=3D var->format) + return xstrdup (var->print_value); + else + return value_get_print_value (var->value, format); } } } @@ -2624,7 +2642,7 @@ } =20 static char * -cplus_value_of_variable (struct varobj *var) +cplus_value_of_variable (struct varobj *var, enum varobj_display_formats f= ormat) { =20 /* If we have one of our special types, don't print out @@ -2632,7 +2650,7 @@ if (CPLUS_FAKE_CHILD (var)) return xstrdup (""); =20 - return c_value_of_variable (var); + return c_value_of_variable (var, format); } =20 /* Java */ @@ -2707,9 +2725,9 @@ } =20 static char * -java_value_of_variable (struct varobj *var) +java_value_of_variable (struct varobj *var, enum varobj_display_formats fo= rmat) { - return cplus_value_of_variable (var); + return cplus_value_of_variable (var, format); } =20 extern void _initialize_varobj (void); Index: gdb/Makefile.in =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvs/src/src/gdb/Makefile.in,v retrieving revision 1.996 diff -u -r1.996 Makefile.in --- gdb/Makefile.in 26 Mar 2008 14:53:28 -0000 1.996 +++ gdb/Makefile.in 1 Apr 2008 14:01:31 -0000 @@ -3219,7 +3219,7 @@ $(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) Index: gdb/mi/mi-cmd-var.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvs/src/src/gdb/mi/mi-cmd-var.c,v retrieving revision 1.47 diff -u -r1.47 mi-cmd-var.c --- gdb/mi/mi-cmd-var.c 26 Mar 2008 14:51:28 -0000 1.47 +++ gdb/mi/mi-cmd-var.c 1 Apr 2008 14:01:36 -0000 @@ -28,6 +28,7 @@ #include "value.h" #include #include "gdb_string.h" +#include "mi-getopt.h" =20 const char mi_no_values[] =3D "--no-values"; const char mi_simple_values[] =3D "--simple-values"; @@ -195,11 +196,33 @@ return MI_CMD_DONE; } =20 +/* Parse a string argument into a format value. */ + +static enum varobj_display_formats +mi_parse_format (const char *arg) +{ + int len; + + len =3D strlen (arg); + + if (strncmp (arg, "natural", len) =3D=3D 0) + return FORMAT_NATURAL; + else if (strncmp (arg, "binary", len) =3D=3D 0) + return FORMAT_BINARY; + else if (strncmp (arg, "decimal", len) =3D=3D 0) + return FORMAT_DECIMAL; + else if (strncmp (arg, "hexadecimal", len) =3D=3D 0) + return FORMAT_HEXADECIMAL; + else if (strncmp (arg, "octal", len) =3D=3D 0) + return FORMAT_OCTAL; + else + error (_("Unknown display format: must be: \"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; =20 @@ -216,21 +239,8 @@ if (formspec =3D=3D NULL) error (_("mi_cmd_var_set_format: Must specify the format as: \"natural= \", \"binary\", \"decimal\", \"hexadecimal\", or \"octal\"")); =20 - len =3D strlen (formspec); - - if (strncmp (formspec, "natural", len) =3D=3D 0) - format =3D FORMAT_NATURAL; - else if (strncmp (formspec, "binary", len) =3D=3D 0) - format =3D FORMAT_BINARY; - else if (strncmp (formspec, "decimal", len) =3D=3D 0) - format =3D FORMAT_DECIMAL; - else if (strncmp (formspec, "hexadecimal", len) =3D=3D 0) - format =3D FORMAT_HEXADECIMAL; - else if (strncmp (formspec, "octal", len) =3D=3D 0) - format =3D FORMAT_OCTAL; - else - error (_("mi_cmd_var_set_format: Unknown display format: must be: \"na= tural\", \"binary\", \"decimal\", \"hexadecimal\", or \"octal\"")); - + format =3D mi_parse_format (formspec); +=20=20 /* Set the format of VAR to given format */ varobj_set_display_format (var, format); =20 @@ -493,15 +503,58 @@ { struct varobj *var; =20 - if (argc !=3D 1) - error (_("mi_cmd_var_evaluate_expression: Usage: NAME.")); + enum varobj_display_formats format; + int formatFound; + int optind; + char *optarg; +=20=20=20=20 + enum opt + { + OP_FORMAT + }; + static struct mi_opt opts[] =3D + { + {"f", OP_FORMAT, 1}, + { 0, 0, 0 } + }; + + /* Parse arguments */ + format =3D FORMAT_NATURAL; + formatFound =3D 0; + optind =3D 0; + while (1) + { + int opt =3D mi_getopt ("mi_cmd_var_evaluate_expression", argc, argv,= opts, &optind, &optarg); + if (opt < 0) + break; + switch ((enum opt) opt) + { + case OP_FORMAT: + if (formatFound) + error (_("mi_cmd_var_evaluate_expression: cannot specify format= more than once")); +=20=20=20 + format =3D mi_parse_format (optarg); + formatFound =3D 1; + break; + } + } =20 - /* Get varobj handle, if a valid var obj name was specified */ - var =3D varobj_get_handle (argv[0]); + if (optind >=3D argc) + error (_("mi_cmd_var_evaluate_expression: Usage: [-f FORMAT] NAME")); +=20=20=20 + if (optind < argc - 1) + error (_("mi_cmd_var_evaluate_expression: Garbage at end of command")); +=20 + /* Get varobj handle, if a valid var obj name was specified */ + var =3D varobj_get_handle (argv[optind]); if (var =3D=3D NULL) error (_("mi_cmd_var_evaluate_expression: Variable object not found")); +=20=20=20 + 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)); =20 - ui_out_field_string (uiout, "value", varobj_get_value (var)); return MI_CMD_DONE; }