From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15021 invoked by alias); 23 Jan 2008 14:30:09 -0000 Received: (qmail 14995 invoked by uid 22791); 23 Jan 2008 14:30:06 -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 14:29:37 +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 m0NETX34009979; Wed, 23 Jan 2008 08:29:33 -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 08:29:32 -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 14:30:00 -0000 Message-ID: <6D19CA8D71C89C43A057926FE0D4ADAA04290E54@ecamlmw720.eamcs.ericsson.se> In-Reply-To: <18326.44682.805865.581205@kahikatea.snap.net.nz> From: "Marc Khouzam" To: "Nick Roberts" Cc: 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/msg00546.txt.bz2 > > I kind of cheated and used NULL to indicate that the format used should= be > > the one stored in the varobj structure. >=20 > I would use a new function, e.g., something like=20 >=20 > char * > varobj_get_formatted_value (struct varobj *var, > enum varobj_display_formats format) > { > enum varobj_display_formats oldformat; > char* value; > oldformat =3D var->format; > var->format =3D format; > value =3D varobj_get_value (var); > var->format =3D oldformat; > return value; > } >=20 > and call it when argc =3D=3D 2 in mi_cmd_var_evaluate_expression so that = you > don't have to change all calls to varobj_get_value and related functions. > (Note: not tested) I hadn't thought of temporarily setting var->format, instead of passing 'fo= rmat' everywhere. Much easier! Is there any way that varob_get_value() could no= t return? Like a failed gdb_assert? Or are we sure that var->format will be reset to the old format properly no matter what happens to varobj_get_value? > > +/* 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\"")); > > +} > > + >=20 > and I would refactor this out of mi_cmd_var_set_format. Didn't I do that already?