From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29481 invoked by alias); 5 Feb 2008 14:47:51 -0000 Received: (qmail 29461 invoked by uid 22791); 5 Feb 2008 14:47:48 -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, 05 Feb 2008 14:47:18 +0000 Received: from eusrcmw750.eamcs.ericsson.se (eusrcmw750.exu.ericsson.se [138.85.77.50]) by imr1.ericy.com (8.13.1/8.13.1) with ESMTP id m15ElBxs012063; Tue, 5 Feb 2008 08:47:11 -0600 Received: from ecamlmw720.eamcs.ericsson.se ([142.133.1.72]) by eusrcmw750.eamcs.ericsson.se with Microsoft SMTPSVC(6.0.3790.1830); Tue, 5 Feb 2008 08:47:11 -0600 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] -var-evaluate-expression NAME [FORMAT] Date: Tue, 05 Feb 2008 14:47:00 -0000 Message-ID: <6D19CA8D71C89C43A057926FE0D4ADAA04290E90@ecamlmw720.eamcs.ericsson.se> In-Reply-To: <18343.34335.642831.945359@kahikatea.snap.net.nz> From: "Marc Khouzam" To: "Nick Roberts" Cc: "Daniel Jacobowitz" , 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-02/txt/msg00103.txt.bz2 > > I think a solution based on=20 > > http://sourceware.org/ml/gdb-patches/2008-01/msg00531.html > > is probably the cleanest. Can I have an educated opinion on > > this decision? > > This also uses value_get_print_value in c_value_of_variable.=20=20 Did you mean that this solution "also uses print_value" after Vladimir's=20 patch? What we would do is use the format parameter that would be passed all the way to c_value_of_variable; if the specified format is=20 the same as var->format we call print_value (as done in Vladimir's patch), but if the format is something different, we call value_get_print_value (var->value, format). (See below). > I can't seem to apply your earlier patch as I get spurious characters > when I save it (=3D -> =3D3D, \n -> =3D20\n, etc) but I wonder if we've m= ade > things too complicated. I've redone the patch (slightly cleaner than before). It's at the bottom. =20 > What happens if you just use value_get_print_value (var->value, var->form= at) > directly in mi_cmd_var_evaluate_expression instead of varobj_get_value (v= ar)? This won't work, because it bypassed all the logic done between the call to varobj_get_value() and the one to value_get_print_value(); such things as returning "{...}" for structs and unions, returning "[numChildren]" for arr= ays; it would also bypass the checks for var->value =3D=3D NULL, and value_lazy(= ), etc. Marc =3D=3D Indentation is not correct, tests and doc have been removed. This is just for discussion since I have to wait for my copyright=20 assignment anyway. I did test and run regression successfully. 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.15 diff -u -r1.15 varobj.h --- gdb/varobj.h 30 Jan 2008 07:17:31 -0000 1.15 +++ gdb/varobj.h 5 Feb 2008 14:37:03 -0000 @@ -109,6 +109,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.103 diff -u -r1.103 varobj.c --- gdb/varobj.c 4 Feb 2008 07:49:04 -0000 1.103 +++ gdb/varobj.c 5 Feb 2008 14:37:03 -0000 @@ -217,7 +217,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); @@ -242,7 +243,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 @@ -262,7 +264,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 @@ -280,7 +283,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 @@ -313,7 +317,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. */ @@ -833,9 +838,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 @@ -1770,10 +1782,11 @@ =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 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; } @@ -2207,7 +2220,8 @@ } =20 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 @@ -2252,7 +2266,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); } } } @@ -2578,7 +2598,8 @@ } =20 static char * -cplus_value_of_variable (struct varobj *var) +cplus_value_of_variable (struct varobj *var, + enum varobj_display_formats format) { =20 /* If we have one of our special types, don't print out @@ -2586,7 +2607,7 @@ if (CPLUS_FAKE_CHILD (var)) return xstrdup (""); =20 - return c_value_of_variable (var); + return c_value_of_variable (var, format); } =20 /* Java */ @@ -2661,9 +2682,10 @@ } =20 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); } =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.978 diff -u -r1.978 Makefile.in --- gdb/Makefile.in 30 Jan 2008 07:17:31 -0000 1.978 +++ gdb/Makefile.in 5 Feb 2008 14:37:03 -0000 @@ -3208,7 +3208,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.45 diff -u -r1.45 mi-cmd-var.c --- gdb/mi/mi-cmd-var.c 30 Jan 2008 07:17:31 -0000 1.45 +++ gdb/mi/mi-cmd-var.c 5 Feb 2008 14:37:09 -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"; @@ -190,11 +191,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 @@ -211,21 +234,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 @@ -487,16 +497,58 @@ mi_cmd_var_evaluate_expression (char *command, char **argv, int argc) { struct varobj *var; + 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 - if (argc !=3D 1) - error (_("mi_cmd_var_evaluate_expression: Usage: NAME.")); + format =3D mi_parse_format (optarg); + formatFound =3D 1; + break; + } + } + + if (optind >=3D argc) + error (_("mi_cmd_var_evaluate_expression: Usage: [-f FORMAT] NAME")); =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[0]); + var =3D varobj_get_handle (argv[optind]); if (var =3D=3D NULL) error (_("mi_cmd_var_evaluate_expression: Variable object not found")); =20 - ui_out_field_string (uiout, "value", varobj_get_value (var)); + 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)); + return MI_CMD_DONE; } =20 @@ -558,9 +610,9 @@ nv =3D varobj_list (&rootlist); cleanup =3D make_cleanup (xfree, rootlist); if (mi_version (uiout) <=3D 1) - make_cleanup_ui_out_tuple_begin_end (uiout, "changelist"); + make_cleanup_ui_out_tuple_begin_end (uiout, "changelist"); else - make_cleanup_ui_out_list_begin_end (uiout, "changelist"); + make_cleanup_ui_out_list_begin_end (uiout, "changelist"); if (nv <=3D 0) { do_cleanups (cleanup); @@ -582,9 +634,9 @@ error (_("mi_cmd_var_update: Variable object not found")); =20 if (mi_version (uiout) <=3D 1) - cleanup =3D make_cleanup_ui_out_tuple_begin_end (uiout, "changelis= t"); + cleanup =3D make_cleanup_ui_out_tuple_begin_end (uiout, "changelist= "); else - cleanup =3D make_cleanup_ui_out_list_begin_end (uiout, "changelist= "); + cleanup =3D make_cleanup_ui_out_list_begin_end (uiout, "changelist"= ); varobj_update_one (var, print_values, 1 /* explicit */); do_cleanups (cleanup); } @@ -613,26 +665,26 @@ else if (nc < 0) { if (mi_version (uiout) > 1) - cleanup =3D make_cleanup_ui_out_tuple_begin_end (uiout, NULL); + cleanup =3D make_cleanup_ui_out_tuple_begin_end (uiout, NULL); ui_out_field_string (uiout, "name", varobj_get_objname(var)); =20 switch (nc) { - case NOT_IN_SCOPE: - ui_out_field_string (uiout, "in_scope", "false"); + case NOT_IN_SCOPE: + ui_out_field_string (uiout, "in_scope", "false"); + break; + case INVALID: + ui_out_field_string (uiout, "in_scope", "invalid"); break; - case INVALID: - ui_out_field_string (uiout, "in_scope", "invalid"); - break; - case TYPE_CHANGED: + case TYPE_CHANGED: ui_out_field_string (uiout, "in_scope", "true"); - ui_out_field_string (uiout, "new_type", varobj_get_type(var)); - ui_out_field_int (uiout, "new_num_children",=20 + ui_out_field_string (uiout, "new_type", varobj_get_type(var)); + ui_out_field_int (uiout, "new_num_children",=20 varobj_get_num_children(var)); break; } if (mi_version (uiout) > 1) - do_cleanups (cleanup); + do_cleanups (cleanup); } else {