From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11532 invoked by alias); 22 Jan 2008 20:38:34 -0000 Received: (qmail 11521 invoked by uid 22791); 22 Jan 2008 20:38:33 -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, 22 Jan 2008 20:38:11 +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 m0MKcAlQ026676 for ; Tue, 22 Jan 2008 14:38:10 -0600 Received: from ecamlmw720.eamcs.ericsson.se ([142.133.1.72]) by eusrcmw750.eamcs.ericsson.se with Microsoft SMTPSVC(6.0.3790.1830); Tue, 22 Jan 2008 14:35:43 -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: [Patch] -var-evaluate-expression NAME [FORMAT] Date: Tue, 22 Jan 2008 20:38:00 -0000 Message-ID: <6D19CA8D71C89C43A057926FE0D4ADAA04290E50@ecamlmw720.eamcs.ericsson.se> From: "Marc Khouzam" To: 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/msg00531.txt.bz2 Hi, Here is a patch to add an optional format parameter to -var-evaluate-expres= sion. -var-evaluate-expression NAME [FORMAT] This allows a frontend to request a value in a different format without cha= nging the current format of the variable object. If the format is not specified, the command behaves as before (current form= at of=20 the varObject is used.) I kind of cheated and used NULL to indicate that the format used should be = the one stored in the varobj structure. Instead, I could have extended the enu= meration varobj_display_formats to have a FORMAT_CURRENT entry, but I didn't like th= at much. I did not update tests, run regression or changed the documentation (don't = know how to do any of these things). 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.43 diff -u -r1.43 mi-cmd-var.c --- mi/mi-cmd-var.c 1 Jan 2008 22:53:14 -0000 1.43 +++ mi/mi-cmd-var.c 22 Jan 2008 20:22:07 -0000 @@ -57,7 +57,7 @@ ui_out_field_int (uiout, "numchild", varobj_get_num_children (var)); =20=20=20 if (mi_print_value_p (varobj_get_gdb_type (var), print_values)) - ui_out_field_string (uiout, "value", varobj_get_value (var)); + ui_out_field_string (uiout, "value", varobj_get_value (var, NULL)); =20 type =3D varobj_get_type (var); if (type !=3D NULL) @@ -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 @@ -489,16 +498,24 @@ 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 && argc !=3D 2) + error (_("mi_cmd_var_evaluate_expression: Usage: NAME [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 2) + { + format =3D mi_parse_format(argv[1]); + ui_out_field_string (uiout, "value", varobj_get_value (var, &format)= ); + } + else + ui_out_field_string (uiout, "value", varobj_get_value (var, NULL)); + return MI_CMD_DONE; } =20 @@ -524,7 +541,7 @@ if (!varobj_set_value (var, expression)) error (_("mi_cmd_var_assign: Could not assign expression to variable o= bject")); =20 - ui_out_field_string (uiout, "value", varobj_get_value (var)); + ui_out_field_string (uiout, "value", varobj_get_value (var, NULL)); return MI_CMD_DONE; } =20 @@ -645,7 +662,7 @@ cleanup =3D make_cleanup_ui_out_tuple_begin_end (uiout, NULL); ui_out_field_string (uiout, "name", varobj_get_objname (*cc)); if (mi_print_value_p (varobj_get_gdb_type (*cc), print_values)) - ui_out_field_string (uiout, "value", varobj_get_value (*cc)); + ui_out_field_string (uiout, "value", varobj_get_value (*cc, NUL= L)); ui_out_field_string (uiout, "in_scope", "true"); ui_out_field_string (uiout, "type_changed", "false"); if (mi_version (uiout) > 1) 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 22 Jan 2008 20:22:07 -0000 @@ -104,7 +104,8 @@ =20 extern int varobj_get_attributes (struct varobj *var); =20 -extern char *varobj_get_value (struct varobj *var); +extern char *varobj_get_value (struct varobj *var, + enum varobj_display_formats *format); =20 extern int varobj_set_value (struct varobj *var, char *expression); =20 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 22 Jan 2008 20:22:07 -0000 @@ -221,7 +221,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,=20 + enum varobj_display_formats *format); =20 static char *value_get_print_value (struct value *value, enum varobj_display_formats format); @@ -246,7 +247,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 @@ -266,7 +268,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 @@ -284,7 +287,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 @@ -317,7 +321,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. */ @@ -849,11 +854,10 @@ } =20 char * -varobj_get_value (struct varobj *var) +varobj_get_value (struct varobj *var, enum varobj_display_formats *format) { - return my_value_of_variable (var); + return my_value_of_variable (var, format); } - /* 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() */ @@ -1786,10 +1790,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 *for= mat) { 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; } @@ -2215,8 +2219,10 @@ } =20 static char * -c_value_of_variable (struct varobj *var) +c_value_of_variable (struct varobj *var, enum varobj_display_formats *form= at) { + enum varobj_display_formats format_to_use; + /* 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 catch that case explicitly. */ @@ -2260,7 +2266,12 @@ =20 gdb_assert (varobj_value_is_changeable_p (var)); gdb_assert (!value_lazy (var->value)); - return value_get_print_value (var->value, var->format); + if (format =3D=3D NULL) + format_to_use =3D var->format; + else + format_to_use =3D *format; +=20=20=20=20=20=20=20=20=20=20=20 + return value_get_print_value (var->value, format_to_use); } } } @@ -2586,7 +2597,7 @@ } =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 @@ -2594,7 +2605,7 @@ if (CPLUS_FAKE_CHILD (var)) return xstrdup (""); =20 - return c_value_of_variable (var); + return c_value_of_variable (var, format); } =20 /* Java */ @@ -2669,9 +2680,9 @@ } =20 static char * -java_value_of_variable (struct varobj *var) +java_value_of_variable (struct varobj *var, enum varobj_display_formats *f= ormat) { - return cplus_value_of_variable (var); + return cplus_value_of_variable (var, format); } =20 extern void _initialize_varobj (void); =20 Marc Khouzam Software Designer, Methods and Tools =20 Ericsson Canada Inc EMC/Q 8500 Decarie Blvd. H4P 2N2, Mont-Royal, Qc, Canada www.ericsson.comOffice: +514 345 7900 x42350 Fax: +514 345 6159 Mobile: +514 951 7191 Email: Marc.Khouzam@ericsson.com Ce courriel est confidentiel et uniquement destin=E9 =E0 son ou ses destina= taires. Il est d=E9fendu de le consulter, de l'utiliser, de le d=E9voiler o= u de le diffuser sans autorisation. Si ce message vous est parvenu par erre= ur, merci d'en aviser l'exp=E9diteur par retour de courrier et de le d=E9tr= uire sans le divulguer. Un courriel et ses pi=E8ces jointes peut =EAtre sa= ns autorisation corrompu, interrompu, amend=E9, alt=E9r=E9 et infect=E9. L'= entreprise ne re=E7oit et n'envoie de courriel qu'avec l'entente qu'elle n'= est responsable d'aucune corruption, interception, modification, alt=E9rati= on, infection ou cons=E9quence possible. This communication is confidential and intended solely for the addressee(s)= . Any unauthorized review, use, disclosure or distribution is prohibited. I= f you believe this message has been sent to you in error, please notify the= sender by replying to this transmission and delete the message without dis= closing it. Thank you. E-mail including attachments is susceptible to data= corruption, interruption, unauthorized amendment, tampering and viruses, a= nd we only send and receive e-mails on the basis that we are not liable for= any such corruption, interception, amendment, tampering or viruses or any = consequences thereof.