From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20902 invoked by alias); 23 Jan 2008 17:04:10 -0000 Received: (qmail 20867 invoked by uid 22791); 23 Jan 2008 17:04:01 -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; Wed, 23 Jan 2008 17:03:36 +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 m0NH3VP5030939; Wed, 23 Jan 2008 11:03:32 -0600 Received: from ecamlmw720.eamcs.ericsson.se ([142.133.1.72]) by eusrcmw751.eamcs.ericsson.se with Microsoft SMTPSVC(6.0.3790.1830); Wed, 23 Jan 2008 11:03:31 -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: Wed, 23 Jan 2008 17:04:00 -0000 Message-ID: <6D19CA8D71C89C43A057926FE0D4ADAA04290E59@ecamlmw720.eamcs.ericsson.se> In-Reply-To: <20080123144006.GA5885@caradoc.them.org> From: "Marc Khouzam" To: "Daniel Jacobowitz" Cc: "Nick Roberts" , 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-01/txt/msg00557.txt.bz2 Here is a new version of the patch using Nick's suggestion. I had a bit of trouble with the cleanup and am not sure this is how it should be done. Comments? Marc ### Eclipse Workspace Patch 1.0 #P gdb Index: 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.44 diff -u -r1.44 mi-cmd-var.c --- mi/mi-cmd-var.c 23 Jan 2008 06:13:44 -0000 1.44 +++ mi/mi-cmd-var.c 23 Jan 2008 16:59:00 -0000 @@ -190,11 +190,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; +=20=20=20=20=20=20=20=20=20 + 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 +233,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 @@ -492,16 +501,25 @@ mi_cmd_var_evaluate_expression (char *command, char **argv, int argc) { struct varobj *var; + enum varobj_display_formats format; =20 - if (argc !=3D 1) - error (_("mi_cmd_var_evaluate_expression: Usage: NAME.")); + if (argc !=3D 1 &&=20 + (argc !=3D 3 || strcmp(argv[1], "-f") !=3D 0)) + error (_("mi_cmd_var_evaluate_expression: Usage: NAME [-f FORMAT]")); =20 /* Get varobj handle, if a valid var obj name was specified */ var =3D varobj_get_handle (argv[0]); 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 (argc =3D=3D 3) + { + format =3D mi_parse_format(argv[2]); + 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 Index: 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.14 diff -u -r1.14 varobj.h --- varobj.h 1 Jan 2008 22:53:13 -0000 1.14 +++ varobj.h 23 Jan 2008 16:59:00 -0000 @@ -104,6 +104,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: 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.99 diff -u -r1.99 varobj.c --- varobj.c 1 Jan 2008 22:53:13 -0000 1.99 +++ varobj.c 23 Jan 2008 16:59:00 -0000 @@ -192,6 +192,9 @@ =20 static struct cleanup *make_cleanup_free_variable (struct varobj *var); =20 +static struct cleanup *make_cleanup_set_format (struct varobj *var, + enum varobj_display_formats format); + static struct type *get_type (struct varobj *var); =20 static struct type *get_value_type (struct varobj *var); @@ -854,6 +857,24 @@ return my_value_of_variable (var); } =20 +char * +varobj_get_formatted_value (struct varobj *var, + enum varobj_display_formats format) +{ + enum varobj_display_formats oldformat; + struct cleanup *old_chain; + char* value; +=20=20 + oldformat =3D var->format; + old_chain =3D make_cleanup_set_format (var, oldformat); + + var->format =3D format; + value =3D my_value_of_variable (var); +=20=20 + do_cleanups (old_chain); + return value; +} + /* Set the value of an object variable (if it is editable) to the value of the given expression */ /* Note: Invokes functions that can call error() */ @@ -1543,6 +1564,36 @@ return make_cleanup (do_free_variable_cleanup, var); } =20 +struct cleanup_set_format_struct +{ + struct varobj *var; + enum varobj_display_formats format; +}; + +static void +do_set_format_cleanup (void *cleanup_set_format)=20 +{ + struct cleanup_set_format_struct *cleanup_struct =3D cleanup_set_format; + + varobj_set_display_format(cleanup_struct->var,=20 + cleanup_struct->format); +=20=20 + xfree(cleanup_struct); +} + +static struct cleanup * +make_cleanup_set_format (struct varobj *var,=20 + enum varobj_display_formats format) +{ + struct cleanup_set_format_struct *cleanup_struct; +=20=20 + cleanup_struct =3D XMALLOC (struct cleanup_set_format_struct); + cleanup_struct->var =3D var; + cleanup_struct->format =3D format; + + return make_cleanup (do_set_format_cleanup, cleanup_struct); +} + /* This returns the type of the variable. It also skips past typedefs to return the real type of the variable.