From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11172 invoked by alias); 30 Nov 2005 18:57:49 -0000 Received: (qmail 11165 invoked by uid 22791); 30 Nov 2005 18:57:48 -0000 X-Spam-Check-By: sourceware.org Received: from zproxy.gmail.com (HELO zproxy.gmail.com) (64.233.162.192) by sourceware.org (qpsmtpd/0.31) with ESMTP; Wed, 30 Nov 2005 18:57:42 +0000 Received: by zproxy.gmail.com with SMTP id l1so71891nzf for ; Wed, 30 Nov 2005 10:57:40 -0800 (PST) Received: by 10.36.74.2 with SMTP id w2mr669550nza; Wed, 30 Nov 2005 10:57:40 -0800 (PST) Received: by 10.37.2.6 with HTTP; Wed, 30 Nov 2005 10:57:40 -0800 (PST) Message-ID: <8f2776cb0511301057k271ee4das7a1deb008362aac8@mail.gmail.com> Date: Wed, 30 Nov 2005 21:20:00 -0000 From: Jim Blandy To: Andrew STUBBS Subject: Re: [PATCH] init-if-undefined command Cc: gdb-patches@sources.redhat.com In-Reply-To: <438DB351.2050500@st.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline References: <437B3E56.3080306@st.com> <8f2776cb0511292141t2f9711a2l9633236db737e67b@mail.gmail.com> <438DB351.2050500@st.com> X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2005-11/txt/msg00513.txt.bz2 Okay, that looks better. We agreed we need a NEWS entry, too; could you include that in your patch? Once Eli approves the NEWS entry, this can go in. On 11/30/05, Andrew STUBBS wrote: > Here is another version with the various help strings updated. > > I have rewritten the main help because I noticed it did not start with > something suitable for 'help data'. I also added a little more > information about its exact behaviour. > > I hope this is better now. > > Andrew Stubbs > > > 2005-11-30 Andrew Stubbs > > * value.c (init_if_undefined_command): New function. > (_initialize_values): Add command init-if-undefined. > > doc/ > * gdb.texinfo (Convenience variables): Add init-if-undefined comm= and. > > Index: src/gdb/value.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 > --- src.orig/gdb/value.c 2005-11-29 16:35:46.000000000 +0000 > +++ src/gdb/value.c 2005-11-30 12:46:34.000000000 +0000 > @@ -727,6 +727,47 @@ show_values (char *num_exp, int from_tty > > static struct internalvar *internalvars; > > +/* If the variable does not already exist create it and give it the valu= e given. > + If no value is given then the default is zero. */ > +static void > +init_if_undefined_command (char* args, int from_tty) > +{ > + struct internalvar* intvar; > + > + /* Parse the expression - this is taken from set_command(). */ > + struct expression *expr =3D parse_expression (args); > + register struct cleanup *old_chain =3D > + make_cleanup (free_current_contents, &expr); > + > + /* Validate the expression. > + Was the expression an assignment? > + Or even an expression at all? */ > + if (expr->nelts =3D=3D 0 || expr->elts[0].opcode !=3D BINOP_ASSIGN) > + { > + printf_unfiltered ("Init-if-undefined requires an assignment expre= ssion.\n"); > + do_cleanups (old_chain); > + return; > + } > + > + /* Extract the variable from the parsed expression. > + In the case of an assign the lvalue will be in elts[1] and elts[2].= */ > + if (expr->elts[1].opcode !=3D OP_INTERNALVAR) > + { > + printf_unfiltered ("The first parameter to init-if-undefined shoul= d be a GDB variable\n"); > + do_cleanups (old_chain); > + return; > + } > + intvar =3D expr->elts[2].internalvar; > + > + /* Only evaluate the expression if the lvalue is void. > + This may still fail if the expresssion is invalid. */ > + if (TYPE_CODE (value_type (intvar->value)) =3D=3D TYPE_CODE_VOID) > + evaluate_expression (expr); > + > + do_cleanups (old_chain); > +} > + > + > /* Look up an internal variable with name NAME. NAME should not > normally include a dollar sign. > > @@ -1639,4 +1680,11 @@ A few convenience variables are given va > add_cmd ("values", no_class, show_values, > _("Elements of value history around item number IDX (or last t= en)."), > &showlist); > + > + add_com ("init-if-undefined", class_vars, init_if_undefined_command, _= ("\ > +Initialize a convenience variable if necessary.\n\ > +init-if-undefined VARIABLE =3D EXPRESSION\n\ > +Set an internal VARIABLE to the result of the EXPRESSION if it does not\= n\ > +exist or does not contain a value. The EXPRESSION is not evaluated if t= he\n\ > +VARIABLE is already initialized.")); > } > Index: src/gdb/doc/gdb.texinfo > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > --- src.orig/gdb/doc/gdb.texinfo 2005-11-29 16:36:23.000000000 +00= 00 > +++ src/gdb/doc/gdb.texinfo 2005-11-30 12:24:23.000000000 +0000 > @@ -6131,6 +6131,18 @@ variable, when used as an expression, ha > @item show convenience > Print a list of convenience variables used so far, and their values. > Abbreviated @code{show conv}. > + > +@kindex init-if-undefined > +@cindex convenience variables, initializing > +@item init-if-undefined $@var{variable} =3D @var{expression} > +Set a convenience variable if it has not already been set. This is usef= ul > +for user-defined commands that keep some state. It is similar, in conce= pt, > +to using local static variables with initializers in C (except that > +convenience variables are global). It can also be used to allow users to > +override default values used in a command script. > + > +If the variable is already defined then the expression is not evaluated = so > +any side-effects do not occur. > @end table > > One of the ways to use a convenience variable is as a counter to be > > >