From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7806 invoked by alias); 9 Jan 2010 09:55:06 -0000 Received: (qmail 7796 invoked by uid 22791); 9 Jan 2010 09:55:04 -0000 X-SWARE-Spam-Status: No, hits=-1.7 required=5.0 tests=AWL,BAYES_00,SARE_MSGID_LONG40,SPF_PASS X-Spam-Check-By: sourceware.org Received: from mail-px0-f175.google.com (HELO mail-px0-f175.google.com) (209.85.216.175) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sat, 09 Jan 2010 09:55:00 +0000 Received: by pxi5 with SMTP id 5so14821025pxi.12 for ; Sat, 09 Jan 2010 01:54:59 -0800 (PST) MIME-Version: 1.0 Received: by 10.142.59.16 with SMTP id h16mr19155935wfa.161.1263030899097; Sat, 09 Jan 2010 01:54:59 -0800 (PST) In-Reply-To: <20100106075757.GF24777@adacore.com> References: <4B29018C.6060307@codesourcery.com> <4B3BEDCC.9040103@earthlink.net> <20100106075757.GF24777@adacore.com> From: Hui Zhu Date: Sat, 09 Jan 2010 09:55:00 -0000 Message-ID: Subject: Re: [RFC] Let "gcore" command accept a suffix argument To: Joel Brobecker Cc: Stan Shebs , Tom Tromey , Stan Shebs , Michael Snyder , gdb-patches ml , Eli Zaretskii Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable 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: 2010-01/txt/msg00208.txt.bz2 Thanks Joel, On Wed, Jan 6, 2010 at 15:57, Joel Brobecker wrote: >> 2010-01-06 =A0Hui Zhu =A0 >> =A0 =A0 =A0 * printcmd.c (ctype.h): New include. >> =A0 =A0 =A0 (eval_command): New function. >> =A0 =A0 =A0 (_initialize_printcmd): New command "eval". > > This is looking interesting :). A few comments: > > =A0* what is the exact semantics of the eval command? I looked at > =A0 =A0the implementation, and I'm not I understand, or what I understand > =A0 =A0does not necessarily makes sense to me. > > =A0 =A0So, in plain English first, what is the eval command expected > =A0 =A0to do, in particular, what parts and how will the command translate > =A0 =A0in the argument that gets passed. > > =A0* implementation-wise: > >> +#define CMDSIZE 1024 >> + =A0char cmd[CMDSIZE + 1]; > > The GNU Coding Standard explicitly recommend against hard-coded > arbitrary limitations like these. In particular, your implementation > seems to just silently truncate the result if the user uses > an argument whose result does not fit in your CMDSIZE. > > I think the implementation should allow for the argument to grow > to any size. It will be change. > >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0if (strlen (eval_begin)) >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0{ >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0value =3D parse_and_eval (eval_begi= n); >> + >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0switch (TYPE_CODE (value_type (valu= e))) >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0{ >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0case TYPE_CODE_ARRAY: >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0LA_GET_STRING (value, &= buffer, &length, >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 &char_type, &la_encoding); >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 break; >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0case TYPE_CODE_INT: >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0buffer =3D plongest (va= lue_as_long (value)); >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0length =3D strlen (buff= er); >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0break; >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0default: >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0buffer =3D eval_begin; >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0length =3D exp - eval_b= egin; >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0break; >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0} >> + >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if (length > CMDSIZE - (cmdp - cmd)) >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0length =3D CMDSIZE - (cmdp - cm= d); >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0memcpy (cmdp, buffer, length); >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0cmdp +=3D length; > > I think you should print "value_print" instead of doing the printing > yourself. Your implementation is missing a lot of other cases that > you need to handle (eg: TYPE_CODE_RANGE, just to mention one). > This value will be convert to string and execute_command (cmd, from_tty); will use it. value_print print the value VAL in C-ish syntax on stream STREAM according to OPTIONS. But cannot find a example how to do it, could you help me with it? Best regards, Hui